Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphics Graphics Korea University cgvr.korea.ac.kr 1 Applying Actions 강 신 진 2001. 08. 22.

Similar presentations


Presentation on theme: "Graphics Graphics Korea University cgvr.korea.ac.kr 1 Applying Actions 강 신 진 2001. 08. 22."— Presentation transcript:

1 Graphics Graphics Lab @ Korea University cgvr.korea.ac.kr 1 Applying Actions 강 신 진 2001. 08. 22

2 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 2 Inventor Actions General Model Applying an Action Rendering Calculating a Bounding Box Accumulating a Transformation Matrix Writing to a File Searching for a Node Picking Contents

3 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 3 Inventor Actions Available Action List Using This ActionYou Can Perform This Task SoGetBoundingBoxActionCompute a 3D bounding box SoGetMatrixAcionCompute a transformation matrix SoWriteActionWrite Scene graph to a file SoSearchActionSearch for paths to specific nodes SoHandleEventActionAllow object to handle an event SoRayPickActionPick object in the scene graph along a ray SoCallBackActionTraverse the scene graph and perform your own action using callback function SoGLRenderAction Draw, or render, the scene graph

4 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 4 General Model Initialize the action SbViewportRegion region(300, 200); SoGLRenderAction renderAction(region); Set up special parameters for the action SoGLRenderAction renderAction(region, TRUE); Apply the action to a node renderAction->apply(root) Obtain the result of the action, if possible

5 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 5 Applying an Action Action Application Node Path Path list Traversal state Internal class to store transient state elements Inventor database management

6 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 6 Rendering - Execution Execution of SoGLRenderAction If the node is a group >>Visit each children If the node is a property group >>Replace a value of traversal state If the node is derived from SoTransformation >>Modify the current transformation If the node is shape node >>Draw shape using the current element

7 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 7 Rendering - Transparency Setting the Transparency Quality setTransparencyType() Transparency Levels  SCREEN_DOOR  ADD  DELAYED_ADD  SORTED_OBJECT_ADD  BLEND  DELAYED_BLEND  SORTED_OBJECT_BLEND

8 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 8 Rendering - Antialiasing 2 Types of Antialiasing Smoothing Using the Accumulation Buffer Smoothing SoGLRenderAction :: setSmoothing(SbBool smooth) Accumulation Buffer SoGLRenderAction :: setNumPasses(int num)

9 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 9 Rendering - Off-screen Rendering SoOffScreenRenderer Class Render an image into off-screen memory buffer  To generate image for a PostScript printer  To generate image for a Texture map SoOffScreenRenderer :: SetComponent(Components components)  LUMIANCE  LUMIANCE_TRANSPARENCY  RGB  RGB_TRANSPARENCY

10 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 10 Rendering - Source TEXTURE MAPPING SbBool generateTextureMap (SoNode *root, SoTexture2 *texture, short textureWidth, short textureHeight) { SbViewportRegion myViewport(textureWidth, textureHeight); // Render the scene SoOffscreenRenderer *myRenderer = new SoOffscreenRenderer(myViewport); myRenderer->setBackgroundColor(SbColor(0.3, 0.3, 0.3)); if (!myRenderer->render(root)) { delete myRenderer; return FALSE; } // Generate the texture texture->image.setValue(SbVec2s(textureWidth, textureHeight), SoOffscreenRenderer::RGB, myRenderer->getBuffer()); delete myRenderer; return TRUE; }

11 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 11 Rendering - Caching Saving of an operation Don’t need to traverse the scene graph every time SoSeparator node has 2 field for caching render caching:  renderCaching(SoSFEnum) bounding-box caching  boundingBoxCaching(SoSFEnum)  SoSFEnum => AUTO, ON, OFF How Caching Working Check a valid cache existence Ignore below scene graph and use cache(if C exists)

12 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 12 Calculating a Bounding Box Create an instance of the action sbViewportRegion vpReg; vpReg.setWindowSize(300, 200); SoGetBoundingBoxAction bboxAction(vpReg); Apply the Action bboxAction.apply(root); Obtain Result SoTransform *myTransform; myTransform->center = bboxAction.getCenter();

13 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 13 Accumulating a Transformation Matrix Create an instance of the action soGetMatrixAction mtxAction Apply the Action getMatrix() getInverse()

14 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 14 Writing to a File SoWriteAction class is used SoWriteAction myAction; Writing in binary with file pointer FILE *fp; myAction.getOutput()->setBinary(TRUE); myAction.getOutput()->setFilePointer(fp); myAction.apply(root); Writing in ASCII myAction.getOutput()->openFile(“file.iv”); myAciton.getOutput()->setBinary(FALSE); myAction.apply(root); myAction.getOutput()->closeFile();

15 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 15 Searching for a Node Example SoSearchAction mySearchAction mySearchAction.setType(SoLight::getClassTrypeId()); mySearchAction.setInterest (SoSearchAction::FIRST); mySearchAction.apply(root); If(mySearchAction.getPath() == NULL){ SoDirectionLight *myLight = new SoDirectionalLight; root->insertChild(myLight, 0); }

16 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 16 Picking –1 SoRayPickAction is used Find objects along a ray from the camera

17 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 17 Picking – 2 Specifying the Picking Ray SbViewportRegion viewport(400, 300); SbVec2s cursorPosition(250, 150); SoRayPickAction myPickAction(viewport); myPickAction.setRay(SbVec3f(0.0, 0.0, 0.0), //starting point SbVec3f(0.0, 0.0, -1.0)); //direction vector pickAction->apply(rootNode); Obtain result SoPath *pathToPickObject; Const SoPickPoint *myPickedPoint = pickAction.getPickedPoint(); If(myPickedPoint != NULL) pathToPickedobject = myPickedPoint->getPath();

18 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 18 Picking – 2 SoDetail Have an additional information about the pick Classes that store an SoDetail Class nameType of detail added SoCubeSoCubeDetail SoCylinderSoCylinderDetail SoPointSetSoPointDetail SoConeSoConeDetail

19 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 19 Using the Pick Action Writing the path to the Picked Object SbBool writePickedPath (SoNode *root, const SbViewportRegion &viewport, const SbVec2s &cursorPosition) { SoRayPickAction PickAction(viewport); PickAction.setPoint(cursorPosition); PickAction.setRadius(8.0); PickAction.apply(root); const SoPickedPoint *myPickedPoint = pickAction.getPickedPoint(); If(myPickedPoint == NULL) return FALSE; SoWriteAction myWriteAction; myWrtieAction.apply(myPickedPoint->getpath()); return TRUE; }

20 CGVR Graphics Lab @ Korea University cgvr.korea.ac.kr 20 Calling Back to the Application SoCallbackAction Method which is called whenever a specified node encountered during the traversal Void printSpheres(SoNode *root) { SoCallbackAction myAction; myAction.addPreCallback(SoSphere::getClassTypeId(), printHeaderCallback, NULL); myAction.addTriangleCallback(SoSphere::getClassTypeId(), printTriangleCallback, NULL); myAction.apply(root); }


Download ppt "Graphics Graphics Korea University cgvr.korea.ac.kr 1 Applying Actions 강 신 진 2001. 08. 22."

Similar presentations


Ads by Google