PowerPoint Template
Download
Report
Transcript PowerPoint Template
Graphics
Applying Actions
강신진
2001. 08. 22
cgvr.korea.ac.kr
1
Graphics Lab @ Korea University
Contents
CGVR
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
cgvr.korea.ac.kr
2
Graphics Lab @ Korea University
Inventor Actions
CGVR
Available Action List
Using This Action
You Can Perform This Task
SoGetBoundingBoxAction
Compute a 3D bounding box
SoGetMatrixAcion
Compute a transformation matrix
SoWriteAction
Write Scene graph to a file
SoSearchAction
Search for paths to specific nodes
SoHandleEventAction
Allow object to handle an event
SoRayPickAction
Pick object in the scene graph along a ray
SoCallBackAction
Traverse the scene graph and perform your
own action using callback function
SoGLRenderAction
Draw, or render, the scene graph
cgvr.korea.ac.kr
3
Graphics Lab @ Korea University
General Model
CGVR
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
cgvr.korea.ac.kr
4
Graphics Lab @ Korea University
Applying an Action
Action Application
CGVR
Node
Path
Path list
Traversal state
Internal class to store transient state elements
Inventor database management
cgvr.korea.ac.kr
5
Graphics Lab @ Korea University
Rendering - Execution
CGVR
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
cgvr.korea.ac.kr
6
Graphics Lab @ Korea University
Rendering - Transparency
Setting the Transparency Quality
CGVR
setTransparencyType()
Transparency Levels
SCREEN_DOOR
ADD
DELAYED_ADD
SORTED_OBJECT_ADD
BLEND
DELAYED_BLEND
SORTED_OBJECT_BLEND
cgvr.korea.ac.kr
7
Graphics Lab @ Korea University
Rendering - Antialiasing
2 Types of Antialiasing
Smoothing
Using the Accumulation Buffer
Smoothing
CGVR
SoGLRenderAction :: setSmoothing(SbBool smooth)
Accumulation Buffer
SoGLRenderAction :: setNumPasses(int num)
cgvr.korea.ac.kr
8
Graphics Lab @ Korea University
Rendering - Off-screen
Rendering
CGVR
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
cgvr.korea.ac.kr
9
Graphics Lab @ Korea University
Rendering - Source
CGVR
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;
}
cgvr.korea.ac.kr
10
Graphics Lab @ Korea University
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
CGVR
boundingBoxCaching(SoSFEnum)
SoSFEnum => AUTO, ON, OFF
How Caching Working
Check a valid cache existence
Ignore below scene graph and use cache(if C exists)
cgvr.korea.ac.kr
11
Graphics Lab @ Korea University
Calculating a Bounding Box
Create an instance of the action
sbViewportRegion vpReg;
vpReg.setWindowSize(300, 200);
SoGetBoundingBoxAction bboxAction(vpReg);
Apply the Action
CGVR
bboxAction.apply(root);
Obtain Result
SoTransform *myTransform;
myTransform->center = bboxAction.getCenter();
cgvr.korea.ac.kr
12
Graphics Lab @ Korea University
Accumulating a
Transformation Matrix
Create an instance of the action
CGVR
soGetMatrixAction mtxAction
Apply the Action
getMatrix() getInverse()
cgvr.korea.ac.kr
13
Graphics Lab @ Korea University
Writing to a File
CGVR
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();
cgvr.korea.ac.kr
14
Graphics Lab @ Korea University
Searching for a Node
CGVR
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);
}
cgvr.korea.ac.kr
15
Graphics Lab @ Korea University
Picking –1
CGVR
SoRayPickAction is used
Find objects along a ray from the camera
cgvr.korea.ac.kr
16
Graphics Lab @ Korea University
Picking – 2
CGVR
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();
cgvr.korea.ac.kr
17
Graphics Lab @ Korea University
Picking – 2
SoDetail
CGVR
Have an additional information about the pick
Classes that store an SoDetail
Class name
Type of detail added
SoCube
SoCubeDetail
SoCylinder
SoCylinderDetail
SoPointSet
SoPointDetail
SoCone
SoConeDetail
cgvr.korea.ac.kr
18
Graphics Lab @ Korea University
Using the Pick Action
CGVR
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;
}
cgvr.korea.ac.kr
19
Graphics Lab @ Korea University
Calling Back to the
Application
CGVR
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);
}
cgvr.korea.ac.kr
20
Graphics Lab @ Korea University