Sample Code (3DF): HC_Gather_Capping_Geometry

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

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.

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

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();
}