CMS 3D CMS Logo

IgSoCircleArc.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Inventor/interface/IgSoCircleArc.h"
00004 #include "Inventor/nodes/SoLineSet.h"
00005 #include "Inventor/nodes/SoVertexProperty.h"
00006 
00007 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00008 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00009 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00010 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00011 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00012 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00013 
00014 SO_KIT_SOURCE (IgSoCircleArc);
00015 
00016 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00017 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00018 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00019 
00020 void
00021 IgSoCircleArc::initClass (void)
00022 { SO_KIT_INIT_CLASS (IgSoCircleArc, IgSoShapeKit, "IgSoShapeKit"); }
00023 
00024 IgSoCircleArc::IgSoCircleArc (void)
00025 {
00026     SO_KIT_CONSTRUCTOR (IgSoCircleArc);
00027     SO_KIT_ADD_FIELD (center, (0.f,0.f));
00028     SO_KIT_ADD_FIELD (radius, (1.f));
00029     SO_KIT_ADD_FIELD (sweepAngle, (360.f));
00030     SO_KIT_ADD_CATALOG_ENTRY (line,  SoLineSet, FALSE, separator,\x0, TRUE);
00031     SO_KIT_INIT_INSTANCE ();
00032     setUpConnections (true, true);
00033 }
00034 
00035 void
00036 IgSoCircleArc::refresh (void)
00037 {
00038     static const int    CIRCLE_SEGMENTS = 60;
00039     SoVertexProperty    *vtx = new SoVertexProperty;
00040     SoLineSet           *line = new SoLineSet;
00041     int                 segments = int(CIRCLE_SEGMENTS * sweepAngle.getValue () / 360 + .5);
00042 
00043     if (segments < 3)
00044         segments = 3;
00045 
00046     double              segAngle = sweepAngle.getValue () * M_PI / 180 / segments;
00047     double              r = radius.getValue ();
00048     float               cx, cy;
00049 
00050     center.getValue ().getValue (cx, cy);
00051     for (int i = 0; i < segments; i++)
00052         vtx->vertex.set1Value (i, SbVec3f (r * cos (i * segAngle) + cx,
00053                                            r * sin (i * segAngle) + cy,
00054                                            0));
00055 
00056     vtx->normal = SbVec3f (0, 0, 1);
00057     vtx->normalBinding = SoVertexProperty::OVERALL;
00058     vtx->materialBinding = SoVertexProperty::OVERALL;
00059     line->numVertices = segments;
00060     line->vertexProperty = vtx;
00061 
00062     setPart ("line", line);
00063 }

Generated on Tue Jun 9 17:38:45 2009 for CMSSW by  doxygen 1.5.4