示例#1
0
        bool Brush::canMoveBoundary(const Face& face, const Vec3f& delta) const {

            const Mat4f pointTransform = translationMatrix(delta);
            BrushGeometry testGeometry(m_worldBounds);

            Face testFace(face);
            testFace.transform(pointTransform, Mat4f::Identity, false, false);

            FaceSet droppedFaces;
            FaceList::const_iterator it, end;
            for (it = m_faces.begin(), end = m_faces.end(); it != end; ++it) {
                Face* otherFace = *it;
                if (otherFace != &face)
                    testGeometry.addFace(*otherFace, droppedFaces);
            }

            BrushGeometry::CutResult result = testGeometry.addFace(testFace, droppedFaces);
            bool inWorldBounds = m_worldBounds.contains(testGeometry.bounds);

            m_geometry->restoreFaceSides();

            return inWorldBounds && result == BrushGeometry::Split && droppedFaces.empty();
        }
void NonseparableNumericalTestKernelTrialIntegrator<
    BasisFunctionType, KernelType, ResultType, GeometryFactory>::
    integrate(const std::vector<ElementIndexPair> &elementIndexPairs,
              const Shapeset<BasisFunctionType> &testShapeset,
              const Shapeset<BasisFunctionType> &trialShapeset,
              const std::vector<arma::Mat<ResultType> *> &result) const {
  const int pointCount = m_quadWeights.size();
  const int geometryPairCount = elementIndexPairs.size();

  if (result.size() != elementIndexPairs.size())
    throw std::invalid_argument(
        "NonseparableNumericalTestKernelTrialIntegrator::integrate(): "
        "arrays 'result' and 'elementIndicesA' must have the same number "
        "of elements");
  if (pointCount == 0 || geometryPairCount == 0)
    return;
  // TODO: in the (pathological) case that pointCount == 0 but
  // geometryPairCount != 0, set elements of result to 0.

  const int testDofCount = testShapeset.size();
  const int trialDofCount = trialShapeset.size();

  const BasisData<BasisFunctionType> &testBasisData =
      basisData(TEST, testShapeset);
  const BasisData<BasisFunctionType> &trialBasisData =
      basisData(TRIAL, trialShapeset);
  GeometricalData<CoordinateType> &testGeomData = m_testGeomData.local();
  GeometricalData<CoordinateType> &trialGeomData = m_trialGeomData.local();

  size_t testBasisDeps = 0, trialBasisDeps = 0;
  size_t testGeomDeps = 0, trialGeomDeps = 0;

  m_testTransformations.addDependencies(testBasisDeps, testGeomDeps);
  m_trialTransformations.addDependencies(trialBasisDeps, trialGeomDeps);
  m_kernels.addGeometricalDependencies(testGeomDeps, trialGeomDeps);
  m_integral.addGeometricalDependencies(testGeomDeps, trialGeomDeps);

  typedef typename GeometryFactory::Geometry Geometry;
  std::unique_ptr<Geometry> testGeometry(m_testGeometryFactory.make());
  std::unique_ptr<Geometry> trialGeometry(m_trialGeometryFactory.make());

  CollectionOf3dArrays<BasisFunctionType> testValues, trialValues;
  CollectionOf3dArrays<KernelType> kernelValues;

  for (size_t i = 0; i < result.size(); ++i) {
    assert(result[i]);
    result[i]->set_size(testDofCount, trialDofCount);
  }

  // Iterate over the elements
  for (int pairIndex = 0; pairIndex < geometryPairCount; ++pairIndex) {
    const int testElementIndex = elementIndexPairs[pairIndex].first;
    const int trialElementIndex = elementIndexPairs[pairIndex].second;
    m_testRawGeometry.setupGeometry(testElementIndex, *testGeometry);
    m_trialRawGeometry.setupGeometry(trialElementIndex, *trialGeometry);
    testGeometry->getData(testGeomDeps, m_localTestQuadPoints, testGeomData);
    if (testGeomDeps & DOMAIN_INDEX)
      testGeomData.domainIndex =
          m_testRawGeometry.domainIndex(testElementIndex);
    trialGeometry->getData(trialGeomDeps, m_localTrialQuadPoints,
                           trialGeomData);
    if (trialGeomDeps & DOMAIN_INDEX)
      trialGeomData.domainIndex =
          m_trialRawGeometry.domainIndex(trialElementIndex);
    m_testTransformations.evaluate(testBasisData, testGeomData, testValues);
    m_trialTransformations.evaluate(trialBasisData, trialGeomData, trialValues);

    m_kernels.evaluateAtPointPairs(testGeomData, trialGeomData, kernelValues);
    m_integral.evaluateWithNontensorQuadratureRule(
        testGeomData, trialGeomData, testValues, trialValues, kernelValues,
        m_quadWeights, *result[pairIndex]);
  }
}
QgsDelimitedTextFeatureIterator::QgsDelimitedTextFeatureIterator( QgsDelimitedTextProvider* p, const QgsFeatureRequest& request )
    : QgsAbstractFeatureIterator( request )
    , P( p )
{
  P->mActiveIterators << this;

  // Determine mode to use based on request...
  QgsDebugMsg( "Setting up QgsDelimitedTextIterator" );

  // Does the layer have geometry - will revise later to determine if we actually need to
  // load it.
  mLoadGeometry = P->mGeomRep != QgsDelimitedTextProvider::GeomNone;

  // Does the layer have an explicit or implicit subset (implicit subset is if we have geometry which can
  // be invalid)

  mTestSubset = P->mSubsetExpression;
  mTestGeometry = false;

  mMode = FileScan;
  if ( request.filterType() == QgsFeatureRequest::FilterFid )
  {
    QgsDebugMsg( "Configuring for returning single id" );
    mFeatureIds.append( request.filterFid() );
    mMode = FeatureIds;
    mTestSubset = false;
  }
  // If have geometry and testing geometry then evaluate options...
  // If we don't have geometry then all records pass geometry filter.
  // CC: 2013-05-09
  // Not sure about intended relationship between filtering on geometry and
  // requesting no geometry? Have preserved current logic of ignoring spatial filter
  // if not requesting geometry.

  else if ( request.filterType() == QgsFeatureRequest::FilterRect && mLoadGeometry
            && !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) )
  {
    QgsDebugMsg( "Configuring for rectangle select" );
    mTestGeometry = true;
    // Exact intersection test only applies for WKT geometries
    mTestGeometryExact = mRequest.flags() & QgsFeatureRequest::ExactIntersect
                         && P->mGeomRep == QgsDelimitedTextProvider::GeomAsWkt;

    QgsRectangle rect = request.filterRect();

    // If request doesn't overlap extents, then nothing to return
    if ( ! rect.intersects( P->extent() ) )
    {
      QgsDebugMsg( "Rectangle outside layer extents - no features to return" );
      mMode = FeatureIds;
    }
    // If the request extents include the entire layer, then revert to
    // a file scan

    else if ( rect.contains( P->extent() ) )
    {
      QgsDebugMsg( "Rectangle contains layer extents - bypass spatial filter" );
      mTestGeometry = false;
    }
    // If we have a spatial index then use it.  The spatial index already accounts
    // for the subset.  Also means we don't have to test geometries unless doing exact
    // intersection

    else if ( P->mUseSpatialIndex )
    {
      mFeatureIds = P->mSpatialIndex->intersects( rect );
      // Sort for efficient sequential retrieval
      qSort( mFeatureIds.begin(), mFeatureIds.end() );
      QgsDebugMsg( QString( "Layer has spatial index - selected %1 features from index" ).arg( mFeatureIds.size() ) );
      mMode = FeatureIds;
      mTestSubset = false;
      mTestGeometry = mTestGeometryExact;
    }
  }

  // If we have a subset index then use it..
  if ( mMode == FileScan && P->mUseSubsetIndex )
  {
    QgsDebugMsg( QString( "Layer has subset index - use %1 items from subset index" ).arg( P->mSubsetIndex.size() ) );
    mTestSubset = false;
    mMode = SubsetIndex;
  }

  // Otherwise just have to scan the file
  if ( mMode == FileScan )
  {
    QgsDebugMsg( "File will be scanned for desired features" );
  }

  // If the request does not require geometry, can we avoid loading it?
  // We need it if we are testing geometry (ie spatial filter), or
  // if testing the subset expression, and it uses geometry.
  if ( mRequest.flags() & QgsFeatureRequest::NoGeometry &&
       ! mTestGeometry &&
       !( mTestSubset && P->mSubsetExpression->needsGeometry() ) )
  {
    QgsDebugMsg( "Feature geometries not required" );
    mLoadGeometry = false;
  }

  QgsDebugMsg( QString( "Iterator is scanning file: " ) + ( scanningFile() ? "Yes" : "No" ) );
  QgsDebugMsg( QString( "Iterator is loading geometries: " ) + ( loadGeometry() ? "Yes" : "No" ) );
  QgsDebugMsg( QString( "Iterator is testing geometries: " ) + ( testGeometry() ? "Yes" : "No" ) );
  QgsDebugMsg( QString( "Iterator is testing subset: " ) + ( testSubset() ? "Yes" : "No" ) );

  rewind();
}
int mitkSliceNavigationControllerTest(int /*argc*/, char* /*argv*/[])
{
   int result=EXIT_FAILURE;

   std::cout << "Creating and initializing a PlaneGeometry: ";
   mitk::PlaneGeometry::Pointer planegeometry = mitk::PlaneGeometry::New();

   mitk::Point3D origin;
   mitk::Vector3D right, bottom, normal;
   mitk::ScalarType width, height;
   mitk::ScalarType widthInMM, heightInMM, thicknessInMM;

   width  = 100;    widthInMM  = width;
   height = 200;    heightInMM = height;
   thicknessInMM = 1.5;
   //  mitk::FillVector3D(origin,         0,          0, thicknessInMM*0.5);
   mitk::FillVector3D(origin, 4.5,              7.3, 11.2);
   mitk::FillVector3D(right,  widthInMM,          0, 0);
   mitk::FillVector3D(bottom,         0, heightInMM, 0);
   mitk::FillVector3D(normal,         0,          0, thicknessInMM);

   mitk::Vector3D spacing;
   normal.Normalize(); normal *= thicknessInMM;
   mitk::FillVector3D(spacing, 1.0, 1.0, thicknessInMM);
   planegeometry->InitializeStandardPlane(right.GetVnlVector(), bottom.GetVnlVector(), &spacing);
   planegeometry->SetOrigin(origin);
   std::cout<<"[PASSED]"<<std::endl;

   std::cout << "Creating and initializing a SlicedGeometry3D with the PlaneGeometry: ";
   mitk::SlicedGeometry3D::Pointer slicedgeometry = mitk::SlicedGeometry3D::New();
   unsigned int numSlices = 5;
   slicedgeometry->InitializeEvenlySpaced(planegeometry, thicknessInMM, numSlices, false);
   std::cout<<"[PASSED]"<<std::endl;

   std::cout << "Creating a Geometry3D with the same extent as the SlicedGeometry3D: ";
   mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New();
   geometry->SetBounds(slicedgeometry->GetBounds());
   geometry->SetIndexToWorldTransform(slicedgeometry->GetIndexToWorldTransform());
   std::cout<<"[PASSED]"<<std::endl;

   mitk::Point3D cornerpoint0;
   cornerpoint0 = geometry->GetCornerPoint(0);

   result=testGeometry(geometry, width, height, numSlices, widthInMM, heightInMM, thicknessInMM, cornerpoint0, right, bottom, normal);
   if(result!=EXIT_SUCCESS)
      return result;

   mitk::AffineTransform3D::Pointer transform = mitk::AffineTransform3D::New();
   transform->SetMatrix(geometry->GetIndexToWorldTransform()->GetMatrix());
   mitk::BoundingBox::Pointer boundingbox = geometry->CalculateBoundingBoxRelativeToTransform(transform);
   geometry->SetBounds(boundingbox->GetBounds());
   cornerpoint0 = geometry->GetCornerPoint(0);

   result=testGeometry(geometry, width, height, numSlices, widthInMM, heightInMM, thicknessInMM, cornerpoint0, right, bottom, normal);
   if(result!=EXIT_SUCCESS)
      return result;

   std::cout << "Changing the IndexToWorldTransform of the geometry to a rotated version by SetIndexToWorldTransform() (keep cornerpoint0): ";
   transform = mitk::AffineTransform3D::New();
   mitk::AffineTransform3D::MatrixType::InternalMatrixType vnlmatrix;
   vnlmatrix = planegeometry->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix();
   mitk::VnlVector axis(3);
   mitk::FillVector3D(axis, 1.0, 1.0, 1.0); axis.normalize();
   vnl_quaternion<mitk::ScalarType> rotation(axis, 0.223);
   vnlmatrix = rotation.rotation_matrix_transpose()*vnlmatrix;
   mitk::Matrix3D matrix;
   matrix = vnlmatrix;
   transform->SetMatrix(matrix);
   transform->SetOffset(cornerpoint0.GetVectorFromOrigin());

   right.SetVnlVector( rotation.rotation_matrix_transpose()*right.GetVnlVector() );
   bottom.SetVnlVector(rotation.rotation_matrix_transpose()*bottom.GetVnlVector());
   normal.SetVnlVector(rotation.rotation_matrix_transpose()*normal.GetVnlVector());
   geometry->SetIndexToWorldTransform(transform);
   std::cout<<"[PASSED]"<<std::endl;

   cornerpoint0 = geometry->GetCornerPoint(0);

   result = testGeometry(geometry, width, height, numSlices, widthInMM, heightInMM, thicknessInMM, cornerpoint0, right, bottom, normal);
   if(result!=EXIT_SUCCESS)
      return result;

   //Testing Execute RestorePlanePositionOperation
   result = testRestorePlanePostionOperation();
   if(result!=EXIT_SUCCESS)
      return result;

   // Re-Orient planes not working as it should on windows
   // However, this might be adjusted during a geometry redesign.
   /*
   //Testing  ReorientPlanes
   result = testReorientPlanes();
   if(result!=EXIT_SUCCESS)
   return result;
   */

   std::cout<<"[TEST DONE]"<<std::endl;
   return EXIT_SUCCESS;
}