Пример #1
0
//-------------------------------------------------------------------------------------------------
/// Returns the shape of the Object
const boost::shared_ptr<const Object> RectangularDetector::shape() const
{
  // --- Create a cuboid shape for your pixels ----
  double szX=m_xpixels;
  double szY=m_ypixels;
  double szZ=0.5;
  std::ostringstream xmlShapeStream;
  xmlShapeStream
      << " <cuboid id=\"detector-shape\"> "
      << "<left-front-bottom-point x=\""<<szX<<"\" y=\""<<-szY<<"\" z=\""<<-szZ<<"\"  /> "
      << "<left-front-top-point  x=\""<<szX<<"\" y=\""<<-szY<<"\" z=\""<<szZ<<"\"  /> "
      << "<left-back-bottom-point  x=\""<<-szX<<"\" y=\""<<-szY<<"\" z=\""<<-szZ<<"\"  /> "
      << "<right-front-bottom-point  x=\""<<szX<<"\" y=\""<<szY<<"\" z=\""<<-szZ<<"\"  /> "
      << "</cuboid>";

  std::string xmlCuboidShape(xmlShapeStream.str());
  Geometry::ShapeFactory shapeCreator;
  boost::shared_ptr<Geometry::Object> cuboidShape = shapeCreator.createShape(xmlCuboidShape);

  return cuboidShape;
}
Пример #2
0
    void FindDetectorsInShape::exec()
    {
      // Get the input workspace
      const MatrixWorkspace_const_sptr WS = getProperty("Workspace");

      bool includeMonitors = getProperty("IncludeMonitors");

      std::string shapeXML = getProperty("ShapeXML");

      //convert into a Geometry object
      Geometry::ShapeFactory sFactory;
      boost::shared_ptr<Geometry::Object> shape_sptr = sFactory.createShape(shapeXML);

      //get the instrument out of the workspace
      Instrument_const_sptr instrument_sptr = WS->getInstrument();

      //To get all the detector ID's
      detid2det_map allDetectors;
      instrument_sptr->getDetectors(allDetectors);

      std::vector<int> foundDets;

      //progress
      detid2det_map::size_type objCmptCount = allDetectors.size();
      int iprogress_step = static_cast<int>(objCmptCount / 100);
      if (iprogress_step == 0) iprogress_step = 1;
      int iprogress=0;


      //Now go through all
      detid2det_map::iterator it;
      detid2det_map::const_iterator it_end = allDetectors.end();
      for (it = allDetectors.begin(); it != it_end; it++)
      {
        Geometry::IDetector_const_sptr det = it->second;

        //attempt to dynamic cast up to an IDetector
        boost::shared_ptr<const Geometry::IDetector> detector_sptr =
            boost::dynamic_pointer_cast<const Geometry::IDetector>(it->second);

        if (detector_sptr)
        {
          if ((includeMonitors) || (!detector_sptr->isMonitor()))
          {
            //check if the centre of this item is within the user defined shape
            if (shape_sptr->isValid(detector_sptr->getPos()))
            {
              //shape encloses this objectComponent
              g_log.debug()<<"Detector contained in shape " << detector_sptr->getID() << std::endl;
              foundDets.push_back(detector_sptr->getID());
            }
          }
        }

        iprogress++;
        if (iprogress % iprogress_step == 0)
        {
          progress(static_cast<double>(iprogress)/static_cast<double>(objCmptCount));
          interruption_point();
        }
      }
      setProperty("DetectorList",foundDets);
    }