Example #1
0
    std::tuple<vtkSmartPointer<vtkPolyData>, vtkSmartPointer<vtkCellArray>, vtkSmartPointer<vtkFloatArray>> genvtkPolyData()
    {
        auto points = vtkSmartPointer<vtkPoints>::New();
        points->InsertNextPoint(0, 0, 0);
        points->InsertNextPoint(0, 1, 0);
        points->InsertNextPoint(1, 1, 0);

        auto poly = vtkSmartPointer<vtkPolyData>::New();
        poly->SetPoints(points);

        auto indices = vtkSmartPointer<vtkCellArray>::New();
        indices->InsertNextCell(3);
        indices->InsertCellPoint(0);
        indices->InsertCellPoint(1);
        indices->InsertCellPoint(2);

        auto vectors = vtkSmartPointer<vtkFloatArray>::New();
        vectors->SetName(vectorName());
        vectors->SetNumberOfComponents(3);
        vectors->SetNumberOfTuples(1);
        vectors->SetTypedComponent(0, 0, 0);
        vectors->SetTypedComponent(0, 1, 0);
        vectors->SetTypedComponent(0, 2, 1);

        return { poly, indices, vectors };
    }
PointsIdMapPair get_vtk_points_from_graph(const GraphType &sg) {
  using vertex_descriptor = boost::graph_traits<GraphType>::vertex_descriptor;
  using vertex_iterator = boost::graph_traits<GraphType>::vertex_iterator;
  using edge_iterator = boost::graph_traits<GraphType>::edge_iterator;
  auto points = vtkSmartPointer<vtkPoints>::New();

  std::unordered_map<vtkIdType, std::vector<graph_descriptor>> idMap;
  vertex_iterator vi, vi_end;
  std::tie(vi, vi_end) = boost::vertices(sg);
  for(; vi != vi_end; ++vi) {
    auto id =
        points->InsertNextPoint(sg[*vi].pos[0], sg[*vi].pos[1], sg[*vi].pos[2]);
    graph_descriptor gdesc;
    gdesc.exist = true;
    gdesc.is_vertex = true;
    gdesc.vertex_d = *vi;
    std::vector<graph_descriptor> gdescs;
    gdescs.push_back(gdesc);
    idMap[id] = gdescs;
  }

  edge_iterator ei, ei_end;
  std::tie(ei, ei_end) = boost::edges(sg);
  for(; ei != ei_end; ++ei) {
    auto &sg_edge = sg[*ei];
    auto &sg_edge_points = sg_edge.edge_points;
    for(size_t index = 0; index < sg_edge_points.size(); ++index) {
      const auto &p = sg_edge_points[index];
      auto id = points->InsertNextPoint(p[0], p[1], p[2]);
      graph_descriptor gdesc;
      gdesc.exist = true;
      gdesc.is_edge = true;
      gdesc.edge_d = *ei;
      gdesc.edge_points_index = index;
      std::vector<graph_descriptor> gdescs;
      gdescs.push_back(gdesc);
      idMap[id] = gdescs;
    }
  }
#ifndef NDEBUG
  std::set<PointType> repeated_points;
  bool repeated_exists;
  std::tie(repeated_points, repeated_exists) = check_unique_points_in_graph(sg);
  if(repeated_exists) {
    std::cout
        << "Warning: duplicated points exist in get_vtk_points_from_graph."
           "Repeated Points: "
        << repeated_points.size() << std::endl;
    for(const auto &p : repeated_points) {
      SG::print_pos(std::cout, p);
      std::cout << std::endl;
    }
  }
  // assert(duplicated_points_exist == false);
#endif

  return std::make_pair(points, idMap);
};
Example #3
0
    static vtkSmartPointer<vtkPolyData> genPolyDataSet()
    {
        auto poly = vtkSmartPointer<vtkPolyData>::New();
        auto points = vtkSmartPointer<vtkPoints>::New();

        points->InsertNextPoint(0, 0, 0);
        points->InsertNextPoint(0, 1, 0);
        points->InsertNextPoint(1, 1, 0);
        poly->SetPoints(points);
        std::array<vtkIdType, 3> pointIds = { 0, 1, 2 };
        poly->Allocate(static_cast<vtkIdType>(pointIds.size()));
        poly->InsertNextCell(VTK_TRIANGLE, static_cast<int>(pointIds.size()), pointIds.data());

        return poly;
    }
Example #4
0
void iARenderer::emitSelectedCells(vtkUnstructuredGrid* selectedCells)
{
	double cell[DIM] = { 0,0,0 };
	double* spacing = getRenderObserver()->GetImageData()->GetSpacing();
	auto selCellPoints = vtkSmartPointer<vtkPoints>::New();
	for (vtkIdType i = 0; i < selectedCells->GetNumberOfCells(); ++i)
	{
		GetCellCenter(selectedCells, i, cell, spacing);
		selCellPoints->InsertNextPoint(cell);
	}
	emit cellsSelected(selCellPoints);
}
Example #5
0
ProcessExecutor::ProcessExecutor(
        const State::AddressAccessor& addr,
        const std::vector<State::vec3f>& spline,
        const Device::DeviceList& devices,
        State::vec3f scale,
        State::vec3f origin,
        bool deriv):
    m_spline{vtkParametricSpline::New()},
    m_scale{scale},
    m_origin{origin},
    m_message{make_message(addr, devices)},
    m_use_deriv{deriv}
{
    // Load the spline
    auto points = vtkPoints::New();
    for(const State::vec3f& pt : spline)
    {
        points->InsertNextPoint(pt[0], pt[1], pt[2]);
    }
    m_spline->SetPoints(points);
}
Example #6
0
    TestVtkMeshConverter()
        : vtu(nullptr)
    {
        // Points and cells
        auto points = vtkSmartPointer<vtkPoints>::New();
        points->InsertNextPoint(703.875, 758.75, 0.9971);
        points->InsertNextPoint(767.625, 679.5, 6.2356);
        points->InsertNextPoint(835.25, 602.50, 11.2227);
        points->InsertNextPoint(608.75, 629.375, 10.3723);
        points->InsertNextPoint(672, 549.375, 17.4011);
        points->InsertNextPoint(739.75, 472.5, 20.9258);
        points->InsertNextPoint(703.875, 758.75, 101.07145);
        points->InsertNextPoint(767.625, 679.5, 106.2616);
        points->InsertNextPoint(835.25, 602.5, 111.2233);
        points->InsertNextPoint(608.75, 629.375, 110.4138);
        points->InsertNextPoint(672, 549.375, 117.4165);
        points->InsertNextPoint(739.75, 472.5, 120.92995);

        auto cells = vtkSmartPointer<vtkCellArray>::New();
        auto cell1 = vtkSmartPointer<vtkIdList>::New();
        cell1->InsertNextId(4);
        cell1->InsertNextId(1);
        cell1->InsertNextId(0);
        cell1->InsertNextId(3);
        cell1->InsertNextId(10);
        cell1->InsertNextId(7);
        cell1->InsertNextId(6);
        cell1->InsertNextId(9);
        auto cell2 = vtkSmartPointer<vtkIdList>::New();
        cell2->InsertNextId(5);
        cell2->InsertNextId(2);
        cell2->InsertNextId(1);
        cell2->InsertNextId(4);
        cell2->InsertNextId(11);
        cell2->InsertNextId(8);
        cell2->InsertNextId(7);
        cell2->InsertNextId(10);
        cells->InsertNextCell(cell1);
        cells->InsertNextCell(cell2);

        vtu = vtkSmartPointer<vtkUnstructuredGrid>::New();
        vtu->SetPoints(points);
        vtu->SetCells(12, cells);

        // Data arrays
        auto pointIds = vtkSmartPointer<vtkIntArray>::New();
        pointIds->SetNumberOfComponents(1);
        pointIds->SetName("PointIDs");
        for (int i = 0; i < 12; ++i)
            pointIds->InsertNextTuple1(i);
        vtu->GetPointData()->AddArray(pointIds);

        auto materialIds = vtkSmartPointer<vtkUnsignedIntArray>::New();
        materialIds->SetNumberOfComponents(1);
        materialIds->SetName("MaterialIDs");
        materialIds->InsertNextTuple1(0);
        materialIds->InsertNextTuple1(1);
        vtu->GetCellData()->AddArray(materialIds);
    }