Cross Sections and Views in Teigha PRC

Alexander Borovikov

September 26, 2017

Cross Sections and Views in Teigha PRC

With Teigha PRC it is possible to create named views with or without cross sections.

Creating views

To include a custom view in a .pdf document, you must create a special view object in Teigha PRC and set up a camera for the view.

You can see a cross section example in the CrossSectionExample.cpp file:

void simpleCrossSectionExample(OdStreamBufPtr pPrcStream, CreationMode mode, OdDbHostAppServices &pH, OdPrcHostAppServices &pPrcHost)
 
… // create view
 
{ 
OdPrcViewPtr pNewView = OdPrcView::createObject(); 
pNewFileStructure->addObject(pNewView); 
OdPrcName name; 
name.setName(L"NE Isometric"); 
pNewView->name() = name; 
// - add view to PO 
OdPrcProductOccurrencePtr productOc = pFile->fileStructures().last()->fileStructureTree().productOccurrence().last(); 
OdPrcObjectIdArray &arr_view = productOc->annotationViews(); 
arr_view.push_back(pNewView->id()); 
OdPrcSceneDisplayParametersPtr pSceneDisplayParameters = OdPrcSceneDisplayParameters::createObject(); pNewFileStructure->addObject(pSceneDisplayParameters); 
pNewView->sceneDisplayParameters() = pSceneDisplayParameters->id(); 

// - set up camera for view 
OdPrcCameraPtr pCamera = OdPrcCamera::createObject(); 
pNewFileStructure->addObject(pCamera); 
pCamera->lookAt().set(0.0, 0.0, 0.0); 
pCamera->up().set(0.0, 0.0, 1.0); 
pCamera->location().set(5.0, 5.0, 5.0); 
pCamera->setXFov(1.0472); 
pCamera->setYFov(1.0472); 
pSceneDisplayParameters->camera() = pCamera->id(); 
} 
… 

The example shows how to create scene display parameters and set up a camera, including the camera target, position, and up vector. Notice the camera field of the view parameter: the scale is set based on this parameter. Don’t forget to name the view, which will be available in the views list of the .pdf file.

name.setName(L"NE Isometric"); 
pNewView->name() = name; 

The created view becomes available in the list of views:

image1

When the created view is applied:

image2

Creating cross sections

To include views with cross sections in a .pdf document, first create a custom view, and then set up a clipping plane.

Here is a cross section example:

void simpleCrossSectioExample(OdStreamBufPtr pPrcStream, CreationMode mode, OdDbHostAppServices &pH, OdPrcHostAppServices &pPrcHost)
 … 
// create view with XZ clipping plane 
{ 
OdPrcViewPtr pNewView = OdPrcView::createObject(); 
pNewFileStructure->addObject(pNewView); 
OdPrcName name; 
name.setName(L"NE Isometric clipped by XZ"); 
pNewView->name() = name; 
// - add view to PO 
OdPrcProductOccurrencePtr productOc = pFile->
fileStructures().last()->fileStructureTree().productOccurrence().last(); 
OdPrcObjectIdArray &arr_view = productOc->annotationViews(); 
arr_view.push_back(pNewView->id()); 
OdPrcSceneDisplayParametersPtr pSceneDisplayParameters = OdPrcSceneDisplayParameters::createObject(); pNewFileStructure->addObject(pSceneDisplayParameters); 
pNewView->sceneDisplayParameters() = pSceneDisplayParameters->id(); 
// - set up camera for view 
OdPrcCameraPtr pCamera = OdPrcCamera::createObject(); 
pNewFileStructure->addObject(pCamera); 
pCamera->lookAt().set(0.0, 0.0, 0.0); 
pCamera->up().set(0.0, 0.0, 1.0); 
pCamera->location().set(5.0, 5.0, 5.0); 
pCamera->setXFov(1.0472); 
pCamera->setYFov(1.0472); 
pSceneDisplayParameters->camera() = pCamera->id(); 
// - add clipping plane to the view 
OdPrcSurfacePtrArray &viewClippingPlanes = ((OdPrcSceneDisplayParameters*)pSceneDisplayParameters)->clippingPlanes(); 
OdPrcPlanePtr pPlane = OdPrcPlane::createObject(); 
OdGeVector3d normal(0.0, 1.0, 0.0); 
OdGePoint3d origin(0.0, 0.0, 0.0); 
normal.normalize(); 
OdGePlane gePlane(origin, normal); 
OdGeInterval intU(-3., 3); 
OdGeInterval intV(-3., 3); 
setPlaneEnvelope(&gePlane, intU, intV); 
pPlane->setFromOdGeSurface(gePlane); 
viewClippingPlanes.push_back(pPlane); 
} 
… 

After setting up the camera, add clipping planes to the scene display parameters. Set the normal vector for the clipping plane (it is in the direction of the section part of the object to be removed).

image3

Notice that while the PRC format specification doesn’t explicitly prohibit creation of several clipping planes per view (clipping planes are actually stored in an array, suggesting that several clipping planes per single view are possible), Adobe Reader doesn’t support this feature so only one clipping plane is used.

For another example, see the OdaPrcApp command in the PrcCrossSectionCommands.cpp file.

void _CROSSSECTION_func (OdEdCommandContext* pCmdCtx) 
…
image4