#include <OSGDVRClipper.h>
Public Member Functions | |
| DVRClipper (void) | |
| ~DVRClipper (void) | |
| void | clipSlice (DVRVolume *volume, DVRSlice &slice, const Vec3f &slicingNormal, Real32 dist2RefPlane, DVRRenderSlice &clippedSlice) |
| clips the slice | |
| void | initialize (DVRVolume *volume) |
| initialize the clipper | |
| void | reset (DVRVolume *volume) |
| Reset objects state. | |
| void | setReferencePlane (const Plane &refPlane) |
| const Plane & | getReferencePlane () const |
| bool | setNumAddPerVertexAttr (DVRVolume *volume, UInt32 additionalPerVertexAttributes) |
| set the number of additional per vertex attributes | |
Private Attributes | |
| bool | hasTesselatorSupport |
| GLUtesselator available? | |
| GLdouble * | sliceVertexData |
| Plane | refPlane |
| UInt32 | numAddPerVertexAttr |
Definition at line 13 of file OSGDVRClipper.h.
|
|
Definition at line 32 of file OSGDVRClipper.cpp. References GLdouble, hasTesselatorSupport, numAddPerVertexAttr, and sliceVertexData. 00033 { 00034 myTess = NULL; 00035 // allocate temp. storage for 6 vertex positions and texture coordinates 00036 sliceVertexData = (GLdouble*)malloc(6*6*sizeof(GLdouble)); 00037 00038 numAddPerVertexAttr = 0; 00039 hasTesselatorSupport = false; 00040 }
|
|
|
Definition at line 42 of file OSGDVRClipper.cpp. References sliceVertexData. 00043 { 00044 if(myTess) 00045 gluDeleteTess(myTess); 00046 00047 free(sliceVertexData); 00048 }
|
|
||||||||||||||||||||||||
|
Definition at line 191 of file OSGDVRClipper.cpp. References osg::DVRRenderSlice::clear(), osg::DVRTriangle::contourNeighbour, osg::DVRTriangle::cutPoint, osg::DVRClipObjects::Difference, DVRVOLUME_PARAMETER, osg::DVRSlice::getTextureScale(), osg::DVRSlice::getTextureTranslate(), osg::PointInterface< ValueTypeT, StorageInterfaceT >::getValues(), osg::DVRSlice::getVertex(), osg::DVRSlice::getVertexCount(), hasTesselatorSupport, osg::NullFC, numAddPerVertexAttr, osg::DVRClipObjects::Off, sliceVertexData, osg::DVRRenderSlicePrimitive::type, and osg::DVRRenderSlicePrimitive::vertices. Referenced by osg::Brick::render2DSliceXY(), osg::Brick::render2DSliceXZ(), osg::Brick::render2DSliceYZ(), and osg::Brick::render3DSlices(). 00196 { 00197 const Vec3f &texScale = unclippedSlice.getTextureScale (); 00198 const Vec3f &texTranslate = unclippedSlice.getTextureTranslate(); 00199 00200 // get clip objects 00201 DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 00202 DVRClipObjects); 00203 00204 // nothing to clip with? 00205 if(clipObjects == NullFC) 00206 { 00207 DVRRenderSlicePrimitive *newPrimitive = new DVRRenderSlicePrimitive(); 00208 00209 newPrimitive->type = GL_TRIANGLE_FAN; 00210 00211 for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++) 00212 { 00213 UInt32 idx = (6+numAddPerVertexAttr)*i; 00214 sliceVertexData[idx ] = 00215 unclippedSlice.getVertex(i).getValues()[0]; 00216 00217 sliceVertexData[idx + 1] = 00218 unclippedSlice.getVertex(i).getValues()[1]; 00219 00220 sliceVertexData[idx + 2] = 00221 unclippedSlice.getVertex(i).getValues()[2]; 00222 00223 00224 // set (standard) texture coordinates 00225 sliceVertexData[idx + 3] = 00226 texScale[0] * 00227 unclippedSlice.getVertex(i).getValues()[0] + 00228 texTranslate[0]; 00229 00230 sliceVertexData[idx + 4] = 00231 texScale[1] * 00232 unclippedSlice.getVertex(i).getValues()[1] + 00233 texTranslate[1]; 00234 00235 sliceVertexData[idx + 5] = 00236 texScale[2] * 00237 unclippedSlice.getVertex(i).getValues()[2] + 00238 texTranslate[2]; 00239 00240 newPrimitive->vertices.push_back(&sliceVertexData[idx]); 00241 } 00242 00243 clippedSlice.push_back(newPrimitive); 00244 00245 return; 00246 } 00247 00248 if(!hasTesselatorSupport) 00249 return; 00250 00251 // render colored contours only (usefull for debugging) 00252 if(clipObjects->getDoContours()) 00253 { 00254 glDisable(GL_TEXTURE ); 00255 glDisable(GL_LIGHTING ); 00256 00257 glBegin (GL_LINE_STRIP); 00258 { 00259 int col = 0; 00260 00261 for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++) 00262 { 00263 glColor3f(col % 3 == 0 ? 1.0f : 0.0f, 00264 col % 3 == 1 ? 1.0f : 0.0f, 00265 col % 3 == 2 ? 1.0f : 0.0f); 00266 00267 col++; 00268 00269 glVertex3fv(unclippedSlice.getVertex(i).getValues()); 00270 } 00271 } 00272 glEnd(); 00273 00274 bool clipAwayOutside = 00275 clipObjects->getClipMode() == DVRClipObjects::Difference; 00276 00277 for(UInt32 i = 0; i < clipObjects->count(); i++) 00278 { 00279 // get i-th clip object 00280 DVRClipGeometryPtr clipObject = clipObjects->get(i); 00281 00282 // compute the contours of the triangles intersecting the 00283 // current slice 00284 00285 const DVRTriangleList &contours = 00286 clipObject->getContours(dist2RefPlane, 00287 !clipAwayOutside, 00288 slicingNormal); 00289 00290 if(!contours.empty()) 00291 { 00292 DVRTriangle *current; 00293 DVRTriangle *contourStart; 00294 00295 // iterate over all contours 00296 DVRTriangleList::const_iterator contoursIt; 00297 00298 for(contoursIt = contours.begin(); 00299 contoursIt != contours.end (); 00300 contoursIt++) 00301 { 00302 contourStart = current = *contoursIt; 00303 00304 glBegin(GL_LINE_STRIP); 00305 { 00306 int col = 0; 00307 00308 // iterate over all triangles in the current contour 00309 do 00310 { 00311 glColor3f(col % 3 == 0 ? 1.0f : 0.0f, 00312 col % 3 == 1 ? 1.0f : 0.0f, 00313 col % 3 == 2 ? 1.0f : 0.0f); 00314 00315 col++; 00316 00317 glVertex3dv(current->cutPoint); 00318 00319 current = current->contourNeighbour; 00320 00321 } while(current!= contourStart); 00322 } 00323 glEnd(); 00324 } 00325 } 00326 } 00327 00328 glEnable(GL_TEXTURE ); 00329 glEnable(GL_LIGHTING); 00330 00331 } 00332 else 00333 { 00334 // tesselate and render the clipped slices 00335 00336 // set the slice normal for tesselation 00337 gluTessNormal(myTess, 00338 slicingNormal[0], 00339 slicingNormal[1], 00340 slicingNormal[2]); 00341 00342 clippedSlice.clear(); 00343 00344 gluTessBeginPolygon(myTess, &clippedSlice); 00345 00346 // set the slice's base contour 00347 gluTessBeginContour(myTess); 00348 00349 for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++) 00350 { 00351 UInt32 idx = (6 + numAddPerVertexAttr) * i; 00352 00353 sliceVertexData[idx ] = 00354 unclippedSlice.getVertex(i).getValues()[0]; 00355 00356 sliceVertexData[idx + 1] = 00357 unclippedSlice.getVertex(i).getValues()[1]; 00358 00359 sliceVertexData[idx + 2] = 00360 unclippedSlice.getVertex(i).getValues()[2]; 00361 00362 // set (standard) texture coordinates 00363 sliceVertexData[idx + 3] = 00364 texScale[0] * 00365 unclippedSlice.getVertex(i).getValues()[0] + 00366 texTranslate[0]; 00367 00368 sliceVertexData[idx + 4] = 00369 texScale[1] * 00370 unclippedSlice.getVertex(i).getValues()[1] + 00371 texTranslate[1]; 00372 00373 sliceVertexData[idx + 5] = 00374 texScale[2] * 00375 unclippedSlice.getVertex(i).getValues()[2] + 00376 texTranslate[2]; 00377 00378 gluTessVertex(myTess, 00379 &sliceVertexData[idx], 00380 &sliceVertexData[idx]); 00381 } 00382 00383 gluTessEndContour(myTess); 00384 00385 // set contours of clip objects 00386 if(clipObjects->getClipMode() != DVRClipObjects::Off) 00387 { 00388 // get clip mode 00389 bool clipAwayOutside = 00390 clipObjects->getClipMode() == DVRClipObjects::Difference; 00391 00392 // add the contours of the intersections of the clip geometries 00393 // with the slice 00394 for(UInt32 i = 0; i < clipObjects->count(); i++) 00395 { 00396 // get i-th clip object 00397 DVRClipGeometryPtr clipObject = clipObjects->get(i); 00398 00399 // compute the contours of the triangles intersecting 00400 // the current slice 00401 00402 const DVRTriangleList &contours = 00403 clipObject->getContours( dist2RefPlane, 00404 !clipAwayOutside, 00405 slicingNormal); 00406 00407 if(!contours.empty()) 00408 { 00409 DVRTriangle *current; 00410 DVRTriangle *contourStart; 00411 00412 // iterate over all contours 00413 DVRTriangleList::const_iterator contoursIt; 00414 00415 for(contoursIt = contours.begin(); 00416 contoursIt != contours.end (); 00417 contoursIt++) 00418 { 00419 contourStart = current = *contoursIt; 00420 00421 // start new contour 00422 gluTessBeginContour(myTess); 00423 00424 // iterate over all triangles in the current contour 00425 do 00426 { 00427 // set (standard) texture coordinates 00428 current->cutPoint[3] = 00429 texScale[0] * 00430 current->cutPoint[0] + 00431 texTranslate[0]; 00432 00433 current->cutPoint[4] = 00434 texScale[1] * 00435 current->cutPoint[1] + 00436 texTranslate[1]; 00437 00438 current->cutPoint[5] = 00439 texScale[2] * 00440 current->cutPoint[2] + 00441 texTranslate[2]; 00442 00443 if(!current->cutPoint) 00444 std::cerr << "WTF: cutPoint is NULL" 00445 << std::endl; 00446 00447 gluTessVertex(myTess, 00448 current->cutPoint, 00449 current->cutPoint); 00450 00451 current = current->contourNeighbour; 00452 00453 } while(current != contourStart); 00454 00455 gluTessEndContour(myTess); 00456 } 00457 } 00458 } 00459 } 00460 00461 gluTessEndPolygon(myTess); 00462 } 00463 }
|
|
|
Definition at line 104 of file OSGDVRClipper.cpp. References beginCallback(), DVRVOLUME_PARAMETER, endCallback(), errorCallback(), hasTesselatorSupport, osg::NullFC, vertexCallback(), and vertexCombineCallback(). Referenced by osg::DVRVolume::draw(). 00105 { 00106 if(volume == NULL) 00107 return; 00108 00109 // get clip objects 00110 DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 00111 DVRClipObjects); 00112 00113 if(clipObjects == NullFC) 00114 return; 00115 00116 if(!hasTesselatorSupport) 00117 { 00118 // check for glu tesselator support 00119 hasTesselatorSupport = (atof((char*)gluGetString(GLU_VERSION)) >= 1.2); 00120 00121 if(!hasTesselatorSupport) 00122 return; 00123 } 00124 00125 if(myTess == NULL) 00126 { 00127 myTess = gluNewTess(); 00128 00129 // registering callback functions for glu tesselator... 00130 gluTessCallback(myTess, 00131 GLU_TESS_COMBINE_DATA, 00132 (GLvoid (CALLBACK *)()) vertexCombineCallback); 00133 00134 gluTessCallback(myTess, 00135 GLU_TESS_VERTEX_DATA, 00136 (GLvoid (CALLBACK *)()) vertexCallback); 00137 00138 gluTessCallback(myTess, 00139 GLU_TESS_BEGIN_DATA, 00140 (GLvoid (CALLBACK *)()) beginCallback); 00141 00142 gluTessCallback(myTess, 00143 GLU_TESS_END_DATA, 00144 (GLvoid (CALLBACK *)()) endCallback); 00145 00146 gluTessCallback(myTess, 00147 GLU_TESS_ERROR, 00148 (GLvoid (CALLBACK *)()) errorCallback); 00149 00150 } 00151 00152 }
|
|
|
Definition at line 154 of file OSGDVRClipper.cpp. References DVRVOLUME_PARAMETER, hasTesselatorSupport, osg::DVRClipObjects::Intersection, and osg::NullFC. Referenced by osg::DVRVolume::draw(), and osg::Brick::render3DSlices(). 00155 { 00156 if(volume == NULL || !hasTesselatorSupport) 00157 return; 00158 00159 // get clip objects 00160 DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 00161 DVRClipObjects); 00162 00163 if(clipObjects == NullFC) 00164 return; 00165 00166 // set tesselator properties according to clip mode 00167 if(clipObjects->getClipMode() == DVRClipObjects::Intersection) 00168 { 00169 gluTessProperty(myTess, 00170 GLU_TESS_WINDING_RULE, 00171 GLU_TESS_WINDING_ABS_GEQ_TWO); 00172 } 00173 else 00174 { 00175 gluTessProperty(myTess, 00176 GLU_TESS_WINDING_RULE, 00177 GLU_TESS_WINDING_POSITIVE); 00178 } 00179 00180 // reset local data 00181 for(UInt32 i = 0; i < clipObjects->count(); i++) 00182 { 00183 // reset i-th clip object 00184 DVRClipGeometryPtr clipObject = clipObjects->get(i); 00185 00186 clipObject->resetLocalData (); 00187 clipObject->computeSeedVertices(); 00188 } 00189 }
|
|
|
Definition at line 50 of file OSGDVRClipper.cpp. References FDEBUG, osg::Plane::getDistanceFromOrigin(), osg::Plane::getNormal(), refPlane, and osg::Plane::set(). Referenced by osg::DVRVolume::initializeClipObjects(). 00051 { 00052 FDEBUG(("pre DVRVolume::setRefPlane - %f %f %f : %f\n", 00053 rP.getNormal()[0], 00054 rP.getNormal()[1], 00055 rP.getNormal()[2], 00056 rP.getDistanceFromOrigin())); 00057 00058 refPlane.set(rP.getNormal(), rP.getDistanceFromOrigin()); 00059 00060 FDEBUG(("post DVRVolume::setRefPlane - %f %f %f : %f\n", 00061 refPlane.getNormal()[0], 00062 refPlane.getNormal()[1], 00063 refPlane.getNormal()[2], 00064 refPlane.getDistanceFromOrigin())); 00065 }
|
|
|
Definition at line 67 of file OSGDVRClipper.cpp. References refPlane. Referenced by osg::Brick::render2DSliceXY(), osg::Brick::render2DSliceXZ(), and osg::Brick::render2DSliceYZ(). 00068 { 00069 return refPlane; 00070 }
|
|
||||||||||||
|
basically there are two attributes available, the vertex position and a 3D texture coordinate. If one needs additional attributes, e.g. color, texture coordinates,.., the number of (double) values needed has to be set with this function. Definition at line 73 of file OSGDVRClipper.cpp. References DVRVOLUME_PARAMETER, GLdouble, osg::NullFC, numAddPerVertexAttr, and sliceVertexData. 00076 { 00077 numAddPerVertexAttr = additionalPerVertexAttributes; 00078 00079 sliceVertexData = (GLdouble*) realloc( 00080 sliceVertexData, 00081 6 * (6 + additionalPerVertexAttributes) * sizeof(GLdouble)); 00082 00083 if(!sliceVertexData) 00084 return false; 00085 00086 // get clip objects 00087 DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 00088 DVRClipObjects); 00089 00090 if(clipObjects == NullFC) 00091 return true; 00092 00093 for(UInt32 i = 0; i < clipObjects->count(); i++) 00094 { 00095 DVRClipGeometryPtr clipObject = clipObjects->get(i); 00096 00097 if(!clipObject->setNumAddPerVertexAttr(additionalPerVertexAttributes)) 00098 return false; 00099 } 00100 return true; 00101 }
|
|
|
Definition at line 53 of file OSGDVRClipper.h. Referenced by clipSlice(), DVRClipper(), initialize(), and reset(). |
|
|
Definition at line 62 of file OSGDVRClipper.h. Referenced by clipSlice(), DVRClipper(), setNumAddPerVertexAttr(), and ~DVRClipper(). |
|
|
Definition at line 65 of file OSGDVRClipper.h. Referenced by getReferencePlane(), and setReferencePlane(). |
|
|
Definition at line 68 of file OSGDVRClipper.h. Referenced by clipSlice(), DVRClipper(), and setNumAddPerVertexAttr(). |
1.4.3