Example #1
0
float AABB::getShortestDistance(const hydra::math::Vector3D& inPoint) const {
    //if inside return 0.0f
    if(isInside(inPoint)) return 0.0f;

    //relative point's position
    Vector3D relativePos = inPoint - mCorner;

    bool x_positive = (relativePos.x() > (mVector.x() / 2.0f)),
         y_positive = (relativePos.y() > (mVector.y() / 2.0f)),
         z_positive = (relativePos.z() > (mVector.z() / 2.0f));

    float closestCornerX = 0.0f, closestCornerY = 0.0f, closestCornerZ = 0.0f;
    if(x_positive) closestCornerX = mVector.x();
    if(y_positive) closestCornerY = mVector.y();
    if(z_positive) closestCornerZ = mVector.z();

    Vector3D closestCorner(closestCornerX, closestCornerY, closestCornerZ);
    float distanceToClosestCorner = (relativePos - closestCorner).getMagnitude();

    //if in the interval
    bool xIsInInterval = relativePos.x() > 0.0f && relativePos.x() < mVector.x(),
         yIsInInterval = relativePos.y() > 0.0f && relativePos.y() < mVector.y(),
         zIsInInterval = relativePos.z() > 0.0f && relativePos.z() < mVector.z();

    assert(!(xIsInInterval && yIsInInterval && zIsInInterval));

    float distanceToClosestPlane = -1.0f;

    if(xIsInInterval && yIsInInterval) {
        if(z_positive) {
            distanceToClosestPlane = fabsf(relativePos.z() - mVector.z());
        }
        else {
            distanceToClosestPlane = fabsf(relativePos.z());
        }
    }

    if(xIsInInterval && zIsInInterval) {
        if(y_positive) {
            distanceToClosestPlane = fabsf(relativePos.y() - mVector.y());
        }
        else {
            distanceToClosestPlane = fabsf(relativePos.y());
        }
    }
    if(zIsInInterval && yIsInInterval) {
        if(x_positive) {
            distanceToClosestPlane = fabsf(relativePos.x() - mVector.x());
        }
        else {
            distanceToClosestPlane = fabsf(relativePos.x());
        }
    }

    if(distanceToClosestPlane < 0.0f) return distanceToClosestCorner;
    else return std::min(distanceToClosestCorner, distanceToClosestPlane);
}
Example #2
0
Vector4D::Vector4D(const Vector3D& v, float w)
{
	vec[0] = v.x();
	vec[1] = v.y();
	vec[2] = v.z();
	vec[3] = w;
}
void Workpiece::update(GCode::ToolPath &path) {
  if (!isAutomatic()) return;
  Rectangle3D bounds;

  // Guess workpiece bounds from cutting moves
  vector<SmartPointer<Sweep> > sweeps;
  vector<Rectangle3D> bboxes;

  for (unsigned i = 0; i < path.size(); i++) {
    const GCode::Move &move = path.at(i);

    if (move.getType() == GCode::MoveType::MOVE_RAPID) continue;

    int tool = move.getTool();
    if (tool < 0) continue;

    if (sweeps.size() <= (unsigned)tool) sweeps.resize(tool + 1);
    if (sweeps[tool].isNull())
      sweeps[tool] = ToolSweep::getSweep(path.getTools().get(tool));

    sweeps[tool]->getBBoxes(move.getStartPt(), move.getEndPt(), bboxes, 0);
  }

  for (unsigned i = 0; i < bboxes.size(); i++) bounds.add(bboxes[i]);

  if (bounds == Rectangle3D()) return;

  // Start from z = 0
  Vector3D bMin = bounds.getMin();
  Vector3D bMax = bounds.getMax();
  bounds = Rectangle3D(bMin, Vector3D(bMax.x(), bMax.y(), 0));

  // At least 2mm thick
  if (bounds.getHeight() < 2)
    bounds.add(Vector3D(bMin.x(), bMin.y(), bMin.z() - 2));

  if (bounds.isReal()) {
    // Add margin
    Vector3D margin = bounds.getDimensions() * getMargin() / 100.0;
    bounds.add(bounds.getMin() - margin);
    bounds.add(bounds.getMax() + Vector3D(margin.x(), margin.y(), 0));

    setBounds(bounds);
  }
}
Example #4
0
///// paintGL /////////////////////////////////////////////////////////////////
void GLView::paintGL()
/// Overridden from QGlWidget::paintGL(). Does the drawing of the OpenGL scene.
{
  if(staticUpdateIndex != updateIndex)
    updateGLSettings();

  ///// build a quaternion from the user's changes
  Quaternion<float> changeQuaternion(xRot, yRot, zRot);
  ///// multiply it with the current quaternion
  Quaternion<float> tempQuaternion = *orientationQuaternion;
  *orientationQuaternion = tempQuaternion*changeQuaternion;  // no *= operator implemented yet => calling default constructor?
  ///// generate an axis-angle representation for OpenGL
  Vector3D<float> axis;
  float angle;
  orientationQuaternion->getAxisAngle(axis, angle);

  if(!animation)
  {
    ///// reset the changes
    xRot = 0.0f;
    yRot = 0.0f;
    zRot = 0.0f;
  }

  //if(baseParameters.antialias)
  //{
  //  glClear(GL_COLOR_BUFFER_BIT);
  //}
  //else
  //{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  //}

  glLoadIdentity();
  //qDebug("GlView::xPos = %f, yPos = %f, zPos = %f", xPos, yPos, zPos);
  //qDebug("GlView::orientationQuaternion = (%f, %f, %f, %f)",orientationQuaternion->x(),orientationQuaternion->y(),orientationQuaternion->z(),orientationQuaternion->w());
  ///// camera setup
  if(baseParameters.perspectiveProjection)
    gluLookAt(0.0f, 0.0f, zPos, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
  else
    resizeGL(width(), height());
  glPushMatrix();
  glTranslatef(xPos, yPos, 0.0f);
  glRotatef(angle, axis.x(), axis.y(), axis.z());

  drawScene(); // pure virtual

  glPopMatrix();
  glFlush(); // drawing is complete => send for execution
  if(animation)
    timer->start(redrawWait);
}
QRgb Camera::ptScreen(Terrain &t,const Vector3D& aBox, const Vector3D& bBox, const Vector3D& s, int i, int j, int l, int h)
{
    double x=i*2*lw/l-lw;
    double y=j*2*lh/h-lh;

    Vector3D pt =origine+(dw*w)+(x*u)+(y*v);
    Vector3D dir(pt-origine);
    dir.normalize();
    Ray r(origine,dir);

    //std::cout << origine.x()  <<", "<<origine.y()<<", "<<origine.z()<<"/"<<dir.x()<<", "<<dir.y()<<", "<<dir.z()<< std::endl;
    Vector3D inter;
    bool isBox=false;
    if(!r.intersectRayMarching(t,aBox,bBox,inter,isBox)) {
        QColor couleur(0,0,255,255);
        return couleur.rgb();
    }

    //std::cout << "Touch" << std::endl;
    Vector3D normale;
    double hauteur = t.getHauteurNormale(Vector2D(inter.x(),inter.z()),normale);
    if(isBox) {
        QColor couleur(255,0,0,255);
        return couleur.rgb();
    }
    //std::cout << normale.x()  <<", "<<normale.y()<<", "<<normale.z()<<std::endl;
    double lu=normale*(-s);
    //std::cout <<lu<<std::endl;
    if(lu<0)
        lu=0;


    lu*=200.0;

    if(lu>255)
        lu=255;

    QColor couleur(lu,lu,lu,255);
    return couleur.rgb();


}
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;
}
// 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
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
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
Example #10
0
int benchCachingAndVector(Vector3D<Precision> const &point, Vector3D<Precision> const &dir,
                          Vector3D<kVc::precision_v> const *corners, int vecsize
#ifdef SORTHITBOXES
                          ,
                          Container_t &hitlist
#endif
                          )
{
#ifdef INNERTIMER
  Stopwatch timer;
  timer.Start();
#endif

  Vector3D<Precision> invdir(1. / dir.x(), 1. / dir.y(), 1. / dir.z());
  int hitcount = 0;

  int sign[3];
  sign[0] = invdir.x() < 0;
  sign[1] = invdir.y() < 0;
  sign[2] = invdir.z() < 0;
  for (auto box = 0; box < vecsize; ++box) {
    kVc::precision_v distance =
        BoxImplementation<translation::kIdentity, rotation::kIdentity>::IntersectCachedKernel2<kVc>(
            &corners[2 * box], point, invdir, sign[0], sign[1], sign[2], 0, vecgeom::kInfLength);
    kVc::bool_v hit = distance < vecgeom::kInfLength;
    // std::cerr << hit << "\n";
    // this is Vc specific
    hitcount += hit.count();
#ifdef SORTHITBOXES
    // a little tricky: need to iterate over the mask
    for (auto i = 0; i < kVc::precision_v::Size; ++i) {
      if (hit[i])
        // which box id??
        hitlist.push_back(BoxIdDistancePair_t(box * kVc::precision_v::Size + i, distance[i]));
    }
#endif
  }
// interpret as binary number and do a switch statement
// do a big switch statement here
//    switch( size[0] + size[1] + size[2] ){
//    case 0: {
//        for( auto box = 0; box < vecsize; ++box ){
//        kVc::precision_v distance = BoxImplementation<translation::kIdentity,
//        rotation::kIdentity>::IntersectCachedKernel<kVc,0,0,0>(
//           &corners[2*box],
//           point,
//           invdir,
//           0, vecgeom::kInfLength );
//           kVc::bool_v hit = distance < vecgeom::kInfLength;
//           //std::cerr << hit << "\n";
//           hitcount += hit.count();
//        }       break; }
//    case 3: {
//        for( auto box = 0; box < vecsize; ++box ){
//          kVc::precision_v distance = BoxImplementation<translation::kIdentity,
//          rotation::kIdentity>::IntersectCachedKernel<kVc,1,1,1>(
//          &corners[2*box],
//          point,
//          invdir,
//          0, vecgeom::kInfLength );
//          kVc::bool_v hit = distance < vecgeom::kInfLength;
//          //std::cerr << hit << "\n";
//          hitcount += hit.count();
//    }       break; }
//    default : std::cerr << "DEFAULT CALLED\n";
//    }
#ifdef INNERTIMER
  timer.Stop();
  std::cerr << "# VECTOR hitting " << hitcount << "\n";
  std::cerr << "# VECTOR timer " << timer.Elapsed() << "\n";
#endif
  return hitcount;
}
Example #11
0
int benchCachingNoVector(Vector3D<Precision> const &point, Vector3D<Precision> const &dir,
                         std::vector<Vector3D<Precision>> const &corners
#ifdef SORTHITBOXES
                         ,
                         Container_t &hitlist
#endif
                         )
{
#ifdef INNERTIMER
  Stopwatch timer;
  timer.Start();
#endif

  Vector3D<Precision> invdir(1. / dir.x(), 1. / dir.y(), 1. / dir.z());
  int vecsize  = corners.size() / 2;
  int hitcount = 0;
  int sign[3];
  sign[0] = invdir.x() < 0;
  sign[1] = invdir.y() < 0;
  sign[2] = invdir.z() < 0;
  // interpret as binary number and do a switch statement
  // do a big switch statement here
  // int code = 2 << size[0] + 2 << size[1] + 2 << size[2];
  for (auto box = 0; box < vecsize; ++box) {
    double distance = BoxImplementation<translation::kIdentity, rotation::kIdentity>::IntersectCachedKernel2<kScalar>(
        &corners[2 * box], point, invdir, sign[0], sign[1], sign[2], 0, vecgeom::kInfLength);
    if (distance < vecgeom::kInfLength) {
      hitcount++;
#ifdef SORTHITBOXES
      hitlist.push_back(BoxIdDistancePair_t(box, distance));
#endif
    }
  }

//    switch( size[0] + size[1] + size[2] ){
//    case 0: {
//        for( auto box = 0; box < vecsize; ++box ){
//        double distance = BoxImplementation<translation::kIdentity,
//        rotation::kIdentity>::IntersectCachedKernel<kScalar,0,0,0>(
//           &corners[2*box],
//           point,
//           invdir,
//           0, vecgeom::kInfLength );
//           if( distance < vecgeom::kInfLength ) hitcount++;
//         }       break; }
//    case 3: {
//        for( auto box = 0; box < vecsize; ++box ){
//                double distance = BoxImplementation<translation::kIdentity,
//                rotation::kIdentity>::IntersectCachedKernel<kScalar,1,1,1>(
//                   &corners[2*box],
//                   point,
//                   invdir,
//                   0, vecgeom::kInfLength );
//                   if( distance < vecgeom::kInfLength ) hitcount++;
//                 }       break; }
//    default : std::cerr << "DEFAULT CALLED\n";
//    }
#ifdef INNERTIMER
  timer.Stop();
  std::cerr << "# CACHED hitting " << hitcount << "\n";
  std::cerr << "# CACHED timer " << timer.Elapsed() << "\n";
#endif
  return hitcount;
}
Example #12
0
int main()
{
  // number of boxes
  int numberofboxes = N * N * N;

  int code = (2 << 1) + (2 << 0) + (2 << 1);
  std::cerr << code << "\n";

  // setup AOS form of boxes
  std::vector<Vector3D<Precision>> uppercorners(numberofboxes);
  std::vector<Vector3D<Precision>> lowercorners(numberofboxes);

  // setup same in mixed array of corners ... upper-lower-upper-lower ...
  std::vector<Vector3D<Precision>> corners(2 * numberofboxes);

  // setup SOA form of boxes -- the memory layout should probably rather be SOA6D
  Vector3D<kVc::precision_v> *VcCorners = new Vector3D<kVc::precision_v>[ 2 * numberofboxes / kVc::precision_v::Size ];

  int counter1 = 0;
  int counter2 = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < N; ++k) {
        lowercorners[counter1] = Vector3D<Precision>(i, j, k);
        uppercorners[counter1] = Vector3D<Precision>(i + delta, j + delta, k + delta);

        corners[counter2] = lowercorners[counter1];
        counter2++;
        corners[counter2] = uppercorners[counter1];
        counter2++;

        counter1++;
      }
    }
  }

  // print boxes
  for (int i = 0; i < numberofboxes; ++i) {
    // std::cerr << "# " << i << " lower " << lowercorners[i] << " " << uppercorners[i] << "\n";
  }

  // set up VcCorners
  counter2 = 0;
  for (int i = 0; i < numberofboxes; i += kVc::precision_v::Size) {
    Vector3D<kVc::precision_v> lower;
    Vector3D<kVc::precision_v> upper;
    // assign by components
    for (int k = 0; k < kVc::precision_v::Size; ++k) {
      lower.x()[k] = lowercorners[i + k].x();
      lower.y()[k] = lowercorners[i + k].y();
      lower.z()[k] = lowercorners[i + k].z();
      upper.x()[k] = uppercorners[i + k].x();
      upper.y()[k] = uppercorners[i + k].y();
      upper.z()[k] = uppercorners[i + k].z();
    }
    // std::cerr << lower << "\n";
    // std::cerr << upper << "\n";
    VcCorners[counter2++] = lower;
    VcCorners[counter2++] = upper;
  }
  std::cerr << "assigned " << counter2 << "Vc vectors\n";

  // constructing samples
  std::vector<Vector3D<Precision>> points(SZ);
  std::vector<Vector3D<Precision>> directions(SZ);
  for (int i = 0; i < SZ; ++i) {
    points[i]     = Vector3D<Precision>(N * delta + 0.1, N * delta + 0.1, N * delta + 0.1);
    directions[i] = volumeUtilities::SampleDirection();
  }

  Container_t hitlist;
  hitlist.resize(2 * N);

  Stopwatch timer;
  int hits                    = 0;
  double meanfurthestdistance = 0;

  timer.Start();
  for (int i = 0; i < SZ; ++i) {
#ifdef SORTHITBOXES
    hitlist.clear();
#endif
    hits += benchCachingNoVector(points[i], directions[i], corners
#ifdef SORTHITBOXES
                                 ,
                                 hitlist
#endif
                                 );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
// std::cerr << hitlist << "\n";
#endif
  }
  timer.Stop();
  std::cerr << "Cached times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  hits                 = 0;
  meanfurthestdistance = 0.;
  timer.Start();
  for (int i = 0; i < SZ; ++i) {
    hitlist.clear();
    hits += benchNoCachingNoVector(points[i], directions[i], corners
#ifdef SORTHITBOXES
                                   ,
                                   hitlist
#endif
                                   );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
#endif
  }
  timer.Stop();
  std::cerr << "Ordinary times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  hits                 = 0;
  meanfurthestdistance = 0.;
  timer.Start();
  for (int i = 0; i < SZ; ++i) {
#ifdef SORTHITBOXES
    hitlist.clear();
#endif
    hits += benchCachingAndVector(points[i], directions[i], VcCorners, numberofboxes / kVc::precision_v::Size
#ifdef SORTHITBOXES
                                  ,
                                  hitlist
#endif
                                  );
#ifdef SORTHITBOXES
    sort(hitlist, HitBoxComparatorFunctor());
    meanfurthestdistance += hitlist.back().second;
// std::cerr << "VECTORHITLIST" << hitlist << "\n";
#endif
  }
  timer.Stop();
  std::cerr << "Vector times and hit " << timer.Elapsed() << " " << hits << " " << meanfurthestdistance << "\n";

  return 0;
}