00001
00003
00004
00005
00006
00007
00008
00010
00011 #include "VP1GuideLineSystems/VP1CylindricalGrid.h"
00012 #include "VP1GuideLineSystems/VP1Floor.h"
00013 #include "VP1Base/VP1QtInventorUtils.h"
00014 #include "CLHEP/Units/SystemOfUnits.h"
00015
00016 #include <Inventor/nodes/SoSeparator.h>
00017 #include <Inventor/nodes/SoVertexProperty.h>
00018 #include <Inventor/nodes/SoLineSet.h>
00019 #include <Inventor/nodes/SoTranslation.h>
00020 #include <Inventor/nodes/SoPackedColor.h>
00021 #include <Inventor/SbColor4f.h>
00022
00023
00024 class VP1CylindricalGrid::Imp {
00025 public:
00026 Imp(VP1CylindricalGrid *,
00027 SoSeparator * attachsep);
00028 VP1CylindricalGrid * theclass;
00029 SoSeparator * attachSep;
00030
00031 bool shown;
00032 SbColor4f colourAndTransp;
00033 double extent;
00034 double spacing;
00035
00036 SoSeparator * sep;
00037 SoPackedColor * circlecol;
00038
00039 void rebuild3DObjects();
00040 void updateColour();
00041 };
00042
00043
00044 VP1CylindricalGrid::VP1CylindricalGrid(SoSeparator * attachsep,
00045 IVP1System * sys,QObject * parent)
00046 : QObject(parent), VP1HelperClassBase(sys,"VP1CylindricalGrid"), d(new Imp(this,attachsep))
00047 {
00048 }
00049
00050
00051 VP1CylindricalGrid::~VP1CylindricalGrid()
00052 {
00053 setShown(false);
00054 if (d->sep)
00055 d->sep->unref();
00056 if (d->circlecol)
00057 d->circlecol->unref();
00058 d->attachSep->unref();
00059 delete d;
00060 }
00061
00062
00063 VP1CylindricalGrid::Imp::Imp(VP1CylindricalGrid *tc,SoSeparator * as)
00064 : theclass(tc), attachSep(as), shown(false),
00065 colourAndTransp(SbColor4f(1,1,1,1)),extent(10), spacing(1),
00066 sep(0), circlecol(0)
00067 {
00068 attachSep->ref();
00069 }
00070
00071
00072 void VP1CylindricalGrid::Imp::rebuild3DObjects()
00073 {
00074 theclass->messageVerbose("(Re)building 3D objects");
00075
00076 if (sep) {
00077 sep->removeAllChildren();
00078 } else {
00079 sep = new SoSeparator;
00080 sep->ref();
00081 }
00082
00083 const bool save = sep->enableNotify(false);
00084
00085 int nmax; double distmax;
00086 if (!VP1Floor::calcParsFromExtentAndSpacing( theclass, extent, spacing, 20, nmax, distmax )) {
00087 nmax = 10;
00088 distmax = 10*m;
00089 theclass->message("ERROR: Problems calculating nmax/distmax.");
00090 }
00091
00092 if (!circlecol) {
00093 circlecol = new SoPackedColor();
00094 circlecol->ref();
00095 }
00096
00097
00098 sep->addChild(circlecol);
00099
00100 for (int ir=1;ir<=nmax;++ir) {
00101 SoNode * circle = VP1QtInventorUtils::createCircle(ir*spacing);
00102 SoSeparator * s = new SoSeparator;
00103 SoTranslation *t1= new SoTranslation();
00104 t1->translation.setValue(0.0,0.0,-distmax-spacing);
00105 s->addChild(t1);
00106 for (int iz = -nmax; iz<=nmax; ++iz) {
00107 SoTranslation *t2= new SoTranslation();
00108 t2->translation.setValue(0.0,0.0,spacing);
00109 s->addChild(t2);
00110 s->addChild(circle);
00111 }
00112 sep->addChild(s);
00113 }
00114
00115
00116
00117 SoVertexProperty * grid_cylindrical_vertices = new SoVertexProperty();
00118
00119 int ivert(0);
00120 int nsublines(0);
00121 static const double invsqrttwo = 1.0/sqrt(2.0);
00122 for (int ir=1;ir<=nmax;++ir) {
00123 double r = ir*spacing;
00124 double r2 = r*invsqrttwo;
00125 grid_cylindrical_vertices->vertex.set1Value(ivert++,r,0,-distmax);
00126 grid_cylindrical_vertices->vertex.set1Value(ivert++,r,0,+distmax);
00127 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,r,-distmax);
00128 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,r,+distmax);
00129 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r,0,-distmax);
00130 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r,0,+distmax);
00131 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,-r,-distmax);
00132 grid_cylindrical_vertices->vertex.set1Value(ivert++,0,-r,+distmax);
00133 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,r2,-distmax);
00134 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,r2,+distmax);
00135 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,-r2,-distmax);
00136 grid_cylindrical_vertices->vertex.set1Value(ivert++,r2,-r2,+distmax);
00137 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,r2,-distmax);
00138 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,r2,+distmax);
00139 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,-r2,-distmax);
00140 grid_cylindrical_vertices->vertex.set1Value(ivert++,-r2,-r2,+distmax);
00141 nsublines+=8;
00142 }
00143
00144 grid_cylindrical_vertices->materialBinding=SoMaterialBinding::OVERALL;
00145 grid_cylindrical_vertices->normalBinding=SoNormalBinding::OVERALL;
00146 SoLineSet * line = new SoLineSet();
00147 line->numVertices.enableNotify(FALSE);
00148 line->numVertices.setNum(nsublines);
00149 for (int i=0;i<nsublines;++i)
00150 line->numVertices.set1Value(i,2);
00151 line->vertexProperty = grid_cylindrical_vertices;
00152 line->numVertices.enableNotify(TRUE);
00153 line->numVertices.touch();
00154
00155 sep->addChild(line);
00156 updateColour();
00157
00158 if (save) {
00159 sep->enableNotify(true);
00160 sep->touch();
00161 }
00162
00163 }
00164
00165
00166 void VP1CylindricalGrid::Imp::updateColour()
00167 {
00168 theclass->messageVerbose("Updating packed colour");
00169 if (circlecol)
00170 circlecol->orderedRGBA = colourAndTransp.getPackedValue();
00171 if (!sep||sep->getNumChildren()<1)
00172 return;
00173 SoNode * n = sep->getChild(0);
00174 if (!n||n->getTypeId()!=SoLineSet::getClassTypeId())
00175 return;
00176 SoLineSet * line = static_cast<SoLineSet*>(n);
00177 SoVertexProperty * vertices = static_cast<SoVertexProperty *>(line->vertexProperty.getValue());
00178 if (vertices)
00179 vertices->orderedRGBA = colourAndTransp.getPackedValue();
00180 }
00181
00182
00183 void VP1CylindricalGrid::setShown(bool b)
00184 {
00185 messageVerbose("Signal received: setShown("+str(b)+")");
00186 if (d->shown==b)
00187 return;
00188 d->shown=b;
00189 if (d->shown) {
00190 d->rebuild3DObjects();
00191 if (d->attachSep->findChild(d->sep)<0)
00192 d->attachSep->addChild(d->sep);
00193 } else {
00194 if (d->sep&&d->attachSep->findChild(d->sep)>=0)
00195 d->attachSep->removeChild(d->sep);
00196 }
00197 }
00198
00199
00200 void VP1CylindricalGrid::setColourAndTransp(const SbColor4f&ct)
00201 {
00202 messageVerbose("Signal received in setColourAndTransp slot.");
00203 if (d->colourAndTransp==ct)
00204 return;
00205 d->colourAndTransp=ct;
00206 if (d->shown)
00207 d->updateColour();
00208 }
00209
00210
00211 void VP1CylindricalGrid::setExtent(const double& e)
00212 {
00213 messageVerbose("Signal received: setExtent("+str(e)+")");
00214 if (d->extent==e)
00215 return;
00216 d->extent=e;
00217 if (d->shown)
00218 d->rebuild3DObjects();
00219 }
00220
00221
00222 void VP1CylindricalGrid::setSpacing(const double&s)
00223 {
00224 messageVerbose("Signal received: setSpacing("+str(s)+")");
00225 if (d->spacing==s)
00226 return;
00227 d->spacing=s;
00228 if (d->shown)
00229 d->rebuild3DObjects();
00230 }