//not optimal for now! (same normals may be drawn few times) static GLuint createNormalList(){ GLuint list = glGenLists(1); glNewList(list, GL_COMPILE); glBegin(GL_LINES); BOOST_FOREACH(const MeshPtr nextMesh, gModel->mMeshes){ const Mesh::VertexCont& vertices = nextMesh->mVertices; BOOST_FOREACH(const Mesh::index_t nextIndex, nextMesh->mIndices){ const Point& vert = vertices[nextIndex].mCoord; Vector3D norm = vertices[nextIndex].mNormal.getUnit(); glVertex3f(vert.x, vert.y, vert.z); glVertex3f(vert.x + norm.x(), vert.y + norm.y(), vert.z + norm.z()); } } glEnd(); glEndList(); return list; }
//----------------------------------------------------------------------------- void PrParametrizeInt::findFixedPntsFromXYZ(vector<int>& fixedPnts) //----------------------------------------------------------------------------- // This is a simple routine which finds the indices // fixedPnts[0..3] of the four vertices of the graph // whose (x,y,z) points are the furthest in the directions // (-1/-1/1), (1/1/1), (-1/1/-1), and (1/-1/-1) in that order. // The indices can be used as fixed points for // parametrising in 3D. { int k; fixedPnts.resize(4); Vector3D dir[4]; dir[0] = Vector3D(-1,-1,1); dir[1] = Vector3D(1,1,1); dir[2] = Vector3D(-1,1,-1); dir[3] = Vector3D(1,-1,-1); Vector3D p0 = g_->get3dNode(0); double dp[4]; for(k=0; k<4; k++) { fixedPnts[k] = 0; dp[k] = p0 * dir[k]; } for(int i=1; i< g_->getNumNodes(); i++) { Vector3D p = g_->get3dNode(i); for(k=0; k<4; k++) { double newdp = p * dir[k]; if (newdp > dp[k]) { fixedPnts[k] = i; dp[k] = newdp; } } } cout << "the following 4 points have been fixed: " << endl; for(k=0; k<4; k++) { Vector3D p = g_->get3dNode(fixedPnts[k]); cout << fixedPnts[k] << " : " << p.x() << "," << p.y() << "," << p.z() << endl; } }
// implement a default function for surface area // based on the method of G4 Precision VPlacedVolume::SurfaceArea() { // std::cout << "WARNING : Sampling SurfaceArea called \n"; int nStat = 100000; double ell = -1.; Vector3D<Precision> p; Vector3D<Precision> minCorner; Vector3D<Precision> maxCorner; Vector3D<Precision> delta; // min max extents of pSolid along X,Y,Z this->Extent(minCorner,maxCorner); // limits delta = maxCorner - minCorner; if(ell<=0.) // Automatic definition of skin thickness { Precision minval = delta.x(); if(delta.y() < delta.x()) { minval= delta.y(); } if(delta.z() < minval) { minval= delta.z(); } ell=.01*minval; } Precision dd=2*ell; minCorner.x()-=ell; minCorner.y()-=ell; minCorner.z()-=ell; delta.x()+=dd; delta.y()+=dd; delta.z()+=dd; int inside=0; for(int i = 0; i < nStat; ++i ) { p = minCorner + Vector3D<Precision>( delta.x()*RNG::Instance(). uniform(), delta.y()*RNG::Instance(). uniform(), delta.z()*RNG::Instance(). uniform() ); if( this->UnplacedContains(p) ) { if( this->SafetyToOut(p)<ell) { inside++; } } else{ if( this->SafetyToIn(p)<ell) { inside++; } } } // @@ The conformal correction can be upgraded return delta.x()*delta.y()*delta.z()*inside/dd/nStat; }
CameraTransformGL::CameraTransformGL(const Na3DWidget& widget3d) { // adapted from v3dr_glwidget::paintGL() glPushAttrib(GL_TRANSFORM_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); Rotation3D rot = widget3d.getCameraRotationInGround(); // absolute translation { Vector3D f = widget3d.getCameraFocusInMicrometers(); Vector3D df = widget3d.getDefaultFocusInMicrometers(); f -= df; f *= widget3d.glUnitsPerImageVoxel(); f = rot * f; glTranslated(-f.x(), -f.y(), -f.z()); // cerr << "focus1: " << -f.x() << ", " << -f.y() << ", " << -f.z() << endl; } // last absolute rotation pose GLdouble mRot[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; rot.setGLMatrix(mRot); glMultMatrixd(mRot); // Y axis down const int flip_X= +1, flip_Y= -1, flip_Z= -1; glScaled(flip_X,flip_Y,flip_Z); // make y-axis downward conformed with image coordinate // Scale back from "volume" coordinates to orthogonal micrometers double scale = widget3d.glUnitsPerImageVoxel(); glScaled(scale, scale, scale); }
void Handle_2048::create_back_tile(Vector3D v, float size, Color c) { m_vertices.push_back(v.x() + size / 2.f); m_vertices.push_back(v.y() + size / 2.f); m_vertices.push_back(v.x() + size / 2.f); m_vertices.push_back(v.y() - size / 2.f); m_vertices.push_back(v.x() - size / 2.f); m_vertices.push_back(v.y() - size / 2.f); m_vertices.push_back(v.x() + size / 2.f); m_vertices.push_back(v.y() + size / 2.f); m_vertices.push_back(v.x() - size / 2.f); m_vertices.push_back(v.y() - size / 2.f); m_vertices.push_back(v.x() - size / 2.f); m_vertices.push_back(v.y() + size / 2.f); for (int x = 0; x < 6; ++x) { m_colors.push_back(c.red()); m_colors.push_back(c.green()); m_colors.push_back(c.blue()); } }
int XRayWithGeant4( G4VPhysicalVolume * world /* the detector to scan */, int axis, Vector3D<Precision> origin, Vector3D<Precision> bboxscreen, Vector3D<Precision> dir, double axis1_start, double axis1_end, double axis2_start, double axis2_end, int data_size_x, int data_size_y, double pixel_axis, int * image) { // ATTENTION: THERE IS A (OR MIGHT BE) UNIT MISSMATCH HERE BETWEEN ROOT AND GEANT // ROOT = cm and GEANT4 = mm; basically a factor of 10 in all dimensions // const double UNITCONV=10.; G4Navigator * nav = new G4Navigator(); // now start XRay procedure nav->SetWorldVolume( world ); G4ThreeVector d(dir.x(),dir.y(),dir.z()); G4ThreeVector p(0,0,0); // false == locate from top G4VPhysicalVolume const * vol = nav->LocateGlobalPointAndSetup( p, &d, false ); double distancetravelled=0.; int crossedvolumecount=0; int counter=0; while( vol!=NULL ) { crossedvolumecount++; double safety; // do one step ( this will internally adjust the current point and so on ) // also calculates safety double step = nav->ComputeStep( p, d, vecgeom::kInfinity, safety ); // std::cerr << " STEP " << step << " ENTERING " << nav->EnteredDaughterVolume() << "\n"; // calculate next point ( do transportation ) and volume ( should go across boundary ) G4ThreeVector next = p + (step) * d; distancetravelled+=step; nav->SetGeometricallyLimitedStep(); vol = nav->LocateGlobalPointAndSetup( next, &d, true); if(VERBOSE) { if( vol != NULL ) std::cout << " *G4 " << counter++ << " * point" << p/10. << " goes to " << " VolumeName: " << vol->GetName(); else std::cout << " NULL: "; std::cout << " step[" << step/10. << "]"<< std::endl; } p=next; } // end while if(VERBOSE) { std::cout << " PassedVolume:" << "<"<< crossedvolumecount << " "; std::cout << " Distance: " << distancetravelled/10.<< std::endl; } return 0; }
void XRayWithROOT(int axis, Vector3D<Precision> origin, Vector3D<Precision> bbox, Vector3D<Precision> dir, double axis1_start, double axis1_end, double axis2_start, double axis2_end, int data_size_x, int data_size_y, double pixel_axis, int * image) { int counter=0; // set start point of geantino Vector3D<Precision> p(0.,0.,0); TGeoNavigator * nav = gGeoManager->GetCurrentNavigator(); nav->SetCurrentPoint( p.x(), p.y(), p.z() ); nav->SetCurrentDirection( dir.x(), dir.y(), dir.z() ); double distancetravelled=0.; int crossedvolumecount=0; if(VERBOSE) { std::cout << " StartPoint(" << p[0] << ", " << p[1] << ", " << p[2] << ")"; std::cout << " Direction <" << dir[0] << ", " << dir[1] << ", " << dir[2] << ">"<< std::endl; } // propagate until we leave detector TGeoNode const * node = nav->FindNode(); std::cout << "INITIAL MAT :" << node->GetVolume()->GetMaterial()->GetName() << "\n"; // if( node ) std::cout << node->GetVolume()->GetName() << "\t"; while( node !=NULL ) { node = nav->FindNextBoundaryAndStep( vecgeom::kInfinity ); distancetravelled+=nav->GetStep(); counter++; if(VERBOSE) { if( node != NULL ) std::cout << " *R " << counter << " * " << " point(" << p[0] << ", " << p[1] << ", " << p[2] << ") goes to " << " VolumeName: "<< node->GetVolume()->GetName() << " (MAT: " << node->GetVolume()->GetMaterial()->GetName() << ") :"; else std::cout << " NULL: "; std::cout << " step[" << nav->GetStep()<< "]"<< std::endl; double const * pROOT = nav->GetCurrentPoint(); p = Vector3D<Precision>(pROOT[0],pROOT[1],pROOT[2]); } // Increase passed_volume // TODO: correct counting of travel in "world" bounding box crossedvolumecount++; } // end while // std::cout << crossedvolumecount << "\n"; if(VERBOSE) { std::cout << " PassedVolume:" << "<"<< crossedvolumecount << " "; std::cout << " total distance travelled: " << distancetravelled<< std::endl; } } // end XRayWithROOT
//----------------------------------------------------------------------------- bool PrParametrizeInt::parametrize3d(vector<int>& fixedPnts, vector<double>& uvw) //----------------------------------------------------------------------------- // Parametrize the nodes of the 3D grapg g_ except those // with indices in "fixedPnts". The parameterization is done // in 3D and the result is returned as vector "uvw" { // To find the internal (u,v,w) nodes, we solve a linear system // thrice: once for u, v and w. The matrix A is the same // in both cases. Only the right-hand side changes. // There is one equation for each interior node, // so we solve Au=b1, Av=b2 and Av=b3 where A is ni * ni and ni is the // number of interior nodes. int n = g_->getNumNodes(); int ni = n - (int)fixedPnts.size(); if(ni == 0) return true; // // setup the "full" matrix A (i.e. without boundary vertices) // // remark: this will only work for closed meshes!!! // // find number of non-zeros in the matrix A int i; int numNonZeros = 0; for(i=0; i<n; i++) { g_->getNeighbours(i, neighbours_); numNonZeros += ((int)neighbours_.size() + 1); } PrMatSparse A (n, n, numNonZeros); int offset = 0; for(i=0; i<n; i++) { A.irow(i) = offset; A(offset) = 1.0; A.jcol(offset) = i; offset++; g_->getNeighbours(i,neighbours_); int degree = (int)neighbours_.size(); makeWeights(i); // Ignoring return value. for(int j=0; j< degree; j++) { int k = neighbours_[j]; A(offset) = weights_[j]; A.jcol(offset) = k; offset++; } } cerr << "Matrix A upset!" << endl; // A.print(cerr); // // setup the matrix B // // setup the linear system // find number of non-zeros in the matrix B numNonZeros = 0; for(i=0; i<n; i++) { if(!isFixed(i,fixedPnts)) numNonZeros += (getNumInt2Nghrs(i, fixedPnts) + 1); } PrMatSparse B (ni,ni,numNonZeros); PrVec b1(ni, 0.0); PrVec b2(ni, 0.0); PrVec b3(ni, 0.0); PrVec uvec(ni); PrVec vvec(ni); PrVec wvec(ni); // Make a permutation array for mapping global i to interior i. vector<int> permute(n); int j = 0; for(i=0; i<n; i++) { if(!isFixed(i,fixedPnts)) { permute[i] = j; j++; } } // Set start vector to the original xyz-coordinates. for(i = 0; i < ni; i++) { Vector3D p=g_->get3dNode(i); uvec(i) = p.x(); vvec(i) = p.y(); wvec(i) = p.z(); } // Initialize right hand side to zero // @afr: Already done in construction of b1, b2, b3. offset = 0; for(i=0; i<n; i++) { if(!isFixed(i,fixedPnts)) { g_->getNeighbours(i,neighbours_); // set the diagonal entry B.irow(permute[i]) = offset; B(offset) = 1.0; for (size_t k=0; k<neighbours_.size(); k++) { int kk = neighbours_[k]; // A^t * A B(offset) += A(kk,i) * A(kk,i); // A^2 // B(offset) += A(kk,i) * A(i, kk); } B.jcol(offset) = permute[i]; offset++; // handle neighbours in 1-neighbourhood int degree = (int)neighbours_.size(); for(j=0; j<degree; j++) { int jj = neighbours_[j]; // compute the b_ij double b_ij; // A^t * A b_ij = - A(i, jj) - A(jj, i); // A^2 // b_ij = - 2*A(i, jj); vector<int> commonNeighbours; g_->getCommonNeighbours(i, jj, commonNeighbours); for (size_t k=0; k<commonNeighbours.size(); k++) { int kk = commonNeighbours[k]; // A^t * A b_ij += A(kk, i) * A(kk,jj); // A^2 // b_ij += A(i, kk) * A(kk,jj); } if(isFixed(jj,fixedPnts)) { Vector3D p=g_->get3dNode(jj); b1(permute[i]) -= b_ij * p.x(); b2(permute[i]) -= b_ij * p.y(); b3(permute[i]) -= b_ij * p.z(); } else { B(offset) = b_ij; B.jcol(offset) = permute[jj]; offset++; } } // handle neighbours in 2-neighbourhood g_->get2Neighbours(i,neighbours_); degree = (int)neighbours_.size(); for(j=0; j<degree; j++) { int jj = neighbours_[j]; // compute the b_ij double b_ij = 0.0; vector<int> commonNeighbours; g_->getCommonNeighbours(i, jj, commonNeighbours); for (size_t k=0; k<commonNeighbours.size(); k++) { int kk = commonNeighbours[k]; // A^t * A b_ij += A(kk, i) * A(kk,jj); // A^2 // b_ij += A(i, kk) * A(kk,jj); } if(isFixed(jj,fixedPnts)) { Vector3D p=g_->get3dNode(jj); b1(permute[i]) -= b_ij * p.x(); b2(permute[i]) -= b_ij * p.y(); b3(permute[i]) -= b_ij * p.z(); } else { B(offset) = b_ij; B.jcol(offset) = permute[jj]; offset++; } } } } cerr << "Matrix B upset!" << endl; // B.print(cerr); // solve the system thrice PrBiCGStab solver; solver.setMaxIterations(ni); solver.setTolerance(tolerance_); solver.solve(B,uvec,b1); solver.solve(B,vvec,b2); solver.solve(B,wvec,b3); // Copy the results to the u and v arrays. uvw.resize(3*n); for(i=0; i<n; i++) { if(!isFixed(i,fixedPnts)) { uvw[3*i+0] = uvec(permute[i]); uvw[3*i+1] = vvec(permute[i]); uvw[3*i+2] = wvec(permute[i]); } else { Vector3D p=g_->get3dNode(i); uvw[3*i+0] = p.x(); uvw[3*i+1] = p.y(); uvw[3*i+2] = p.z(); } } cerr << "System solved!" << endl; // project parameter values to a unit sphere around the barycentre of the // fixed points Vector3D barycentre = 0.25 * (g_->get3dNode(fixedPnts[0]) + g_->get3dNode(fixedPnts[1]) + g_->get3dNode(fixedPnts[2]) + g_->get3dNode(fixedPnts[3]) ); for(i=0; i<n; i++) { Vector3D vec = Vector3D(uvw[3*i+0], uvw[3*i+1], uvw[3*i+2]) - barycentre; vec.normalize(); uvw[3*i+0] = vec.x(); uvw[3*i+1] = vec.y(); uvw[3*i+2] = vec.z(); } return true; }
void cube(Vector3D centre, float rayon) { glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex3f(centre.x() - rayon, centre.y() - rayon, centre.z() - rayon); glVertex3f(centre.x() - rayon, centre.y() + rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() + rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() - rayon, centre.z() - rayon); glEnd(); glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex3f(centre.x() - rayon, centre.y() - rayon, centre.z() + rayon); glVertex3f(centre.x() - rayon, centre.y() + rayon, centre.z() + rayon); glVertex3f(centre.x() + rayon, centre.y() + rayon, centre.z() + rayon); glVertex3f(centre.x() + rayon, centre.y() - rayon, centre.z() + rayon); glEnd(); glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex3f(centre.x() - rayon, centre.y() - rayon, centre.z() - rayon); glVertex3f(centre.x() - rayon, centre.y() + rayon, centre.z() - rayon); glVertex3f(centre.x() - rayon, centre.y() + rayon, centre.z() + rayon); glVertex3f(centre.x() - rayon, centre.y() - rayon, centre.z() + rayon); glEnd(); glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex3f(centre.x() + rayon, centre.y() - rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() + rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() + rayon, centre.z() + rayon); glVertex3f(centre.x() + rayon, centre.y() - rayon, centre.z() + rayon); glEnd(); glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex3f(centre.x() - rayon, centre.y() - rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() - rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() - rayon, centre.z() + rayon); glVertex3f(centre.x() - rayon, centre.y() - rayon, centre.z() + rayon); glEnd(); glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex3f(centre.x() - rayon, centre.y() + rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() + rayon, centre.z() - rayon); glVertex3f(centre.x() + rayon, centre.y() + rayon, centre.z() + rayon); glVertex3f(centre.x() - rayon, centre.y() + rayon, centre.z() + rayon); glEnd(); }
int XRayWithGeant4( G4VPhysicalVolume * world /* the detector to scan */, int axis, Vector3D<Precision> origin, Vector3D<Precision> bboxscreen, Vector3D<Precision> dir, double axis1_start, double axis1_end, double axis2_start, double axis2_end, int data_size_x, int data_size_y, double pixel_axis, int * image) { // ATTENTION: THERE IS A (OR MIGHT BE) UNIT MISSMATCH HERE BETWEEN ROOT AND GEANT // ROOT = cm and GEANT4 = mm; basically a factor of 10 in all dimensions const double UNITCONV=10.; G4Navigator * nav = new G4Navigator(); // now start XRay procedure nav->SetWorldVolume( world ); double pixel_width_1 = (axis1_end-axis1_start)/data_size_x; double pixel_width_2 = (axis2_end-axis2_start)/data_size_y; G4ThreeVector d(dir.x(),dir.y(),dir.z()); for( int pixel_count_2 = 0; pixel_count_2 < data_size_y; ++pixel_count_2 ){ for( int pixel_count_1 = 0; pixel_count_1 < data_size_x; ++pixel_count_1 ) { double axis1_count = axis1_start + pixel_count_1 * pixel_width_1 + 1E-6; double axis2_count = axis2_start + pixel_count_2 * pixel_width_2 + 1E-6; // set start point of XRay G4ThreeVector p; if( axis== 1 ) p = UNITCONV*G4ThreeVector( origin[0]-bboxscreen[0], axis1_count, axis2_count ); else if( axis== 2) p = UNITCONV*G4ThreeVector( axis1_count, origin[1]-bboxscreen[1], axis2_count ); else if( axis== 3) p = UNITCONV*G4ThreeVector( axis1_count, axis2_count, origin[2]-bboxscreen[2] ); // false == locate from top G4VPhysicalVolume const * vol = nav->LocateGlobalPointAndSetup( p, &d, false ); // std::cerr << p << " in vol " << vol->GetName() << " N D " // << vol->GetLogicalVolume()->GetNoDaughters() << "\n"; // double distancetravelled=0.; int crossedvolumecount=0; while( vol!=NULL ) { double safety; // do one step ( this will internally adjust the current point and so on ) // also calculates safety double step = nav->ComputeStep( p, d, vecgeom::kInfinity, safety ); if(step>0.) crossedvolumecount++; // std::cerr << " STEP " << step << " ENTERING " << nav->EnteredDaughterVolume() << "\n"; // calculate next point ( do transportation ) and volume ( should go across boundary ) G4ThreeVector next = p + (step + 1E-6) * d; nav->SetGeometricallyLimitedStep(); vol = nav->LocateGlobalPointAndSetup( next, &d, true); p=next; } // /////////////////////////////////// // // Store the number of passed volume at 'volume_result' *(image+pixel_count_2*data_size_x+pixel_count_1) = crossedvolumecount; } // end inner loop } // end outer loop return 0; }
size_t Triangulation::hash ( const Vector3D & point) { std::hash<double> hashD; size_t n = hashD(point.x()*PRIME*PRIME + point.y()*PRIME + point.z()); return n; }
AnimationPtr loadAnim(std::istream& inSource, Manager& inManager){ if(!inSource.good()) fatalError("stream is in bad condition"); //check header checkAndEatHeader(inSource); //get numFrames size_t numFrames = getNamedValue(inSource, "numFrames"); //get numJoints size_t numJoints = getNamedValue(inSource, "numJoints"); //get framerate size_t frameRate = getNamedValue(inSource, "frameRate"); //get numAnimatedComponents size_t numAnimatedComponents = getNamedValue(inSource, "numAnimatedComponents"); std::string token; //get hierarchy data findNextToken(inSource); std::getline(inSource, token, ' '); if(token != "hierarchy") fatalError("'hierarchy' wanted."); //eat { eatChar(inSource, '{'); std::vector<Bone> joints; std::vector<int> jointFlags; std::vector<int> jointStartIndices; joints.reserve(numJoints); jointFlags.reserve(numJoints); jointStartIndices.reserve(numJoints); for(size_t i = 0; i < numJoints; ++i){ //read next joint // '"' must be here eatChar(inSource, '"'); hydra::data::Bone nextBone; //read name std::getline(inSource, nextBone.mName, '"'); findNextToken(inSource); //read parent's id inSource >> nextBone.mParent; joints.push_back(nextBone); findNextToken(inSource); //read flags int flags = 0; inSource >> flags; jointFlags.push_back(flags); int startIndex = -1; inSource >> startIndex; jointStartIndices.push_back(startIndex); } //eat '}' eatChar(inSource, '}'); //ignore bounds for now //TODO: save them somewhere (may be) //bounds data findNextToken(inSource); std::getline(inSource, token, ' '); if(token != "bounds") fatalError("'bounds' wanted."); eatChar(inSource, '{'); //bounding boxes for each frame //for(size_t i = 0; i < numFrames; ++i){ // //} //just eat till '}' inSource.ignore(1000*numFrames, '}'); //baseframe goes now findNextToken(inSource); std::getline(inSource, token, ' '); if(token != "baseframe") fatalError("'baseframe' wanted"); eatChar(inSource, '{'); for(size_t i = 0; i < numJoints; ++i){ eatChar(inSource, '('); float x, y, z; //read position inSource >> x >> y >> z; joints[i].mPos = Vector3D(x, y, z); eatChar(inSource, ')'); eatChar(inSource, '('); //read orientation inSource >> x >> y >> z; joints[i].mOrient = buildUnitQuat(x, y, z); eatChar(inSource, ')'); } eatChar(inSource, '}'); std::vector< std::vector<float> > frameData; frameData.resize(numFrames); //read frame data for(size_t i = 0; i < numFrames; ++i){ findNextToken(inSource); std::getline(inSource, token, ' '); if(token != "frame") fatalError("'frame' wanted"); int frameIndex = -1; findNextToken(inSource); inSource >> frameIndex; eatChar(inSource, '{'); frameData[frameIndex].resize(numAnimatedComponents); for(size_t j = 0; j < numAnimatedComponents; ++j){ findNextToken(inSource); inSource >> frameData[frameIndex][j]; } eatChar(inSource, '}'); } //all the data read //now we should build frames AnimationPtr anim(new Animation()); anim->mFrames.resize(numFrames); //for each frame for(size_t i = 0; i < numFrames; ++i){ anim->mFrames[i].mBones.resize(numJoints); //for each joint for(size_t j = 0; j < numJoints; ++j){ //copy bone hydra::data::Bone currentBone = joints[j]; int startIndex = jointStartIndices[j]; if (jointFlags[j] & 1){ currentBone.mPos.setX(frameData[i][startIndex]); ++startIndex; } if(jointFlags[j] & 2){ currentBone.mPos.setY(frameData[i][startIndex]); ++startIndex; } if(jointFlags[j] & 4){ currentBone.mPos.setZ(frameData[i][startIndex]); ++startIndex; } Vector3D newQuat; if(jointFlags[j] & 8){ newQuat.setX(frameData[i][startIndex]); ++startIndex; } if(jointFlags[j] & 16){ newQuat.setY(frameData[i][startIndex]); ++startIndex; } if(jointFlags[j] & 32){ newQuat.setZ(frameData[i][startIndex]); ++startIndex; } currentBone.mOrient = buildUnitQuat(newQuat.x(), newQuat.y(), newQuat.z()); //assuming parent bone is alredy handled int parentIndex = currentBone.mParent; //if has parent if(parentIndex >= 0){ const hydra::data::Bone& parentBone = anim->mFrames[i].mBones[parentIndex]; //rotate position parentBone.mOrient.rotate(currentBone.mPos); currentBone.mPos += parentBone.mPos; currentBone.mOrient = parentBone.mOrient * currentBone.mOrient; currentBone.mOrient.normalize(); } anim->mFrames[i].mBones[j] = currentBone; } } anim->mFramerate = static_cast<float>(frameRate); return anim; }
void XRayWithVecGeom(int axis, Vector3D<Precision> origin, Vector3D<Precision> bbox, Vector3D<Precision> dir, double axis1_start, double axis1_end, double axis2_start, double axis2_end, int data_size_x, int data_size_y, double pixel_axis, int * image) { if(VERBOSE){ std::cout << "from [" << axis1_start << ";" << axis2_start << "] to [" << axis1_end << ";" << axis2_end << "]\n"; std::cout << "Xpixels " << data_size_x << " YPixels " << data_size_y << "\n"; std::cout << pixel_axis << "\n"; } double pixel_width_1 = (axis1_end-axis1_start)/data_size_x; double pixel_width_2 = (axis2_end-axis2_start)/data_size_y; if(VERBOSE){ std::cout << pixel_width_1 << "\n"; std::cout << pixel_width_2 << "\n"; } NavigationState * newnavstate = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() ); NavigationState * curnavstate = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() ); for( int pixel_count_2 = 0; pixel_count_2 < data_size_y; ++pixel_count_2 ){ for( int pixel_count_1 = 0; pixel_count_1 < data_size_x; ++pixel_count_1 ) { double axis1_count = axis1_start + pixel_count_1 * pixel_width_1 + 1E-6; double axis2_count = axis2_start + pixel_count_2 * pixel_width_2 + 1E-6; if(VERBOSE) { std::cout << "\n OutputPoint("<< axis1_count<< ", "<< axis2_count<< ")\n"; } // std::cout << pixel_count_1 << " " << pixel_count_2 << "\n"; // set start point of XRay Vector3D<Precision> p; if( axis== 1 ) p.Set( origin[0]-bbox[0], axis1_count, axis2_count); else if( axis== 2) p.Set( axis1_count, origin[1]-bbox[1], axis2_count); else if( axis== 3) p.Set( axis1_count, axis2_count, origin[2]-bbox[2]); SimpleNavigator nav; curnavstate->Clear(); nav.LocatePoint( GeoManager::Instance().GetWorld(), p, *curnavstate, true ); #ifdef VECGEOM_DISTANCE_DEBUG gGeoManager->GetCurrentNavigator()->FindNode( p.x(), p.y(), p.z() ); #endif // curnavstate->Print(); double distancetravelled=0.; int crossedvolumecount=0; if(VERBOSE) { std::cout << " StartPoint(" << p[0] << ", " << p[1] << ", " << p[2] << ")"; std::cout << " Direction <" << dir[0] << ", " << dir[1] << ", " << dir[2] << ">"<< std::endl; } while( ! curnavstate->IsOutside() ) { double step = 0; newnavstate->Clear(); Nav_t navigator; navigator.FindNextBoundaryAndStep( p, dir, *curnavstate, *newnavstate, vecgeom::kInfinity, step); //std::cout << "step " << step << "\n"; distancetravelled+=step; // // std::cout << "GOING FROM " // << curnavstate->Top()->GetLabel() << "("; // curnavstate->Top()->PrintType(); // std::cout << ") to "; // // if( newnavstate->Top() ){ // std::cout << newnavstate->Top()->GetLabel() << "("; // newnavstate->Top()->PrintType(); // std::cout << ")"; // } // else // std::cout << "outside "; // // if ( curnavstate->Top() == newnavstate->Top() ) { // std::cout << " CROSSING PROBLEM \n"; // curnavstate->Print(); // newnavstate->Print(); // } // // std::cout << "# step " << step << " crossed "<< crossedvolumecount << "\n"; // here we have to propagate particle ourselves and adjust navigation state p = p + dir*(step + 1E-6); // std::cout << p << "\n"; newnavstate->CopyTo(curnavstate); // Increase passed_volume // TODO: correct counting of travel in "world" bounding box if(step>0) crossedvolumecount++; // if(crossedvolumecount > 1000){ //std::cerr << "OOPS: Problem for pixel " << pixel_count_1 << " " << pixel_count_2 << " \n"; //break;} } // end while /////////////////////////////////// // Store the number of passed volume at 'volume_result' *(image+pixel_count_2*data_size_x+pixel_count_1) = crossedvolumecount; } // end inner loop } // end outer loop NavigationState::ReleaseInstance( curnavstate ); NavigationState::ReleaseInstance( newnavstate ); } // end XRayWithVecGeom
/** * Method is used to add new physics material. * @param name is new material name. * @param params is material parameters vector: static friction, dynamic friction, restitution. */ void PhysicsManager::addPhysicsMaterial(const string& name, const Vector3D& params) { PxMaterial* material = physicsSDK->createMaterial(params.x(),params.y(),params.z()); materials.push_back(make_pair(name,material)); }
int Ray::intersectsBox(const Vector3D &a, const Vector3D &b, Vector3D &in, Vector3D &out) const { Vector3D ax(b.x(), a.y(), a.z()); // a décalé en x Vector3D az(a.x(), a.y(), b.z()); // a décalé en z Vector3D bx(a.x(), b.y(), b.z()); // b décalé en x Vector3D bz(b.x(), b.y(), a.z()); // b décalé en z if(origine.x() > a.x() && origine.x() < b.x() && origine.y() > a.y() && origine.y() < b.y() && origine.z() > a.z() && origine.z() < b.z()) { in=origine; if(intersects(a, az, ax, out)){ // Intersection du plan a az ax if(out.x() >= a.x() && out.x() <= b.x() && out.z() >= a.z() && out.z() <= b.z()){ // In da box return 1; } } if(intersects(a, az, bx, out)) { // Intersection du plan a az bx if(out.y() >= a.y() && out.y() <= b.y() && out.z() >= a.z() && out.z() <= b.z()){ // In da box return 1; } } if(intersects(a, ax, bz, out)){ // Intersection du plan a ax bz if(out.x() >= a.x() && out.x() <= b.x() && out.y() >= a.y() && out.y() <= b.y()){ // In da box return 1; } } if(intersects(b, bx, bz, out)){ // Intersection du plan b bx bz if(out.x() >= a.x() && out.x() <= b.x() && out.z() >= a.z() && out.z() <= b.z()){ // In da box return 1; } } if(intersects(b, bx, az, out)){ // Intersection du plan b bx az if(out.x() >= a.x() && out.x() <= b.x() && out.y() >= a.y() && out.y() <= b.y()){ // In da box return 1; } } if(intersects(b, bz, ax, out)){ // Intersection du plan b bz ax if(out.y() >= a.y() && out.y() <= b.y() && out.z() >= a.z() && out.z() <= b.z()){ // In da box return 1; } } } else { // Origine hors de la boite int resu=0; Vector3D aaxaz; Vector3D aazbx; Vector3D aaxbz; Vector3D bbxbz; Vector3D bbxaz; Vector3D bbzax; bool ifaaxaz = intersects(a, ax, az, aaxaz); bool ifaazbx = intersects(a, az, bx, aazbx); bool ifaaxbz = intersects(a, ax, bz, aaxbz); bool ifbbxbz = intersects(b, bx, bz, bbxbz); bool ifbbxaz = intersects(b, bx, az, bbxaz); bool ifbbzax = intersects(b, bz, ax, bbzax); if(ifaaxaz&&resu<2){ // Intersection sur le plan a ax az et pas encore deux points d'entrée/sortie if(aaxaz.x() >= a.x() && aaxaz.x() <= b.x() && aaxaz.z() >= a.z() && aaxaz.z() <= b.z()){ // In da box if(resu==0){ in=aaxaz; ++resu; } else{ if(resu==1&&aaxaz.distanceToPoint(in)>0.001){ out=aaxaz; ++resu; } } } } if(ifaazbx&&resu<2){ // Intersection sur le plan a az bx et pas encore deux points d'entrée/sortie if(aazbx.y() >= a.y() && aazbx.y() <= b.y() && aazbx.z() >= a.z() && aazbx.z() <= b.z()){ // In da box if(resu==0){ in=aazbx; ++resu; } else{ if(resu==1&&aazbx.distanceToPoint(in)>0.001){ out=aazbx; ++resu; } } } } if(ifaaxbz&&resu<2){ // Intersection sur le plan a ax bz et pas encore deux points d'entrée/sortie if(aaxbz.x() >= a.x() && aaxbz.x() <= b.x() && aaxbz.y() >= a.y() && aaxbz.y() <= b.y()){ // In da box if(resu==0){ in=aaxbz; ++resu; } else{ if(resu==1&&aaxbz.distanceToPoint(in)>0.001){ out=aaxbz; ++resu; } } } } if(ifbbxbz&&resu<2){ // Intersection sur le plan b bx bz et pas encore deux points d'entrée/sortie if(bbxbz.x() >= a.x() && bbxbz.x() <= b.x() && bbxbz.z() >= a.z() && bbxbz.z() <= b.z()){ // In da box if(resu==0){ in=bbxbz; ++resu; } else{ if(resu==1&&bbxbz.distanceToPoint(in)>0.001){ out=bbxbz; ++resu; } } } } if(ifbbxaz&&resu<2){ // Intersection sur le plan b bx az et pas encore deux points d'entrée/sortie if(bbxaz.x() >= a.x() && bbxaz.x() <= b.x() && bbxaz.y() >= a.y() && bbxaz.y() <= b.y()){ // In da box if(resu==0){ in=bbxaz; ++resu; } else{ if(resu==1&&bbxaz.distanceToPoint(in)>0.001){ out=bbxaz; ++resu; } } } } if(ifbbzax&&resu<2){ // Intersection sur le plan b bz ax et pas encore deux points d'entrée/sortie if(bbzax.y() >= a.y() && bbzax.y() <= b.y() && bbzax.z() >= a.z() && bbzax.z() <= b.z()){ // In da box if(resu==0){ in=bbzax; ++resu; } else{ if(resu==1&&bbzax.distanceToPoint(in)>0.001){ out=bbzax; ++resu; } } } } if(resu < 2) // Passe hors de la boite ou sur une arrête { return 0; } if(origine.distanceToPointSquared(in) > origine.distanceToPointSquared(out)) // Inversion si les deux points trouvés ne l'ont pas été dans le bon ordre { Vector3D tmp = in; in = out; out = tmp; } return 2; } }
/** * Method is used to set physics scene gravity. * @param gravity is gravity vector. */ void PhysicsManager::setGravity(const Vector3D& gravity) { scene->setGravity(PxVec3(gravity.x(),gravity.y(),gravity.z())); }
void Projection::project( const Vector3D& p, float& h, float& v ) { Vector3D pr = myTransform * p; h = (float)pr.x(); v = (float)pr.y(); }
void write_stl( Mesh* mesh, const char* filename, MsqError& err ) { // Open the file ofstream file(filename); if (!file) { MSQ_SETERR(err)(MsqError::FILE_ACCESS); return; } // Write header char header[70]; sprintf( header, "Mesquite%d", rand() ); file << "solid " << header << endl; MsqVertex coords[3]; std::vector<Mesh::VertexHandle> verts(3); std::vector<size_t> offsets(2); // Iterate over all elements size_t count = 0; std::vector<Mesh::ElementHandle> elems; std::vector<Mesh::ElementHandle>::iterator iter; mesh->get_all_elements( elems, err ); MSQ_ERRRTN(err); for (iter = elems.begin(); iter != elems.end(); ++iter) { // Skip non-triangles Mesh::ElementHandle elem = *iter; EntityTopology type; mesh->elements_get_topologies( &elem, &type, 1, err ); MSQ_ERRRTN(err); if (type != TRIANGLE) continue; ++count; // Get vertex coordinates mesh->elements_get_attached_vertices( &elem, 1, verts, offsets, err ); MSQ_ERRRTN(err); mesh->vertices_get_coordinates( &verts[0], coords, 3, err ); MSQ_ERRRTN(err); // Get triagnle normal Vector3D n = (coords[0] - coords[1]) * (coords[0] - coords[2]); n.normalize(); // Write triangle file << "facet normal " << n.x() << " " << n.y() << " " << n.z() << endl; file << "outer loop" << endl; for (unsigned i = 0; i < 3; ++i) file << "vertex " << coords[i].x() << " " << coords[i].y() << " " << coords[i].z() << endl; file << "endloop" << endl; file << "endfacet" << endl; } file << "endsolid " << header << endl; file.close(); if (count == 0) { std::remove(filename); MSQ_SETERR(err)("Mesh contains no triangles", MsqError::INVALID_STATE); } }
// The 'run' protected method void LoadSeriesThread::run() { if(m_seriesToLoadId.isEmpty()) return; // Load the series data from Orthanc OrthancClient::Series series(m_orthanc, m_seriesToLoadId.toStdString()); int w = series.GetWidth(), h = series.GetHeight(), nbInst = series.GetInstanceCount(); if(w != 0 && h != 0 && nbInst != 0) { // If the series is valid, prepare a series data vtkSmartPointer<SeriesData> seriesData(new SeriesData()); seriesData->SetDimensions(w, h, nbInst); seriesData->SetScalarType(VTK_UNSIGNED_SHORT); seriesData->AllocateScalars(); // Load 3D image from Orthanc try{ series.Load3DImage(seriesData->GetScalarPointer(0, 0, 0), Orthanc::PixelFormat_SignedGrayscale16, 2*w, 2*w*h, &m_progressValue); } catch(OrthancClient::OrthancClientException& e) { cerr << e.What() << endl; m_seriesToLoadId = ""; emit seriesLoaded(0); return; } // Load other information OrthancClient::Instance instance = series.GetInstance(0); instance.LoadTagContent("0010-0010"); // Patient name seriesData->setPatientName(instance.GetLoadedTagContent()); // TODO encoding problem instance.LoadTagContent("0008-1030"); // Study description seriesData->setStudyDescription(instance.GetLoadedTagContent()); instance.LoadTagContent("0008-103E"); // Series description seriesData->setSeriesDescription(instance.GetLoadedTagContent()); // Voxel size and spacing seriesData->SetSpacing(series.GetVoxelSizeX(), series.GetVoxelSizeY(), computeSliceSpacing(series)); try { instance.LoadTagContent("0008-0060"); // Modality seriesData->setModality(instance.GetLoadedTagContent()); } catch(exception& e) {} try { instance.LoadTagContent("0028-1052"); // Rescale intercept double intercept = QString(instance.GetLoadedTagContent().c_str()).toDouble(); instance.LoadTagContent("0028-1053"); // Rescale slope double slope = QString(instance.GetLoadedTagContent().c_str()).toDouble(); seriesData->setRescaleInterceptAndSlope(intercept, slope); } catch(exception& e) {} try { seriesData->addBasicWindow(); instance.LoadTagContent("0028-1050"); // Window center QString centersString = instance.GetLoadedTagContent().c_str(); instance.LoadTagContent("0028-1051"); // Window width QString widthsString = instance.GetLoadedTagContent().c_str(); QStringList centers = centersString.split("\\"); QStringList widths = widthsString.split("\\"); if(centers.size() == widths.size()) { for(int i = 0 ; i < centers.size() ; i++) seriesData->addBasicWindow(centers.at(i).toDouble(), widths.at(i).toDouble()); } } catch(exception& e) {} // Signal the data... SeriesData* data = seriesData.GetPointer(); seriesData = 0; // ... after having transformed it instance.LoadTagContent("0020-0037"); QString or1 = instance.GetLoadedTagContent().c_str(); QStringList or1s = or1.split("\\"); Vector3D v(or1s.at(0).toDouble(), or1s.at(1).toDouble(), or1s.at(2).toDouble()); Vector3D w(or1s.at(3).toDouble(), or1s.at(4).toDouble(), or1s.at(5).toDouble()); Vector3D cross = v.crossProduct(w); vtkSmartPointer<vtkImageReslice> transform = vtkSmartPointer<vtkImageReslice>::New(); transform->SetInput(data); transform->SetResliceAxesDirectionCosines(v.x(), v.y(), v.z(), w.x(), w.y(), w.z(), cross.x(), cross.y(), cross.z()); transform->Update(); data->DeepCopy(transform->GetOutput()); emit seriesLoaded(data); } m_seriesToLoadId = ""; }
return true; } std::string vecToStr(const Vector3D &v) { std::stringstream buffer;
void XRayWithROOT(int axis, Vector3D<Precision> origin, Vector3D<Precision> bbox, Vector3D<Precision> dir, double axis1_start, double axis1_end, double axis2_start, double axis2_end, int data_size_x, int data_size_y, double pixel_axis, int * image) { if(VERBOSE){ std::cout << "from [" << axis1_start << ";" << axis2_start << "] to [" << axis1_end << ";" << axis2_end << "]\n"; std::cout << "Xpixels " << data_size_x << " YPixels " << data_size_y << "\n"; std::cout << pixel_axis << "\n"; } double pixel_width_1 = (axis1_end-axis1_start)/data_size_x; double pixel_width_2 = (axis2_end-axis2_start)/data_size_y; if(VERBOSE){ std::cout << pixel_width_1 << "\n"; std::cout << pixel_width_2 << "\n"; } for( int pixel_count_2 = 0; pixel_count_2 < data_size_y; ++pixel_count_2 ){ for( int pixel_count_1 = 0; pixel_count_1 < data_size_x; ++pixel_count_1 ) { double axis1_count = axis1_start + pixel_count_1 * pixel_width_1 + 1E-6; double axis2_count = axis2_start + pixel_count_2 * pixel_width_2 + 1E-6; if(VERBOSE) { std::cout << "\n OutputPoint("<< axis1_count<< ", "<< axis2_count<< ")\n"; } // set start point of XRay Vector3D<Precision> p; if( axis== 1 ) p.Set( origin[0]-bbox[0], axis1_count, axis2_count); else if( axis== 2) p.Set( axis1_count, origin[1]-bbox[1], axis2_count); else if( axis== 3) p.Set( axis1_count, axis2_count, origin[2]-bbox[2]); TGeoNavigator * nav = gGeoManager->GetCurrentNavigator(); nav->SetCurrentPoint( p.x(), p.y(), p.z() ); nav->SetCurrentDirection( dir.x(), dir.y(), dir.z() ); double distancetravelled=0.; int crossedvolumecount=0; double accumulateddensity =0.; if(VERBOSE) { std::cout << " StartPoint(" << p[0] << ", " << p[1] << ", " << p[2] << ")"; std::cout << " Direction <" << dir[0] << ", " << dir[1] << ", " << dir[2] << ">"<< std::endl; } // propagate until we leave detector TGeoNode const * node = nav->FindNode(); TGeoMaterial const * curmat = node->GetVolume()->GetMaterial(); // std::cout << pixel_count_1 << " " << pixel_count_2 << " " << dir << "\t" << p << "\t"; // std::cout << "IN|OUT" << nav->IsOutside() << "\n"; // if( node ) std::cout << node->GetVolume()->GetName() << "\t"; while( node !=NULL ) { node = nav->FindNextBoundaryAndStep( vecgeom::kInfinity ); distancetravelled+=nav->GetStep(); accumulateddensity+=curmat->GetDensity() * distancetravelled; if(VERBOSE) { if( node != NULL ){ std::cout << " VolumeName: "<< node->GetVolume()->GetName(); } else std::cout << " NULL: "; std::cout << " step[" << nav->GetStep()<< "]"<< std::endl; double const * pROOT = nav->GetCurrentPoint(); p = Vector3D<Precision>(pROOT[0],pROOT[1],pROOT[2]); std::cout << " point(" << p[0] << ", " << p[1] << ", " << p[2] << ")"; } // Increase passed_volume // TODO: correct counting of travel in "world" bounding box crossedvolumecount++; curmat = (node!=0) ? node->GetVolume()->GetMaterial() : 0; } // end while // std::cout << crossedvolumecount << "\n"; /////////////////////////////////// // Store the number of passed volume at 'volume_result' *(image+pixel_count_2*data_size_x+pixel_count_1) = crossedvolumecount;// accumulateddensity ;// crossedvolumecount; if(VERBOSE) { std::cout << " EndOfBoundingBox:"; std::cout << " PassedVolume:" << "<"<< crossedvolumecount << " "; std::cout << " step[" << nav->GetStep()<< "]"; std::cout << " Distance: " << distancetravelled<< std::endl; } } // end inner loop } // end outer loop } // end XRayWithROOT
Vector3D Vector3D::minus(Vector3D b) const { return Vector3D(m_x-b.x(), m_y-b.y(), m_z-b.z()); }
// stressing the vector interface of navigator void XRayWithVecGeom_VecNav(int axis, Vector3D<Precision> origin, Vector3D<Precision> bbox, Vector3D<Precision> dir, double axis1_start, double axis1_end, double axis2_start, double axis2_end, int data_size_x, int data_size_y, double pixel_axis, int * image) { if(VERBOSE){ std::cout << "from [" << axis1_start << ";" << axis2_start << "] to [" << axis1_end << ";" << axis2_end << "]\n"; std::cout << "Xpixels " << data_size_x << " YPixels " << data_size_y << "\n"; std::cout << pixel_axis << "\n"; } double pixel_width_1 = (axis1_end-axis1_start)/data_size_x; double pixel_width_2 = (axis2_end-axis2_start)/data_size_y; if(VERBOSE){ std::cout << pixel_width_1 << "\n"; std::cout << pixel_width_2 << "\n"; } // we need N navstates ( where N should be a multiple of the SIMD width ) unsigned int N = 8; NavigationState ** newnavstates = new NavigationState*[N]; NavigationState ** curnavstates = new NavigationState*[N]; for( unsigned int j=0;j<N;++j ){ newnavstates[j] = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() ); curnavstates[j] = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() ); } SOA3D<Precision> points(N); SOA3D<Precision> dirs(N); SOA3D<Precision> workspaceforlocalpoints(N); SOA3D<Precision> workspaceforlocaldirs(N); // initialize dirs from dir for( unsigned int j=0; j<N; ++j ) dirs.set(j, dir.x(), dir.y(),dir.z()); double * steps = new double[N]; double * psteps = new double[N]; double * safeties = new double[N]; int * nextnodeworkspace = new int[N]; // some workspace for the navigator; not important here // initialize physical steps to infinity for(unsigned int j=0;j<N;++j) psteps[j]=vecgeom::kInfinity; for( int pixel_count_2 = 0; pixel_count_2 < data_size_y; ++pixel_count_2 ){ for( int pixel_count_1 = 0; pixel_count_1 < data_size_x; ++pixel_count_1 ) { double axis1_count = axis1_start + pixel_count_1 * pixel_width_1 + 1E-6; double axis2_count = axis2_start + pixel_count_2 * pixel_width_2 + 1E-6; if(VERBOSE) { std::cout << "\n OutputPoint("<< axis1_count<< ", "<< axis2_count<< ")\n"; } // std::cout << pixel_count_1 << " " << pixel_count_2 << "\n"; // set start points of XRay; points should be in a SOA/AOS SimpleNavigator nav; // initialize points and locate them is serialized for( unsigned int j=0; j<N; ++j ){ if( axis== 1 ) points.set( j, origin[0]-bbox[0], axis1_count, axis2_count ); else if( axis== 2) points.set( j, axis1_count, origin[1]-bbox[1], axis2_count ); else if( axis== 3) points.set( j, axis1_count, axis2_count, origin[2]-bbox[2] ); curnavstates[j]->Clear(); nav.LocatePoint( GeoManager::Instance().GetWorld(), points[j], *curnavstates[j], true ); } double distancetravelled=0.; int crossedvolumecount=0; if(VERBOSE) { std::cout << " StartPoint(" << points[0].x() << ", " << points[1].y() << ", " << points[2].z() << ")"; std::cout << " Direction <" << dirs[0].x() << ", " << dirs[1].y() << ", " << dirs[2].z() << ">"<< std::endl; } // we do the while loop only over the first "particle index" // the rest of the particles should follow exactly the same path while( ! curnavstates[0]->IsOutside() ) { nav.FindNextBoundaryAndStep( points, dirs, workspaceforlocalpoints, workspaceforlocaldirs, curnavstates, newnavstates, psteps, safeties, steps, nextnodeworkspace); //std::cout << "step " << step << "\n"; distancetravelled+=steps[0]; // TODO: DO HERE AN ASSERTION THAT ALL STEPS AGREE // // std::cout << "GOING FROM " // << curnavstate->Top()->GetLabel() << "("; // curnavstate->Top()->PrintType(); // std::cout << ") to "; // // if( newnavstate->Top() ){ // std::cout << newnavstate->Top()->GetLabel() << "("; // newnavstate->Top()->PrintType(); // std::cout << ")"; // } // else // std::cout << "outside "; // // if ( curnavstate->Top() == newnavstate->Top() ) { // std::cout << " CROSSING PROBLEM \n"; // curnavstate->Print(); // newnavstate->Print(); // } // // std::cout << "# step " << step << " crossed "<< crossedvolumecount << "\n"; // here we have to propagate particle ourselves and adjust navigation state // propagate points for(unsigned int j=0;j<N;++j){ points.set(j, points[j] + dirs[j]*(steps[0] + 1E-6)); newnavstates[j]->CopyTo(curnavstates[j]); } // Increase passed_volume // TODO: correct counting of travel in "world" bounding box if(steps[0]>0) crossedvolumecount++; } // end while /////////////////////////////////// // Store the number of passed volume at 'volume_result' *(image+pixel_count_2*data_size_x+pixel_count_1) = crossedvolumecount; } // end inner loop } // end outer loop for( unsigned int j=0; j<N ; ++j ) { NavigationState::ReleaseInstance( curnavstates[j] ); NavigationState::ReleaseInstance( newnavstates[j] ); } } // end XRayWithVecGeomVectorInterface
Vector3D Vector3D::cross(Vector3D b) const { meters x = m_y*b.z() - m_z*b.y(); meters y = m_z*b.x() - m_x*b.z(); meters z = m_x*b.y() - m_y*b.x(); return Vector3D(x,y,z); }
/** * Method is used to initialize 3D sound effect. * @param position is 3D sound position. */ void SoundEffect::initialize3DSoundEffect(const Vector3D& position) { effectSound.setPosition(position.x(),position.y(),position.z()); effectSound.setRelativeToListener(true); }
Vector3D Vector3D::plus(Vector3D b) const { return Vector3D(m_x+b.x(), m_y+b.y(), m_z+b.z()); }
bool Terrain::isOut(const Vector3D &p) { Vector2D p2(p.x(),p.z()); return p.y()>getHauteur(p2); }
// stressing the vector interface of navigator void XRayWithVecGeom_VecNav(int axis, Vector3D<Precision> origin, Vector3D<Precision> bbox, Vector3D<Precision> dir, double axis1_start, double axis1_end, double axis2_start, double axis2_end, int data_size_x, int data_size_y, double pixel_axis, int * image) { int counter=0; // we need N navstates ( where N should be a multiple of the SIMD width ) unsigned int N = 8; NavigationState ** newnavstates = new NavigationState*[N]; NavigationState ** curnavstates = new NavigationState*[N]; for( unsigned int j=0;j<N;++j ){ newnavstates[j] = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() ); curnavstates[j] = NavigationState::MakeInstance( GeoManager::Instance().getMaxDepth() ); } SOA3D<Precision> points(N); SOA3D<Precision> dirs(N); SOA3D<Precision> workspaceforlocalpoints(N); SOA3D<Precision> workspaceforlocaldirs(N); // initialize dirs from dir for( unsigned int j=0; j<N; ++j ) dirs.set(j, dir.x(), dir.y(),dir.z()); double * steps = new double[N]; double * psteps = new double[N]; double * safeties = new double[N]; int * nextnodeworkspace = new int[N]; // some workspace for the navigator; not important here // initialize physical steps to infinity for(unsigned int j=0;j<N;++j) psteps[j]=vecgeom::kInfinity; Stopwatch internaltimer; internaltimer.Start(); SimpleNavigator nav; // initialize points and locate them is serialized for( unsigned int j=0; j<N; ++j ){ points.set( j, 0, 0, 0 ); curnavstates[j]->Clear(); nav.LocatePoint( GeoManager::Instance().GetWorld(), points[j], *curnavstates[j], true ); } double distancetravelled=0.; int crossedvolumecount=0; if(VERBOSE) { std::cout << " StartPoint(" << points[0].x() << ", " << points[1].y() << ", " << points[2].z() << ")"; std::cout << " Direction <" << dirs[0].x() << ", " << dirs[1].y() << ", " << dirs[2].z() << ">"<< std::endl; } // we do the while loop only over the first "particle index" // the rest of the particles should follow exactly the same path while( ! curnavstates[0]->IsOutside() ) { nav.FindNextBoundaryAndStep( points, dirs, workspaceforlocalpoints, workspaceforlocaldirs, curnavstates, newnavstates, psteps, safeties, steps, nextnodeworkspace); //std::cout << "step " << step << "\n"; distancetravelled+=steps[0]; // TODO: DO HERE AN ASSERTION THAT ALL STEPS AGREE if(VERBOSE) { if( newnavstates[0]->Top() != NULL ) std::cout << " *VGV " << counter++ << " * point" << points[0] << " goes to " << " VolumeName: " << newnavstates[0]->Top()->GetLabel(); else std::cout << " NULL: "; std::cout << " step[" << steps[0] << "]"; std::cout << " boundary[" << newnavstates[0]->IsOnBoundary() << "]\n"; } // here we have to propagate particle ourselves and adjust navigation state // propagate points for(unsigned int j=0;j<N;++j){ points.set(j, points[j] + dirs[j]*(steps[0] + 1E-6)); newnavstates[j]->CopyTo(curnavstates[j]); } // Increase passed_volume // TODO: correct counting of travel in "world" bounding box if(steps[0]>0) crossedvolumecount++; } // end while internaltimer.Stop(); std::cout << "VecGeom vec time (per track) " << internaltimer.Elapsed()/N << "\n"; for( unsigned int j=0; j<N ; ++j ) { NavigationState::ReleaseInstance( curnavstates[j] ); NavigationState::ReleaseInstance( newnavstates[j] ); } } // end XRayWithVecGeomVectorInterface
void CameraMovement::moveCamera(Camera& camera, Vector3D deltaV) { static Vector3D camVelocity(0,0,40); camVelocity = camVelocity.plus(deltaV); if (camVelocity.magnitude() > 0) { Vector3D newCamLocation = camera.getLocation().plus(camVelocity); // check known bounds if (newCamLocation.z() < m_minimumCameraZ) { newCamLocation.z() = m_minimumCameraZ; } if (newCamLocation.x() < m_boundsMin.x()) { newCamLocation.x() = m_boundsMin.x(); } else if (newCamLocation.x() > m_boundsMax.x()) { newCamLocation.x() = m_boundsMax.x(); } if (newCamLocation.y() < m_boundsMin.y()) { newCamLocation.y() = m_boundsMin.y(); } else if (newCamLocation.y() > m_boundsMax.y()) { newCamLocation.y() = m_boundsMax.y(); } // Check pyramid bounds // calculate the x,y portion of pyramid center/top Vector3D pyramidTop = m_boundsMax.plus(m_boundsMin).times(0.5); // calculate max z pyramidTop.z() = std::max( (m_cameraMax.x() - m_cameraMin.x())/(2*std::tan(camera.getHorizontalFov()/2.0)), (m_cameraMax.y() - m_cameraMin.y())/(2*std::tan(camera.getVerticalFov()/2.0)) ) + m_minimumCameraZ; if (newCamLocation.z() > pyramidTop.z()) { newCamLocation = pyramidTop; } else { // up dir meters upBase = (m_cameraMax.y() - m_cameraMin.y()) / 2.0; meters upMax = pyramidTop.y() + upBase*(pyramidTop.z() - newCamLocation.z()) / (pyramidTop.z() - m_minimumCameraZ); if ( newCamLocation.y() - pyramidTop.y() > upMax) { newCamLocation.y() = upMax + pyramidTop.y(); } else if ( newCamLocation.y() - pyramidTop.y() < -upMax ) { newCamLocation.y() = - upMax + pyramidTop.y(); } // right dir meters rightBase = (m_cameraMax.x() - m_cameraMin.x()) / 2.0; meters rightMax = pyramidTop.x() + rightBase*(pyramidTop.z() - newCamLocation.z()) / (pyramidTop.z() - m_minimumCameraZ); if ( newCamLocation.x() - pyramidTop.x() > rightMax) { newCamLocation.x() = rightMax + pyramidTop.x(); } else if ( newCamLocation.x() - pyramidTop.x() < -rightMax ) { newCamLocation.x() = - rightMax + pyramidTop.x(); } } camera.setLocation(newCamLocation); // adjust velocity camVelocity = camVelocity.times(1 - m_cameraFriction); if (camVelocity.magnitude() < 0.1) { camVelocity = Vector3D(0,0,0); } } m_boundsMin = Vector3D( MAX_METERS, MAX_METERS, MAX_METERS); m_boundsMax = Vector3D(-MAX_METERS,-MAX_METERS,-MAX_METERS); m_cameraMin = Vector3D( MAX_METERS, MAX_METERS, MAX_METERS); m_cameraMax = Vector3D(-MAX_METERS,-MAX_METERS,-MAX_METERS); }
bool Terrain::isIn(const Vector3D &p) const { Vector2D p2(p.x(),p.z()); return p.y()<=getHauteur(p2); }