CMS 3D CMS Logo

IgSoGridPlaneMap Class Reference

A planar slice (e.g. More...

#include <Iguana/Inventor/interface/IgSoGridPlaneMap.h>

List of all members.

Public Member Functions

 IgSoGridPlaneMap (void)
void setCaller (IgSoGridPlane *caller)

Static Public Member Functions

static void initClass (void)

Public Attributes

SoSFColor color
SbVec3f labelSpot [3]
SoSFBool on
SoSFPlane plane
SoSFBool refreshScale
SoSFFloat spacing
SoSFFloat xLen
SoSFFloat xOrigin
SoSFFloat zLen
SoSFFloat zOrigin

Protected Member Functions

virtual void computeBBox (SoAction *, SbBox3f &box, SbVec3f &center)
virtual void generatePrimitives (SoAction *action)
virtual void GLRender (SoGLRenderAction *renderAction)
virtual ~IgSoGridPlaneMap (void)

Private Member Functions

 SO_NODE_HEADER (IgSoGridPlaneMap)

Private Attributes

SbVec3f m_curCorner [3]
IgSoGridPlanem_gridPlane


Detailed Description

A planar slice (e.g.

of volumetric data) drawn as a colour map.

Definition at line 26 of file IgSoGridPlaneMap.h.


Constructor & Destructor Documentation

IgSoGridPlaneMap::IgSoGridPlaneMap ( void   ) 

Definition at line 54 of file IgSoGridPlaneMap.cc.

References color, f, FALSE, labelSpot, LL, LR, m_curCorner, on, plane, refreshScale, spacing, TRUE, UL, xLen, xOrigin, zLen, and zOrigin.

00054                                         : 
00055         m_gridPlane (0)
00056 {
00057         SO_NODE_CONSTRUCTOR (IgSoGridPlaneMap);
00058         SO_NODE_ADD_FIELD (plane, (SbPlane (SbVec3f (0.0f, 1.0f, 0.0f), 0.f)));
00059         SO_NODE_ADD_FIELD (xOrigin, (0.0f));
00060         SO_NODE_ADD_FIELD (zOrigin, (0.0f));
00061         SO_NODE_ADD_FIELD (xLen, (7.0f));
00062         SO_NODE_ADD_FIELD (zLen, (16.0f));
00063         SO_NODE_ADD_FIELD (spacing, (1000.0f));
00064         SO_NODE_ADD_FIELD (on, (FALSE));
00065         SO_NODE_ADD_FIELD (color, (SbVec3f (1,1,1)));
00066         SO_NODE_ADD_FIELD (refreshScale, (TRUE));
00067         
00068         m_curCorner[LL].setValue (SbVec3f (-1,0,-1));
00069         m_curCorner[LR].setValue (SbVec3f ( 1,0,-1));
00070         m_curCorner[UL].setValue (SbVec3f (-1,0, 1));
00071         
00072         labelSpot[LL].setValue (SbVec3f (-1,0,-1));
00073         labelSpot[LR].setValue (SbVec3f ( 1,0,-1));
00074         labelSpot[UL].setValue (SbVec3f (-1,0, 1));
00075 }

IgSoGridPlaneMap::~IgSoGridPlaneMap ( void   )  [protected, virtual]

Definition at line 92 of file IgSoGridPlaneMap.cc.

00093 {}


Member Function Documentation

void IgSoGridPlaneMap::computeBBox ( SoAction *  ,
SbBox3f &  box,
SbVec3f &  center 
) [protected, virtual]

Definition at line 99 of file IgSoGridPlaneMap.cc.

References f, LL, LR, m_curCorner, pyDBSRunClass::temp, and UL.

00100 {
00101         //center.setValue (0,0,0);
00102         
00103         box.extendBy (m_curCorner[LL]);
00104         box.extendBy (m_curCorner[LR]);
00105         box.extendBy (m_curCorner[UL]);
00106         box.extendBy (m_curCorner[LR] + m_curCorner[UL] - m_curCorner[LL]);
00107         
00108         SbVec3f temp (0.5f * (m_curCorner[LR] + m_curCorner[UL]));
00109         center = temp;
00110 }

void IgSoGridPlaneMap::generatePrimitives ( SoAction *  action  )  [protected, virtual]

Definition at line 261 of file IgSoGridPlaneMap.cc.

References dir, f, i, LL, LLCorner(), LR, LRCorner(), m_curCorner, normVec(), plane, rot, spacing, state, cmsRelvalreportInput::step, UL, ULCorner(), X_AXIS, xLen, xOrigin, Z_AXIS, zLen, and zOrigin.

00262 {
00263         SoState* state = action->getState ();
00264         state->push ();
00265         
00266         SoShapeHintsElement::set (state, SoShapeHintsElement::COUNTERCLOCKWISE,
00267                                         SoShapeHintsElement::UNKNOWN_SHAPE_TYPE,
00268                                         SoShapeHintsElement::CONVEX);
00269                                         
00270         SoPrimitiveVertex vertex;
00271         SoLineDetail      lineDetail;
00272         SoPointDetail     pointDetail;
00273 
00274         vertex.setDetail (&pointDetail);
00275         vertex.setMaterialIndex (0);
00276         
00277         // same normal and material for all points
00278         pointDetail.setNormalIndex (0);
00279         pointDetail.setTextureCoordIndex (0);
00280         pointDetail.setMaterialIndex (0);
00281         
00282         lineDetail.setPartIndex (0);
00283         lineDetail.setLineIndex (0);
00284         
00285         SbPlane currentPlane;
00286         SbVec3f currentCenter;
00287         SbVec3f currentNormal;
00288         SbLine normalLine;
00289 
00290         currentPlane = plane.getValue ();
00291         currentNormal = currentPlane.getNormal ();
00292         normalLine.setValue (SbVec3f (0.,0.,0.), currentNormal);
00293         currentPlane.intersect (normalLine, currentCenter);
00294         
00295         // calculate the plane normal's deviation from (0,1,0) vector
00296         const SbRotation rot (normVec, currentNormal);
00297         vertex.setNormal (currentNormal);
00298                 
00299         // rotate the corners accordingly
00300         rot.multVec (LLCorner, m_curCorner[LL]);
00301         rot.multVec (LRCorner, m_curCorner[LR]);
00302         rot.multVec (ULCorner, m_curCorner[UL]);
00303         
00304         // grid line direction
00305         SbVec3f dir[2];
00306         
00307         dir[X_AXIS] = m_curCorner[LR] - m_curCorner[LL];
00308         dir[Z_AXIS] = m_curCorner[UL] - m_curCorner[LL];
00309         
00310         dir[X_AXIS].normalize ();
00311         dir[Z_AXIS].normalize ();
00312         
00313         // move the center according to the users wishes
00314         currentCenter = currentCenter + dir[X_AXIS] * xOrigin.getValue () + dir[Z_AXIS] * zOrigin.getValue ();
00315 
00316         // length of the displayed lines
00317         float lineLen[2] = {xLen.getValue (), zLen.getValue ()};
00318         
00319         // length of one step (user value is in milimeters)
00320         float stepLength = spacing.getValue () / 1000.0f;
00321         float division[2] = {lineLen[X_AXIS] / stepLength, lineLen[Z_AXIS] / stepLength};
00322         
00323         // correct the length and number of lines to a integer multiplicative
00324         // of a square
00325         for (unsigned axis = X_AXIS; axis <= Z_AXIS; axis++)
00326         {
00327                 float roundedDiv = ceil (division[axis]);
00328                 roundedDiv = (roundedDiv < 1.0f ? 1.0f : roundedDiv);
00329                 
00330                 if (division[axis] - roundedDiv != 0.f)
00331                 {
00332                         lineLen[axis] = stepLength * roundedDiv;
00333                         division[axis] = roundedDiv;
00334                 }
00335         }
00336 
00337         // calculate the start and end point of the first vertical line
00338         SbVec3f firstPos = currentCenter;
00339         SbVec3f secondPos = firstPos + dir[Z_AXIS] * lineLen[Z_AXIS];
00340         
00341         SbVec3f step[2] = {dir[X_AXIS] * stepLength, dir[Z_AXIS] * stepLength};
00342 
00343         // draw the vertical lines
00344         int pointCount = 0;
00345         for (unsigned i = 0; i <= division[X_AXIS]; i++)
00346         {
00347                 // set the line's start and end point
00348                 beginShape (action, SoShape::LINES, &lineDetail);
00349                         vertex.setPoint (firstPos);
00350                         pointDetail.setCoordinateIndex (pointCount++);
00351                         shapeVertex (&vertex);
00352                         
00353                         vertex.setPoint (secondPos);
00354                         pointDetail.setCoordinateIndex (pointCount++);
00355                         shapeVertex (&vertex);
00356                 endShape ();
00357                 lineDetail.incLineIndex();
00358                 
00359                 // changing the x coords
00360                 firstPos += step[X_AXIS];
00361                 secondPos += step[X_AXIS];
00362         }
00363         // vertical lines are one part
00364         lineDetail.incPartIndex();
00365         
00366         // reset the starting points
00367         firstPos = currentCenter;
00368         secondPos = firstPos + dir[X_AXIS] * lineLen[X_AXIS];
00369         
00370         // the same for horizontal lines
00371         for (unsigned i = 0; i <= division[Z_AXIS]; i++)
00372         {
00373                 beginShape (action, SoShape::LINES, &lineDetail);
00374                         vertex.setPoint (firstPos);
00375                         pointDetail.setCoordinateIndex (pointCount++);
00376                         shapeVertex (&vertex);
00377                         
00378                         vertex.setPoint (secondPos);
00379                         pointDetail.setCoordinateIndex (pointCount++);
00380                         shapeVertex (&vertex);
00381                 endShape ();
00382                 lineDetail.incLineIndex();
00383                 
00384                 // changing the z coords
00385                 firstPos += step[Z_AXIS];
00386                 secondPos += step[Z_AXIS];
00387         }
00388         // Restore old state.
00389         state->pop ();
00390 }

void IgSoGridPlaneMap::GLRender ( SoGLRenderAction *  renderAction  )  [protected, virtual]

Definition at line 117 of file IgSoGridPlaneMap.cc.

References c, color, dir, f, i, j, k, labelSpot, LL, LLCorner(), LR, LRCorner(), m_curCorner, m_gridPlane, normVec(), on, plane, refreshScale, rot, spacing, cmsRelvalreportInput::step, UL, ULCorner(), IgSoGridPlane::updateScale(), X_AXIS, xLen, xOrigin, Z_AXIS, zLen, and zOrigin.

00118 {
00119         if (!on.getValue () || !shouldGLRender (action) || action->handleTransparency (true))
00120                 return;
00121                 
00122         SbPlane currentPlane;
00123         SbVec3f currentCenter;
00124         SbVec3f currentNormal;
00125         SbLine normalLine;
00126 
00127         //plane.setValue (SbPlane (SbVec3f (0.0f, 1.0f, 0.0f), 0.f))
00128         currentPlane = plane.getValue ();
00129         currentNormal = currentPlane.getNormal ();
00130         normalLine.setValue (SbVec3f (0.,0.,0.), currentNormal);
00131         currentPlane.intersect (normalLine, currentCenter);
00132         
00133         if (!normVec.equals (currentNormal, 0))
00134         {
00135                 // calculate the plane normal's deviation from (0,1,0) vector
00136                 const SbRotation rot (normVec, currentNormal);
00137         
00138                 // rotate the corners accordingly
00139                 rot.multVec (LLCorner, m_curCorner[LL]);
00140                 rot.multVec (LRCorner, m_curCorner[LR]);
00141                 rot.multVec (ULCorner, m_curCorner[UL]);
00142         }
00143         
00144         // grid line direction
00145         SbVec3f dir[2];
00146         
00147         dir[X_AXIS] = m_curCorner[LR] - m_curCorner[LL];
00148         dir[Z_AXIS] = m_curCorner[UL] - m_curCorner[LL];
00149 
00150         dir[X_AXIS].normalize ();
00151         dir[Z_AXIS].normalize ();
00152         
00153         // move the center according to the users wishes
00154         currentCenter = currentCenter + dir[X_AXIS] * xOrigin.getValue () + dir[Z_AXIS] * zOrigin.getValue ();
00155 
00156         // length of the displayed lines
00157         float lineLen[2] = {xLen.getValue (), zLen.getValue ()};
00158         
00159         // length of one step (user value is in milimeters)
00160         float stepLength = spacing.getValue () / 1000.0f;
00161         float division[2] = {lineLen[X_AXIS] / stepLength, lineLen[Z_AXIS] / stepLength};
00162         
00163         // correct the length and number of lines to a integer multiplicative
00164         // of a square
00165         for (unsigned axis = X_AXIS; axis <= Z_AXIS; axis++)
00166         {
00167                 float roundedDiv = ceil (division[axis]);
00168                 roundedDiv = (roundedDiv < 1.0f ? 1.0f : roundedDiv);
00169                 
00170                 if (division[axis] - roundedDiv != 0.f)
00171                 {
00172                         lineLen[axis] = stepLength * roundedDiv;
00173                         division[axis] = roundedDiv;
00174                 }
00175         }
00176 
00177         // calculate the start and end point of the first vertical line
00178         SbVec3f firstPos = currentCenter;
00179         SbVec3f secondPos = firstPos + dir[Z_AXIS] * lineLen[Z_AXIS];
00180         
00181         // set the positions for the corner labels
00182         labelSpot[LL] = firstPos - dir[X_AXIS] * stepLength - dir[Z_AXIS] * stepLength;
00183         labelSpot[LR] = firstPos + dir[X_AXIS] * (lineLen[X_AXIS] + stepLength) - dir[Z_AXIS] * stepLength;
00184         labelSpot[UL] = secondPos - dir[X_AXIS] * stepLength + dir[Z_AXIS] * stepLength;
00185         
00186         SbVec3f step[2] = {dir[X_AXIS] * stepLength, dir[Z_AXIS] * stepLength};
00187         
00188         const SbColor c = color.getValue ();
00189         float mat[4] = {c[0], c[1], c[2]};
00190         glColor3fv (mat);
00191         unsigned lineNum = 0;
00192         //glNormal3f (currentNormal[0], currentNormal[1], currentNormal[2]);
00193         
00194         unsigned axis = X_AXIS;
00195         const unsigned lineInterval = 10;
00196         
00197         glBegin (GL_LINES);
00198                 // first draw the vertical lines then the horizontal
00199                 for (unsigned j = 0; j < 2; j++)
00200                 {
00201                         for (unsigned i = 0; i <= division[axis]; i++)
00202                         {
00203                                 // change color each interval
00204                                 if (lineNum == lineInterval)
00205                                 {
00206                                         for (unsigned k = 0; k < 3; k++)
00207                                         {
00208                                                 mat[k] = 0.9f - mat[k];
00209                                         }
00210                                         glColor3fv (mat);
00211                                 }
00212                                 // set the line's start and end point
00213                                 glVertex3f (firstPos[0], firstPos[1], firstPos[2]);
00214                                 glVertex3f (secondPos[0], secondPos[1], secondPos[2]);
00215                                 // changing the x coords
00216                                 firstPos += step[axis];
00217                                 secondPos += step[axis];
00218                                 
00219                                 // change back colors
00220                                 if (lineNum == lineInterval)
00221                                 {
00222                                         for (unsigned k = 0; k < 3; k++)
00223                                         {
00224                                                 mat[k] = c[k];
00225                                         }
00226                                         glColor3fv (mat);
00227                                         lineNum = 0;
00228                                 }
00229                                 lineNum++;
00230                         }
00231                         
00232                         // reset the starting points
00233                         firstPos = currentCenter;
00234                         secondPos = firstPos + dir[X_AXIS] * lineLen[X_AXIS];
00235                         axis = Z_AXIS;
00236                         lineNum = 0;
00237                 }
00238         glEnd ();
00239         
00240         // if the refreshScale flag is set, it means that some value important to
00241         // the gridScale has changed so we need to call the update method
00242         if (refreshScale.getValue ())
00243         {
00244                 m_gridPlane->updateScale ();
00245                 refreshScale.setValue (false);
00246         }
00247         
00248 
00249 //      
00250 //      // Restore old state.
00251 //      ((SoGLLazyElement *) SoLazyElement::getInstance (state))
00252 //      ->reset (state, SoLazyElement::DIFFUSE_MASK);
00253 //      state->pop ();
00254 
00255 }

void IgSoGridPlaneMap::initClass ( void   )  [static]

Definition at line 84 of file IgSoGridPlaneMap.cc.

Referenced by initNodes(), and initShapes().

00085 {
00086         SO_NODE_INIT_CLASS (IgSoGridPlaneMap, SoShape, "Shape");
00087         SO_ENABLE (SoCallbackAction, SoLazyElement);
00088         SO_ENABLE (SoPickAction,     SoLazyElement);
00089         SO_ENABLE (SoGLRenderAction, SoGLLazyElement); 
00090 }

void IgSoGridPlaneMap::setCaller ( IgSoGridPlane caller  ) 

Definition at line 78 of file IgSoGridPlaneMap.cc.

References m_gridPlane.

Referenced by IgSoGridPlane::IgSoGridPlane().

00079 {
00080         m_gridPlane = caller;
00081 }

IgSoGridPlaneMap::SO_NODE_HEADER ( IgSoGridPlaneMap   )  [private]


Member Data Documentation

SoSFColor IgSoGridPlaneMap::color

Definition at line 37 of file IgSoGridPlaneMap.h.

Referenced by GLRender(), and IgSoGridPlaneMap().

SbVec3f IgSoGridPlaneMap::labelSpot[3]

Definition at line 38 of file IgSoGridPlaneMap.h.

Referenced by GLRender(), IgSoGridPlaneMap(), and IgSoGridPlane::updateScale().

SbVec3f IgSoGridPlaneMap::m_curCorner[3] [private]

Definition at line 56 of file IgSoGridPlaneMap.h.

Referenced by computeBBox(), generatePrimitives(), GLRender(), and IgSoGridPlaneMap().

IgSoGridPlane* IgSoGridPlaneMap::m_gridPlane [private]

Definition at line 57 of file IgSoGridPlaneMap.h.

Referenced by GLRender(), and setCaller().

SoSFBool IgSoGridPlaneMap::on

Definition at line 30 of file IgSoGridPlaneMap.h.

Referenced by GLRender(), and IgSoGridPlaneMap().

SoSFPlane IgSoGridPlaneMap::plane

Definition at line 31 of file IgSoGridPlaneMap.h.

Referenced by generatePrimitives(), GLRender(), and IgSoGridPlaneMap().

SoSFBool IgSoGridPlaneMap::refreshScale

Definition at line 39 of file IgSoGridPlaneMap.h.

Referenced by GLRender(), and IgSoGridPlaneMap().

SoSFFloat IgSoGridPlaneMap::spacing

Definition at line 36 of file IgSoGridPlaneMap.h.

Referenced by generatePrimitives(), GLRender(), and IgSoGridPlaneMap().

SoSFFloat IgSoGridPlaneMap::xLen

Definition at line 34 of file IgSoGridPlaneMap.h.

Referenced by generatePrimitives(), GLRender(), and IgSoGridPlaneMap().

SoSFFloat IgSoGridPlaneMap::xOrigin

Definition at line 32 of file IgSoGridPlaneMap.h.

Referenced by generatePrimitives(), GLRender(), and IgSoGridPlaneMap().

SoSFFloat IgSoGridPlaneMap::zLen

Definition at line 35 of file IgSoGridPlaneMap.h.

Referenced by generatePrimitives(), GLRender(), and IgSoGridPlaneMap().

SoSFFloat IgSoGridPlaneMap::zOrigin

Definition at line 33 of file IgSoGridPlaneMap.h.

Referenced by generatePrimitives(), GLRender(), and IgSoGridPlaneMap().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:25:43 2009 for CMSSW by  doxygen 1.5.4