# Sample Code (3DF): HC\_Gather\_Capping\_Geometry

**URL:** <https://forum.techsoft3d.com/t/sample-code-3df-hc-gather-capping-geometry/1372>\
**Category:** HOOPS Visualize Desktop\
**Tags:** code, sample, knowledge-base\
**Created:** [September 1, 2021, 4:00am UTC](https://forum.techsoft3d.com/t/sample-code-3df-hc-gather-capping-geometry/1372 "2021-09-01T04:00:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel.peragine](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/gabriel.peragine/32/1535_2.png) [@gabriel.peragine](https://forum.techsoft3d.com/u/gabriel.peragine)\
**Post date:** [September 1, 2021, 4:00am UTC](https://forum.techsoft3d.com/t/sample-code-3df-hc-gather-capping-geometry/1372/1 "2021-09-01T04:00:00Z")

</div>

Following is sample code on Gather\_Capping\_Geometry with all options (“segment only”,”ignore matrix”, “section offset”, “refine cuts”

**Default:** HC\_Gather\_Capping\_Geometry will only generate capping geometry for the given cutting plane.

**Common Errors:**

1. HOOPS need to render capping geometry. Update must be called before calling Gather\_Capping\_Geometry
2. Double check key path. Make sure key path is from the leaf to root (driver) segment.

**OPTIONS**

**Segment Only:** Collect capping geometry only for the target segment, not any of its subsegments

```auto
void CSolidHoopsView::OnExtraSlot5()
{

	HC_Open_Segment_By_Key(m_pHView->GetModelKey()); {

		int pcount, flist_count;
		pcount = 8;
		flist_count = 30;
		HPoint pts[8];
		int faces[30] = { 4, 0, 1, 2, 3,
			4, 1, 5, 6, 2,
			4, 5, 4, 7, 6,
			4, 4, 0, 3, 7,
			4, 3, 2, 6, 7,
			4, 0, 4, 5, 1 };
		pts[0].Set(0, 0, 0);
		pts[1].Set(2, 0, 0);
		pts[2].Set(2, 2, 0);
		pts[3].Set(0, 2, 0);
		pts[4].Set(0, 0, 2);
		pts[5].Set(2, 0, 2);
		pts[6].Set(2, 2, 2);
		pts[7].Set(0, 2, 2);
		
		float	planes[] = { 0, 0, -1, -0.0001,	1, 0, 0, -0.0001,	0, 1, 0, -0.0001 };

		HC_KEY cutplaneSegment = HC_Open_Segment("cut_plane");
			HC_KEY	section = HC_Insert_Cutting_Plane(0, 0, -1, -0.0001);
			float center[] = { 5, 0, 0 };
			HC_Insert_Sphere(center, 2, NULL, NULL);
			HC_Insert_Cutting_Plane(1, 0, 0, -0.0001);

			HC_Open_Segment("section cuts y");					
				HC_Insert_Shell(pcount, pts, flist_count, faces);
				HC_Translate_Object(-1, -1, -1); // translate to origin
			HC_Close_Segment();

		HC_Close_Segment();

		// In order for HC_Gather_Capping_Geometry to work, calling UPDATE is mandatory
		m_pHView->Update();

		// key path from shell to SceneKey
		HC_KEY keypath[4] = { cutplaneSegment, m_pHView->GetModelKey(), m_pHView->GetIncludeLinkKey(), m_pHView->GetSceneKey() };

		HC_Open_Segment("segment only");
		HC_Gather_Capping_Geometry(4, keypath, section, "segment only");
		HC_Set_Color("face=(red,transmission=gray)");
		HC_Close_Segment();

		HC_Open_Segment("default");
		HC_Gather_Capping_Geometry(4, keypath, section, "");
		HC_Set_Color("face=(blue,transmission=blue)");
		HC_Translate_Object(0, 5, 0);
		HC_Close_Segment();

	
		// Delete cut pland and box to see capping geometry
		HC_Delete_By_Key(cutplaneSegment);

	} HC_Close_Segment();

	m_pHView->Update();
}

```

**Ignore Matrix:**

**Section Offset:** This option is only valid when you inserted a “cutting section”. This option will let you specify a single plane offset.

```auto
void CSolidHoopsView::OnExtraSlot5()
{

	HC_Open_Segment_By_Key(m_pHView->GetModelKey()); {

		int pcount, flist_count;
		pcount = 8;
		flist_count = 30;
		HPoint pts[8];
		int faces[30] = { 4, 0, 1, 2, 3,
			4, 1, 5, 6, 2,
			4, 5, 4, 7, 6,
			4, 4, 0, 3, 7,
			4, 3, 2, 6, 7,
			4, 0, 4, 5, 1 };
		pts[0].Set(0, 0, 0);
		pts[1].Set(2, 0, 0);
		pts[2].Set(2, 2, 0);
		pts[3].Set(0, 2, 0);
		pts[4].Set(0, 0, 2);
		pts[5].Set(2, 0, 2);
		pts[6].Set(2, 2, 2);
		pts[7].Set(0, 2, 2);
		
		float	planes[] = { 0, 0, -1, -0.0001,	1, 0, 0, -0.0001,	0, 1, 0, -0.0001 };

		HC_KEY cutplaneSegment = HC_Open_Segment("cut_plane");
			HC_KEY	section = HC_Insert_Cutting_Section(3, planes);
			HC_Open_Segment("section cuts y");					
				HC_Insert_Shell(pcount, pts, flist_count, faces);
				HC_Translate_Object(-1, -1, -1); // translate to origin
			HC_Close_Segment();
		HC_Close_Segment();

		// In order for HC_Gather_Capping_Geometry to work, calling UPDATE is mandatory
		m_pHView->Update();

		// key path from shell to SceneKey
		HC_KEY keypath[4] = { cutplaneSegment, m_pHView->GetModelKey(), m_pHView->GetIncludeLinkKey(), m_pHView->GetSceneKey() };

		HC_Open_Segment("section cuts x");
			HC_Gather_Capping_Geometry(4, keypath, section, "section offset = 1, refine cuts");
			HC_Set_Color("face=(green,transmission=gray)");
		HC_Close_Segment();

		HC_Open_Segment("section cuts y");
			HC_Gather_Capping_Geometry(4, keypath, section, "section offset = 2, refine cuts");
			HC_Set_Color("face=(blue,transmission=gray)");
		HC_Close_Segment();
		
        HC_Open_Segment("section cuts z");
			HC_Gather_Capping_Geometry(4, keypath, section, "section offset = 0, refine cuts");
			HC_Set_Color("face=(red,transmission=gray)");
		HC_Close_Segment();
		
		// Delete cut pland and box to see capping geometry
		HC_Delete_By_Key(cutplaneSegment);

	} HC_Close_Segment();

	m_pHView->Update();
}

```

Refine Cuts: This option will determine if capping geometry will be refine by all cutting planes in scene. Default (OFF), capping geometry is only generate by one cutting plane

```auto
void CSolidHoopsView::OnExtraSlot5()
{

	HC_Open_Segment_By_Key(m_pHView->GetModelKey()); {

		int pcount, flist_count;
		pcount = 8;
		flist_count = 30;
		HPoint pts[8];
		int faces[30] = { 4, 0, 1, 2, 3,
			4, 1, 5, 6, 2,
			4, 5, 4, 7, 6,
			4, 4, 0, 3, 7,
			4, 3, 2, 6, 7,
			4, 0, 4, 5, 1 };
		pts[0].Set(0, 0, 0);
		pts[1].Set(2, 0, 0);
		pts[2].Set(2, 2, 0);
		pts[3].Set(0, 2, 0);
		pts[4].Set(0, 0, 2);
		pts[5].Set(2, 0, 2);
		pts[6].Set(2, 2, 2);
		pts[7].Set(0, 2, 2);
		
		float	planes[] = { 0, 0, -1, -0.0001,	1, 0, 0, -0.0001,	0, 1, 0, -0.0001 };

		HC_KEY cutplaneSegment = HC_Open_Segment("cut_plane");
			HC_KEY	section = HC_Insert_Cutting_Plane(0, 0, -1, -0.0001);
			HC_Insert_Cutting_Plane(1, 0, 0, -0.0001);

			HC_Open_Segment("section cuts y");					
				HC_Insert_Shell(pcount, pts, flist_count, faces);
				HC_Translate_Object(-1, -1, -1); // translate to origin
			HC_Close_Segment();

		HC_Close_Segment();

		// In order for HC_Gather_Capping_Geometry to work, calling UPDATE is mandatory
		m_pHView->Update();

		// key path from shell to SceneKey
		HC_KEY keypath[4] = { cutplaneSegment, m_pHView->GetModelKey(), m_pHView->GetIncludeLinkKey(), m_pHView->GetSceneKey() };

		HC_Open_Segment("section cuts");
		HC_Gather_Capping_Geometry(4, keypath, section, "refine cuts");
		HC_Set_Color("face=(red,transmission=gray)");
		HC_Close_Segment();

		HC_Open_Segment("section default");
		HC_Gather_Capping_Geometry(4, keypath, section, "");
		HC_Set_Color("face=(blue,transmission=blue)");
		HC_Close_Segment();

	
		// Delete cut pland and box to see capping geometry
		HC_Delete_By_Key(cutplaneSegment);

	} HC_Close_Segment();

	m_pHView->Update();
}

```
