int LineOnPointsSelector2D::RequestData(vtkInformation * request,
    vtkInformationVector ** inputVector,
    vtkInformationVector * outputVector)
{
    const int requestedPort = request->Get(vtkDemandDrivenPipeline::FROM_OUTPUT_PORT());
    const bool generateSelection = requestedPort == 0;
    const bool generateGeometry = requestedPort == 1;

    vtkInformation * inInfo = inputVector[0]->GetInformationObject(0);
    vtkInformation * outSelectionInfo = outputVector->GetInformationObject(0);
    vtkInformation * outPointExtractionInfo = outputVector->GetInformationObject(1);

    auto inputPointSet = vtkPointSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
    auto selectionOutput = vtkSelection::SafeDownCast(outSelectionInfo->Get(vtkDataObject::DATA_OBJECT()));
    auto extractedOutput = vtkPolyData::SafeDownCast(outPointExtractionInfo->Get(vtkDataObject::DATA_OBJECT()));

    auto inputPointData = inputPointSet->GetPointData();
    auto extractionPointData = extractedOutput->GetPointData();

    const vtkIdType numInputPoints = inputPointSet->GetNumberOfPoints();
    if (numInputPoints == 0)
    {
        vtkWarningMacro(<< "LineOnPointsSelector2D: No points in input.");
        return 1;
    }
Exemplo n.º 2
0
bool sm2ccConverter::addRGB(ccPointCloud * cloud)
{
	assert(m_sm_cloud && cloud);
	if (!m_sm_cloud || !cloud)
		return false;

	pcl::PointCloud<OnlyRGB>::Ptr pcl_cloud_rgb (new pcl::PointCloud<OnlyRGB>);
	FROM_PCL_CLOUD(*m_sm_cloud, *pcl_cloud_rgb);

	if (!cloud->reserveTheRGBTable())
		return false;

	size_t pointCount = GetNumberOfPoints(m_sm_cloud);

	//loop
	for (size_t i = 0; i < pointCount; ++i)
	{
		colorType C[3] = {	(colorType)pcl_cloud_rgb->points[i].r,
							(colorType)pcl_cloud_rgb->points[i].g,
							(colorType)pcl_cloud_rgb->points[i].b};
		cloud->addRGBColor(C);
	}

	cloud->showColors(true);

	return true;
}
Exemplo n.º 3
0
bool sm2ccConverter::addNormals(ccPointCloud *cloud)
{
	assert(m_sm_cloud && cloud);
	if (!m_sm_cloud || !cloud)
		return false;

	pcl::PointCloud<OnlyNormals>::Ptr pcl_cloud_normals (new pcl::PointCloud<OnlyNormals>);
	FROM_PCL_CLOUD(*m_sm_cloud, *pcl_cloud_normals);

	if (!cloud->reserveTheNormsTable())
		return false;

	size_t pointCount = GetNumberOfPoints(m_sm_cloud);

	//loop
	for (size_t i = 0; i < pointCount; ++i)
	{
		CCVector3 N(	static_cast<PointCoordinateType>(pcl_cloud_normals->at(i).normal_x),
						static_cast<PointCoordinateType>(pcl_cloud_normals->at(i).normal_y),
						static_cast<PointCoordinateType>(pcl_cloud_normals->at(i).normal_z) );

		cloud->addNorm(N);
	}

	cloud->showNormals(true);
	
	return true;
}
Exemplo n.º 4
0
bool sm2ccConverter::addXYZ(ccPointCloud *cloud)
{
	assert(m_sm_cloud && cloud);
	if (!m_sm_cloud || !cloud)
		return false;

	size_t pointCount = GetNumberOfPoints(m_sm_cloud);

	if (!cloud->reserve(static_cast<unsigned>(pointCount)))
		return false;

	//add xyz to the given cloud taking xyz infos from the sm cloud
	pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud (new pcl::PointCloud<pcl::PointXYZ>);
	FROM_PCL_CLOUD(*m_sm_cloud, *pcl_cloud);

	//loop
	for (size_t i = 0; i < pointCount; ++i)
	{
		CCVector3 P(pcl_cloud->at(i).x,
					pcl_cloud->at(i).y,
					pcl_cloud->at(i).z);

		cloud->addPoint(P);
	}

	return true;
}
Exemplo n.º 5
0
//==== The Mouse Clicks Function =======================================//
void myMouseFunc(int button, int state, int x, int y){

	Picker.onMouse(button,state,x,y);

	delete [] xMtx;
	delete [] yMtx;

	xMtx = GetXMatrix();
	yMtx = GetYMatrix();

	n = GetNumberOfPoints();
}
Exemplo n.º 6
0
int AssignPointAttributeToCoordinatesFilter::RequestData(
    vtkInformation * /*request*/,
    vtkInformationVector ** inputVector,
    vtkInformationVector * outputVector)
{
    auto inData = vtkPointSet::SafeDownCast(inputVector[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
    auto outData = vtkPointSet::SafeDownCast(outputVector->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));

    auto previousPointCoords = inData->GetPoints()->GetData();
    vtkDataArray * pointsToAssign = nullptr;

    if (!this->AttributeArrayToAssign.empty())
    {
        auto newPoints = inData->GetPointData()->GetArray(this->AttributeArrayToAssign.c_str());
        if (!newPoints)
        {
            vtkErrorMacro("Array to assign not found in input data: " + this->AttributeArrayToAssign);
            return 0;
        }

        if (newPoints->GetNumberOfComponents() != 3
            || newPoints->GetNumberOfTuples() != inData->GetNumberOfPoints())
        {
            vtkErrorMacro("Component/Tuple count mismatching in selected data array: " + this->AttributeArrayToAssign);
            return 0;
        }
        pointsToAssign = newPoints;
    }

    outData->ShallowCopy(inData);

    if (pointsToAssign)
    {
        vtkNew<vtkPoints> newPoints;
        newPoints->SetData(pointsToAssign);
        outData->SetPoints(newPoints.Get());
    }

    // pass current point coordinates as point attribute
    if (previousPointCoords)
    {
        outData->GetPointData()->AddArray(previousPointCoords);
    }

    if (auto currentCoords = pointsToAssign ? pointsToAssign : previousPointCoords)
    {
        outData->GetPointData()->SetActiveScalars(currentCoords->GetName());
    }

    return 1;
}
std::pair<vtkSmartPointer<vtkMergePoints>,
          std::unordered_map<vtkIdType, std::vector<graph_descriptor>>>
get_vtk_points_from_graphs(
    const std::vector<std::reference_wrapper<const GraphType>> &graphs,
    const BoundingBox *box) {
  assert(graphs.size() > 0);
  auto unique_points = vtkSmartPointer<vtkPoints>::New();
  std::unordered_map<vtkIdType, std::vector<graph_descriptor>> unique_id_map;
  // check vtkMergePoints with InsertUniquePoint
  // The approach is to keep the points from get_vtk_points_from_graphs
  // of the first graph
  // vtkSmartPointer<vtkPointSet> pointSet =
  // vtkSmartPointer<vtkPolyData>::New();
  vtkSmartPointer<vtkMergePoints> mergePoints =
      vtkSmartPointer<vtkMergePoints>::New();
  vtkIdType lastPtId;
  std::vector<PointsIdMapPair> graphs_point_map;
  std::vector<double *> bounds_vector;
  for(size_t graph_index = 0; graph_index < graphs.size(); ++graph_index) {
    graphs_point_map.emplace_back(
        get_vtk_points_from_graph(graphs[graph_index]));
    const auto &points_per_graph = graphs_point_map.back().first;
    bounds_vector.emplace_back(points_per_graph->GetBounds());
  }

  BoundingBox enclosing_box;
  if(!box)
    enclosing_box = BoundingBox::BuildEnclosingBox(bounds_vector);
  else
    enclosing_box = *box;

  // Init the merger with points from the first graph
  {
    unique_points = graphs_point_map[0].first;
    double bounds[6];
    enclosing_box.GetBounds(bounds);
    mergePoints->InitPointInsertion(unique_points, bounds);
    // Insert the points
    unique_id_map = graphs_point_map[0].second;
    for(vtkIdType i = 0; i < unique_points->GetNumberOfPoints(); i++) {
      mergePoints->InsertUniquePoint(unique_points->GetPoint(i), lastPtId);
    }
  }

  for(size_t graph_index = 1; graph_index < graphs.size(); ++graph_index) {
    append_new_graph_points(graphs_point_map[graph_index], mergePoints,
                            unique_id_map);
  }

  return std::make_pair(mergePoints, unique_id_map);
};
Exemplo n.º 8
0
TEST_F(MatricesToVtk_Grid3D_test, read_points_from_vtkImageData)
{
    auto image = vtkSmartPointer<vtkImageData>::New();
    image->SetExtent(0, 2, 0, 3, 0, 2);
    image->SetSpacing(0.1, 0.1, 0.1);
    image->SetOrigin(-1.0, -2.0, -3.0);

    io::ReadDataSet readDataSet;
    readDataSet.type = io::DataSetType::vectorGrid3D;
    auto & data = readDataSet.data;

    const vtkIdType numPoints = image->GetNumberOfPoints();
    // xyz (tested) + 3-component vector (not tested here)
    data.resize(6, std::vector<io::t_FP>(static_cast<size_t>(numPoints)));
    for (vtkIdType i = 0; i < numPoints; ++i)
    {
        const auto stdI = static_cast<size_t>(i);
        vtkVector3d point;
        image->GetPoint(i, point.GetData());
        data[0u][stdI] = point.GetX();
        data[1u][stdI] = point.GetY();
        data[2u][stdI] = point.GetZ();
    }

    auto parsedImage = MatricesToVtk::loadGrid3D("TestingGrid3D", { readDataSet });
    ASSERT_TRUE(parsedImage);
    ASSERT_TRUE(parsedImage->dataSet());
    ASSERT_EQ(numPoints, parsedImage->dataSet()->GetNumberOfPoints());
    for (vtkIdType i = 0; i < numPoints; ++i)
    {
        vtkVector3d pRef, pParsed;
        image->GetPoint(i, pRef.GetData());
        parsedImage->dataSet()->GetPoint(i, pParsed.GetData());
        ASSERT_DOUBLE_EQ(pRef.GetX(), pRef.GetX());
        ASSERT_DOUBLE_EQ(pRef.GetY(), pRef.GetY());
        ASSERT_DOUBLE_EQ(pRef.GetZ(), pRef.GetZ());
    }
}
Exemplo n.º 9
0
/**
Create the vtkStructuredGrid from the provided workspace
@param progressUpdating: Reporting object to pass progress information up the
stack.
@return fully constructed vtkDataSet.
*/
vtkSmartPointer<vtkDataSet>
vtkMDLineFactory::create(ProgressAction &progressUpdating) const {
  auto product = tryDelegatingCreation<IMDEventWorkspace, 1>(m_workspace,
                                                             progressUpdating);
  if (product != nullptr) {
    return product;
  } else {
    g_log.warning() << "Factory " << this->getFactoryTypeName()
                    << " is being used. You are viewing data with less than "
                       "three dimensions in the VSI. \n";

    IMDEventWorkspace_sptr imdws =
        doInitialize<IMDEventWorkspace, 1>(m_workspace);
    // Acquire a scoped read-only lock to the workspace (prevent segfault from
    // algos modifying ws)
    Mantid::Kernel::ReadLock lock(*imdws);

    const size_t nDims = imdws->getNumDims();
    size_t nNonIntegrated = imdws->getNonIntegratedDimensions().size();

    /*
    Write mask array with correct order for each internal dimension.
    */
    auto masks = Mantid::Kernel::make_unique<bool[]>(nDims);
    for (size_t i_dim = 0; i_dim < nDims; ++i_dim) {
      bool bIntegrated = imdws->getDimension(i_dim)->getIsIntegrated();
      masks[i_dim] =
          !bIntegrated; // TRUE for unmaksed, integrated dimensions are masked.
    }

    // Ensure destruction in any event.
    boost::scoped_ptr<IMDIterator> it(
        createIteratorWithNormalization(m_normalizationOption, imdws.get()));

    // Create 2 points per box.
    vtkNew<vtkPoints> points;
    points->SetNumberOfPoints(it->getDataSize() * 2);

    // One scalar per box
    vtkNew<vtkFloatArray> signals;
    signals->Allocate(it->getDataSize());
    signals->SetName(vtkDataSetFactory::ScalarName.c_str());
    signals->SetNumberOfComponents(1);

    size_t nVertexes;

    auto visualDataSet = vtkSmartPointer<vtkUnstructuredGrid>::New();
    visualDataSet->Allocate(it->getDataSize());

    vtkNew<vtkIdList> linePointList;
    linePointList->SetNumberOfIds(2);

    Mantid::API::CoordTransform const *transform = NULL;
    if (m_useTransform) {
      transform = imdws->getTransformToOriginal();
    }

    Mantid::coord_t out[1];
    auto useBox = std::vector<bool>(it->getDataSize());

    double progressFactor = 0.5 / double(it->getDataSize());
    double progressOffset = 0.5;

    size_t iBox = 0;
    do {
      progressUpdating.eventRaised(double(iBox) * progressFactor);

      Mantid::signal_t signal_normalized = it->getNormalizedSignal();
      if (std::isfinite(signal_normalized) &&
          m_thresholdRange->inRange(signal_normalized)) {
        useBox[iBox] = true;
        signals->InsertNextValue(static_cast<float>(signal_normalized));

        auto coords = std::unique_ptr<coord_t[]>(
            it->getVertexesArray(nVertexes, nNonIntegrated, masks.get()));

        // Iterate through all coordinates. Candidate for speed improvement.
        for (size_t v = 0; v < nVertexes; ++v) {
          coord_t *coord = coords.get() + v * 1;
          size_t id = iBox * 2 + v;
          if (m_useTransform) {
            transform->apply(coord, out);
            points->SetPoint(id, out[0], 0, 0);
          } else {
            points->SetPoint(id, coord[0], 0, 0);
          }
        }
      } // valid number of vertexes returned
      else {
        useBox[iBox] = false;
      }
      ++iBox;
    } while (it->next());

    for (size_t ii = 0; ii < it->getDataSize(); ++ii) {
      progressUpdating.eventRaised((double(ii) * progressFactor) +
                                   progressOffset);

      if (useBox[ii] == true) {
        vtkIdType pointIds = ii * 2;

        linePointList->SetId(0, pointIds + 0); // xyx
        linePointList->SetId(1, pointIds + 1); // dxyz
        visualDataSet->InsertNextCell(VTK_LINE, linePointList.GetPointer());
      } // valid number of vertexes returned
    }

    signals->Squeeze();
    points->Squeeze();

    visualDataSet->SetPoints(points.GetPointer());
    visualDataSet->GetCellData()->SetScalars(signals.GetPointer());
    visualDataSet->Squeeze();

    // Hedge against empty data sets
    if (visualDataSet->GetNumberOfPoints() <= 0) {
      vtkNullUnstructuredGrid nullGrid;
      visualDataSet = nullGrid.createNullData();
    }

    vtkSmartPointer<vtkDataSet> dataset = visualDataSet;
    return dataset;
  }
}
Exemplo n.º 10
0
  
  /* ************** Others ******************* */
  unsigned int n0,numscalars,numverts,numfaces,count,facecount,nidx;
  double pt[3];
  int dims[2] = {1, 1},vert_field,face_field;

  vtkPoints *pts;
  vtkCellArray *polys;
  vtkIdTypeArray *faces;
  
  // Get hold of vertices and faces
  
  // Vertices
  pts = pipefinal->GetOutput()->GetPoints();
  //pts = surf->GetPoints();
  numverts = pts->GetNumberOfPoints();
  out_verts = mxCreateDoubleMatrix(numverts,3,mxREAL);
  out_vertsptr = mxGetPr(out_verts);
  for(n0=0;n0<numverts;n0++)
    {
      pts->GetPoint(n0,pt);
      out_vertsptr[n0] = pt[0];
      out_vertsptr[numverts+n0] = pt[1];
      out_vertsptr[2*numverts+n0] = pt[2];
    }
  
  // Faces
  polys = pipefinal->GetOutput()->GetPolys();
  //polys = surf->GetPolys();
  faces = (vtkIdTypeArray*)polys->GetData();
  
Exemplo n.º 11
0
Arquivo: mitkMesh.cpp Projeto: 0r/MITK
void mitk::Mesh::ExecuteOperation(Operation* operation)
{
  //adding only the operations, that aren't implemented by the pointset.
  switch (operation->GetOperationType())
  {
  case OpNOTHING:
    break;

  case OpNEWCELL:
    {
      mitk::LineOperation *lineOp =
        dynamic_cast<mitk::LineOperation *>(operation);

      // if no lineoperation, then call superclass pointSet
      if (lineOp == nullptr)
      {
        Superclass::ExecuteOperation(operation);
      }

      bool ok;
      int cellId = lineOp->GetCellId();
      CellAutoPointer cellAutoPointer;
      ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);

      // if it doesn't already exist
      if (!ok)
      {
        cellAutoPointer.TakeOwnership( new PolygonType );
        m_PointSetSeries[0]->SetCell(cellId, cellAutoPointer);
        CellDataType cellData;
        cellData.selected = true;
        cellData.selectedLines.clear();
        cellData.closed = false;
        m_PointSetSeries[0]->SetCellData(cellId, cellData);
      }
    }
    break;

  case OpDELETECELL:
    {
      mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
      {
        Superclass::ExecuteOperation(operation);
      }
      m_PointSetSeries[0]->GetCells()->DeleteIndex((unsigned)lineOp->GetCellId());
      m_PointSetSeries[0]->GetCellData()->DeleteIndex((unsigned)lineOp->GetCellId());
    }
    break;

  case OpCLOSECELL:
    //sets the bolean flag closed from a specified cell to true.
    {
      mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
      {
        //then search the selected cell!//TODO
        Superclass::ExecuteOperation(operation);
      }
      bool ok;
      int cellId = lineOp->GetCellId();
      if (cellId<0)//cellId isn't set
      {
        cellId = this->SearchSelectedCell( 0 );
        if (cellId < 0 )//still not found
          return;
      }
      CellAutoPointer cellAutoPointer;

      //get directly the celldata!TODO
      ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellDataType cellData;
        m_PointSetSeries[0]->GetCellData(cellId, &cellData);
        cellData.closed = true;
        m_PointSetSeries[0]->SetCellData(cellId, cellData);
      }
    }
    break;

  case OpOPENCELL:
    {
      mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
      {
        Superclass::ExecuteOperation(operation);
      }
      bool ok;
      int cellId = lineOp->GetCellId();
      CellAutoPointer cellAutoPointer;
      ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellDataType cellData;
        m_PointSetSeries[0]->GetCellData(cellId, &cellData);
        cellData.closed = false;;
        m_PointSetSeries[0]->SetCellData(cellId, cellData);
      }
    }
    break;

  case OpADDLINE:
    // inserts the ID of the selected point into the indexes of lines in the
    // selected cell afterwars the added line is selected
    {
      mitk::LineOperation *lineOp =
        dynamic_cast<mitk::LineOperation *>(operation);

      int cellId = -1;
      int pId = -1;

      if (lineOp == nullptr)
      {
        cellId = this->SearchSelectedCell( 0 );
        if (cellId == -1)
          return;

        pId = this->SearchSelectedPoint( 0 );
        if (pId == -1)
          return;
      }
      else
      {
        cellId = lineOp->GetCellId();
        if (cellId == -1)
          return;
        pId = lineOp->GetPIdA();
        if (pId == -1)
          return;
      }

      bool ok;
      CellAutoPointer cellAutoPointer;
      ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellType * cell = cellAutoPointer.GetPointer();
        if( cell->GetType() == CellType::POLYGON_CELL )
        {
          PolygonType * polygon = static_cast<PolygonType *>( cell );
          // add the pointId to the Cell. filling the empty cell with
          // one id doesn't mean to add a line, it means, that the
          // initilal PointId is set. The next addition of a pointId adds
          // a line
          polygon->AddPointId(pId);

          // select the line, if we really added a line, so now have more than
          // 1 pointID in the cell
          CellDataType cellData;
          ok = m_PointSetSeries[0]->GetCellData(cellId, &cellData);
          if (ok)
          {
            // A line between point 0 and 1 has the Id 0. A line between
            // 1 and 2 has a Id = 1. So we add getnumberofpoints-2.
            if (polygon->GetNumberOfPoints()>1)
              cellData.selectedLines.push_back(polygon->GetNumberOfPoints()-2);
          }
          m_PointSetSeries[0]->SetCellData(cellId, cellData);
          m_PointSetSeries[0]->SetCell(cellId, cellAutoPointer);
        }
      }
    }
    break;

  case OpDELETELINE:
    {
      // deleted the last line through removing the index PIdA
      // (if set to -1, use the last point) in the given cellId
      mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
      int cellId = -1;
      int pId = -1;

      if (lineOp == nullptr)
      {
        cellId = this->SearchSelectedCell( 0 );
        if (cellId == -1)
          return;
        pId = this->SearchSelectedPoint( 0 );
      }
      else
      {
        cellId = lineOp->GetCellId();
        if (cellId == -1)
          return;
        pId = lineOp->GetPIdA();
      }

      bool ok;
      CellAutoPointer cellAutoPointer;
      ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellType * cell = cellAutoPointer.GetPointer();
        if( cell->GetType() == CellType::POLYGON_CELL )
        {
          PolygonType * oldPolygon = static_cast<PolygonType *>( cell );

          auto   newPolygonCell = new PolygonType;
          CellAutoPointer newCell;
          newCell.TakeOwnership( newPolygonCell );

          PointIdConstIterator it, oldend;
          oldend = oldPolygon->PointIdsEnd();
          if(pId >= 0)
          {
            for(it = oldPolygon->PointIdsBegin(); it != oldend; ++it)
            {
              if((*it) != (MeshType::PointIdentifier)pId)
              {
                newPolygonCell->AddPointId(*it);
              }
            }
          }
          else
          {
            --oldend;
            for(it = oldPolygon->PointIdsBegin(); it != oldend; ++it)
              newPolygonCell->AddPointId(*it);
          }
          oldPolygon->SetPointIds(0, newPolygonCell->GetNumberOfPoints(),
            newPolygonCell->PointIdsBegin());
        }
      }
    }
    break;

  case OpREMOVELINE:
    //Remove the given Index in the given cell through copying everything
    // into a new cell accept the one that has to be deleted.
    {
      mitk::LineOperation *lineOp =
        dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
      {
        Superclass::ExecuteOperation(operation);
      }

      bool ok;
      CellAutoPointer cellAutoPointer;
      int cellId = lineOp->GetCellId();
      ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (!ok)
        return;

      CellType * cell = cellAutoPointer.GetPointer();
      CellAutoPointer newCellAutoPointer;
      newCellAutoPointer.TakeOwnership( new PolygonType );
      PolygonType * newPolygon = static_cast<PolygonType *>( cell );

      PointIdIterator it = cell->PointIdsBegin();
      PointIdIterator end = cell->PointIdsEnd();
      int pointId = lineOp->GetPIdA();
      if (pointId<0)//if not initialized!!
        return;

      while (it!=end)
      {
        if ((*it)==(unsigned int)pointId)
        {
          break;
        }
        else
        {
          newPolygon ->AddPointId(*it);
        }
        ++it;
      }
      while (it!=end)
      {
        newPolygon ->AddPointId(*it);
        it++;
      }
      m_PointSetSeries[0]->SetCell(cellId, newCellAutoPointer);
    }
    break;

  case OpINSERTLINE:
    //  //insert line between two other points.
    ////before A--B   after  A--C--B
    //  //the points A, B and C have to be in the pointset.
    //  //needed: CellId, Id of C , Id A and Id B
    ////the cell has to exist!
    //{
    //mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
    //  if (lineOp == NULL)//if no lineoperation, then call superclass pointSet
    // {
    //    Superclass::ExecuteOperation(operation);
    //  }
    //    int cellId = lineOp->GetCellId();
    //    int pIdC = lineOp->GetPIdC();
    //  int pIdA = lineOp->GetPIdA();
    //    int pIdB = lineOp->GetPIdB();

    //    //the points of the given PointIds have to exist in the PointSet
    //    bool ok;
    //    ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdA);
    //    if (!ok)
    //      return;
    //    ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdB);
    //    if (!ok)
    //      return;
    //  ok = m_PointSetSeries[0]->GetPoints()->IndexExists(pIdC);
    //    if (!ok)
    //      return;

    //    // so the points do exist. So now check, if there is already a cell
    //    // with the given Id
    //    DataType::CellAutoPointer cell;
    //    ok = m_PointSetSeries[0]->GetCell(cellId, cell);
    //  if (!ok)
    //    return;

    //  //pIdA and pIdB should exist in the cell
    //
    //  PointIdIterator pit = cell->PointIdsBegin();
    //    PointIdIterator end = cell->PointIdsEnd();
    //
    //  //now arrange the new Ids in the cell like desired; pIdC between
    //  // pIdA and pIdB
    //  unsigned int nuPoints = cell->GetNumberOfPoints();

    //  std::vector<unsigned int> newPoints;
    //  pit = cell->PointIdsBegin();
    //    end = cell->PointIdsEnd();
    //    int i = 0;
    //    while( pit != end )
    //    {
    //      if ((*pit) = pIdA)
    //      {
    //        //now we have found the place to add pIdC after
    //        newPoints[i] = (*pit);
    //        i++;
    //        newPoints[i] = pIdC;
    //      }
    //      else
    //        newPoints[i] = (*pit);
    //      pit++;
    //    }

    //  //now we have the Ids, that existed before combined with the new ones
    //  //so delete the old cell
    //  //doesn't seem to be necessary!
    //  //cell->ClearPoints();
    //  pit = cell->PointIdsBegin();
    //  cell->SetPointIds(pit);
    //}
    break;

  case OpMOVELINE://(moves two points)
    {
      mitk::LineOperation *lineOp =
        dynamic_cast<mitk::LineOperation *>(operation);

      if (lineOp == nullptr)
      {
        mitk::StatusBar::GetInstance()->DisplayText(
          "Message from mitkMesh: Recieved wrong type of operation! See mitkMeshInteractor.cpp", 10000);
        return;
      }

      //create two operations out of the one operation and call superclass
      //through the transmitted pointIds get the koordinates of the points.
      //then add the transmitted vestor to them
      //create two operations and send them to superclass
      Point3D pointA, pointB;
      pointA.Fill(0.0);
      pointB.Fill(0.0);
      m_PointSetSeries[0]->GetPoint(lineOp->GetPIdA(), &pointA);
      m_PointSetSeries[0]->GetPoint(lineOp->GetPIdB(), &pointB);

      pointA[0] += lineOp->GetVector()[0];
      pointA[1] += lineOp->GetVector()[1];
      pointA[2] += lineOp->GetVector()[2];
      pointB[0] += lineOp->GetVector()[0];
      pointB[1] += lineOp->GetVector()[1];
      pointB[2] += lineOp->GetVector()[2];

      auto   operationA =
        new mitk::PointOperation(OpMOVE, pointA, lineOp->GetPIdA());
      auto   operationB =
        new mitk::PointOperation(OpMOVE, pointB, lineOp->GetPIdB());

      Superclass::ExecuteOperation(operationA);
      Superclass::ExecuteOperation(operationB);
    }
    break;

  case OpSELECTLINE://(select the given line)
    {
      mitk::LineOperation *lineOp =
        dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
      {
        Superclass::ExecuteOperation(operation);
      }
      int cellId = lineOp->GetCellId();
      CellAutoPointer cellAutoPointer;
      bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellDataType cellData;
        m_PointSetSeries[0]->GetCellData(cellId, &cellData);
        SelectedLinesType *selectedLines = &(cellData.selectedLines);
        auto position = std::find(selectedLines->begin(),
          selectedLines->end(), (unsigned int) lineOp->GetId());

        if (position == selectedLines->end())//if not alsready selected
        {
          cellData.selectedLines.push_back(lineOp->GetId());
        }
        m_PointSetSeries[0]->SetCellData(lineOp->GetCellId(), cellData);
      }
    }
    break;

  case OpDESELECTLINE://(deselect the given line)
    {
      mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)
      {
        Superclass::ExecuteOperation(operation);
      }
      int cellId = lineOp->GetCellId();
      CellAutoPointer cellAutoPointer;
      bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellDataType cellData;
        m_PointSetSeries[0]->GetCellData(cellId, &cellData);
        SelectedLinesType *selectedLines = &(cellData.selectedLines);
        auto position = std::find(selectedLines->begin(),
          selectedLines->end(), (unsigned int) lineOp->GetId());

        if (position != selectedLines->end())//if found
        {
          selectedLines->erase(position);
        }
        m_PointSetSeries[0]->SetCellData(cellId, cellData);
      }
    }
    break;

  case OpSELECTCELL://(select the given cell)
    {
      mitk::LineOperation *lineOp =
        dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
      {
        Superclass::ExecuteOperation(operation);
      }

      int cellId = lineOp->GetCellId();
      CellAutoPointer cellAutoPointer;

      //directly get the data!//TODO
      bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellDataType cellData;
        m_PointSetSeries[0]->GetCellData(cellId, &cellData);
        cellData.selected = true;
        m_PointSetSeries[0]->SetCellData(cellId, cellData);
      }
    }
    break;

  case OpDESELECTCELL://(deselect the given cell)
    {
      mitk::LineOperation *lineOp = dynamic_cast<mitk::LineOperation *>(operation);
      if (lineOp == nullptr)//if no lineoperation, then call superclass pointSet
      {
        Superclass::ExecuteOperation(operation);
      }
      int cellId = lineOp->GetCellId();
      CellAutoPointer cellAutoPointer;
      bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (ok)
      {
        CellDataType cellData;
        m_PointSetSeries[0]->GetCellData(cellId, &cellData);
        cellData.selected = false;
        m_PointSetSeries[0]->SetCellData(cellId, cellData);
      }
    }
    break;

  case OpMOVECELL:
    //moves all Points of one cell according to the given vector
    {
      mitk::CellOperation *lineOp = dynamic_cast<mitk::CellOperation *>(operation);
      if (lineOp == nullptr)//if no celloperation, then call superclass pointSet
      {
        Superclass::ExecuteOperation(operation);
      }

      int cellId = lineOp->GetCellId();
      Vector3D vector = lineOp->GetVector();

      //get the cell
      CellAutoPointer cellAutoPointer;
      bool ok = m_PointSetSeries[0]->GetCell(cellId, cellAutoPointer);
      if (!ok)
        return;

      CellDataType cellData;
      m_PointSetSeries[0]->GetCellData(cellId, &cellData);
      // iterate through the pointIds of the CellData and move those points in
      // the pointset
      PointIdIterator it = cellAutoPointer->PointIdsBegin();
      PointIdIterator end = cellAutoPointer->PointIdsEnd();
      while(it != end)
      {
        unsigned int position = (*it);
        PointType point;
        point.Fill(0);
        m_PointSetSeries[0]->GetPoint(position, &point);
        point = point + vector;
        m_PointSetSeries[0]->SetPoint(position, point);
        ++it;
      }

    }
    break;

  default:
    //if the operation couldn't be handled here, then send it to superclass
    Superclass::ExecuteOperation(operation);
    return;
  }
  //to tell the mappers, that the data is modifierd and has to be updated
  this->Modified();

  mitk::OperationEndEvent endevent(operation);
  ((const itk::Object*)this)->InvokeEvent(endevent);

  // As discussed lately, don't mess with rendering from inside data structures
  //*todo has to be done here, cause of update-pipeline not working yet
  //mitk::RenderingManager::GetInstance()->RequestUpdateAll();

}
Exemplo n.º 12
0
int PatchDeformPW::fnGetNumberOfPoints(INode *node)
{
	return GetNumberOfPoints(node);
}
Exemplo n.º 13
0
    vtkErrorMacro(<<"No data to glyph!");
    return 1;
    }

  pts = new vtkIdType[source->GetMaxCellSize()];
  trans = vtkTransform::New();
  matrix = vtkMatrix4x4::New();
  
  inOrigNodes = pd->GetArray("avtOriginalNodeNumbers");
  inOrigCells = pd->GetArray("avtOriginalCellNumbers");

  //
  // Allocate storage for output PolyData
  //
  sourcePts = source->GetPoints();
  numSourcePts = sourcePts->GetNumberOfPoints();
  numSourceCells = source->GetNumberOfCells();

  newPts = vtkPoints::New();
  newPts->Allocate(numDirs*numPts*numSourcePts);

  // Setting up for calls to PolyData::InsertNextCell()
  if ( (sourceCells=source->GetVerts())->GetNumberOfCells() > 0 )
    {
    cells = vtkCellArray::New();
    cells->Allocate(numDirs*numPts*sourceCells->GetSize());
    output->SetVerts(cells);
    cells->Delete();
    }
  if ( (sourceCells=this->GetSource()->GetLines())->GetNumberOfCells() > 0 )
    {
Exemplo n.º 14
0
bool sm2ccConverter::addScalarField(ccPointCloud * cloud, const std::string& name, bool overwrite_if_exist/*=true*/)
{
	assert(m_sm_cloud && cloud);
	if (!m_sm_cloud || !cloud)
		return false;

	//get the field
	PCLScalarField field = m_sm_cloud->fields.at(pcl::getFieldIndex(*m_sm_cloud, name));

	//if this field already exist, simply delete it
	int id = cloud->getScalarFieldIndexByName(name.c_str());
	if (id >= 0)
	{
		if (overwrite_if_exist)
			cloud->deleteScalarField(id);
		else
			return false;
	}

	size_t pointCount = GetNumberOfPoints(m_sm_cloud);

	//create new scalar field
	ccScalarField* cc_scalar_field = new ccScalarField(name.c_str());
	if (!cc_scalar_field->reserve((unsigned)pointCount))
	{
		cc_scalar_field->release();
		return false;
	}

	//get PCL field
	PCLScalarField pclField = m_sm_cloud->fields.at(pcl::getFieldIndex(*m_sm_cloud, name));

	//check if int or float
	bool floatField = (pclField.datatype == PCLScalarField::FLOAT32 || pclField.datatype == PCLScalarField::FLOAT64);

	//temporary change the name of the given field to something else -> S5c4laR should be a pretty uncommon name,
	int field_index = pcl::getFieldIndex(*m_sm_cloud, name);
	m_sm_cloud->fields[field_index].name = std::string("S5c4laR");

	if (floatField)
	{
		pcl::PointCloud<FloatScalar>::Ptr pcl_scalar(new pcl::PointCloud<FloatScalar>);
		FROM_PCL_CLOUD(*m_sm_cloud, *pcl_scalar);

		for (size_t i = 0; i < pointCount; ++i)
		{
			ScalarType scalar = (ScalarType)pcl_scalar->points[i].S5c4laR;
			cc_scalar_field->addElement(scalar);
		}
	}
	else
	{
		pcl::PointCloud<IntScalar>::Ptr pcl_scalar(new pcl::PointCloud<IntScalar>);
		FROM_PCL_CLOUD(*m_sm_cloud, *pcl_scalar);

		for (size_t i = 0; i < pointCount; ++i)
		{
			ScalarType scalar = (ScalarType)pcl_scalar->points[i].S5c4laR;
			cc_scalar_field->addElement(scalar);
		}
	}

	cc_scalar_field->computeMinAndMax();
	cloud->addScalarField(cc_scalar_field);
	cloud->setCurrentDisplayedScalarField(0);
	cloud->showSF(true);

	//restore old name for the scalar field
	m_sm_cloud->fields[field_index].name = name;

	return true;
}
Exemplo n.º 15
0
/**
Create the vtkStructuredGrid from the provided workspace
@param progressUpdating: Reporting object to pass progress information up the
stack.
@return fully constructed vtkDataSet.
*/
vtkSmartPointer<vtkDataSet>
vtkMDHistoLineFactory::create(ProgressAction &progressUpdating) const {
  auto product =
      tryDelegatingCreation<MDHistoWorkspace, 1>(m_workspace, progressUpdating);
  if (product != nullptr) {
    return product;
  } else {
    g_log.warning() << "Factory " << this->getFactoryTypeName()
                    << " is being used. You are viewing data with less than "
                       "three dimensions in the VSI. \n";

    Mantid::Kernel::ReadLock lock(*m_workspace);
    const int nBinsX =
        static_cast<int>(m_workspace->getXDimension()->getNBins());

    const coord_t minX = m_workspace->getXDimension()->getMinimum();

    coord_t incrementX = m_workspace->getXDimension()->getBinWidth();

    const int imageSize = nBinsX;
    vtkNew<vtkPoints> points;
    points->Allocate(static_cast<int>(imageSize));

    vtkNew<vtkFloatArray> signal;
    signal->Allocate(imageSize);
    signal->SetName(vtkDataSetFactory::ScalarName.c_str());
    signal->SetNumberOfComponents(1);

    UnstructuredPoint unstructPoint;
    const int nPointsX = nBinsX;
    Column column(nPointsX);

    NullCoordTransform transform;
    // Mantid::API::CoordTransform* transform =
    // m_workspace->getTransformFromOriginal();
    Mantid::coord_t in[3];
    Mantid::coord_t out[3];

    double progressFactor = 0.5 / double(nBinsX);
    double progressOffset = 0.5;

    // Loop through dimensions
    for (int i = 0; i < nPointsX; i++) {
      progressUpdating.eventRaised(progressFactor * double(i));
      in[0] = minX +
              static_cast<coord_t>(i) * incrementX; // Calculate increment in x;

      float signalScalar =
          static_cast<float>(m_workspace->getSignalNormalizedAt(i));

      if (!std::isfinite(signalScalar)) {
        // Flagged so that topological and scalar data is not applied.
        unstructPoint.isSparse = true;
      } else {
        if (i < (nBinsX - 1)) {
          signal->InsertNextValue(static_cast<float>(signalScalar));
        }
        unstructPoint.isSparse = false;
      }

      transform.apply(in, out);

      unstructPoint.pointId = points->InsertNextPoint(out);
      column[i] = unstructPoint;
    }

    points->Squeeze();
    signal->Squeeze();

    auto visualDataSet = vtkSmartPointer<vtkUnstructuredGrid>::New();
    visualDataSet->Allocate(imageSize);
    visualDataSet->SetPoints(points.GetPointer());
    visualDataSet->GetCellData()->SetScalars(signal.GetPointer());

    for (int i = 0; i < nBinsX - 1; i++) {
      progressUpdating.eventRaised((progressFactor * double(i)) +
                                   progressOffset);
      // Only create topologies for those cells which are not sparse.
      if (!column[i].isSparse) {
        vtkLine *line = vtkLine::New();
        line->GetPointIds()->SetId(0, column[i].pointId);
        line->GetPointIds()->SetId(1, column[i + 1].pointId);
        visualDataSet->InsertNextCell(VTK_LINE, line->GetPointIds());
      }
    }

    visualDataSet->Squeeze();

    // Hedge against empty data sets
    if (visualDataSet->GetNumberOfPoints() <= 0) {
      vtkNullUnstructuredGrid nullGrid;
      visualDataSet = nullGrid.createNullData();
    }

    vtkSmartPointer<vtkDataSet> dataset = visualDataSet;
    return dataset;
  }
}