Beispiel #1
0
vtkSmartPointer<vtkArrayType> FlowAnalysis::vtkMakeArray(const vtkSmartPointer<vtkUniformGrid>& grid, const string& name, size_t numComponents, bool fillZero){
	auto arr=vtkSmartPointer<vtkArrayType>::New();
	arr->SetNumberOfComponents(numComponents);
	arr->SetNumberOfTuples(boxCells.prod());
	arr->SetName(name.c_str());
	if(cellData) grid->GetCellData()->AddArray(arr);
	else grid->GetPointData()->AddArray(arr);
	if(fillZero){ for(int _i=0; _i<(int)numComponents; _i++) arr->FillComponent(_i,0.); }
	return arr;
}
void CDialog_init::moveFemur()// old version , not used
{
	 int temp_Px;
     temp_Px=m_Px.GetPos()-m_Px_local;
     m_Px_local=m_Px.GetPos();
	 int temp_Py;
     temp_Py=m_Py.GetPos()-m_Py_local;
     m_Py_local=m_Py.GetPos();
	 int temp_Pz;
     temp_Pz=m_Pz.GetPos()-m_Pz_local;
     m_Pz_local=m_Pz.GetPos();
	 int temp_Rx;
     temp_Rx=m_Rx.GetPos()-m_Rx_local;
     m_Rx_local=m_Rx.GetPos();
	 int temp_Ry;
     temp_Ry=m_Ry.GetPos()-m_Ry_local;
     m_Ry_local=m_Ry.GetPos();
	 int temp_Rz;
     temp_Rz=m_Rz.GetPos()-m_Rz_local;
     m_Rz_local=m_Rz.GetPos();

	 translation->Translate(temp_Px,temp_Py,temp_Pz);
	 translation->RotateX(temp_Rx);
	 translation->RotateY(temp_Ry);
	 translation->RotateZ(temp_Rz);
     transformFilter->SetTransform(translation);
     transformFilter->Update();
	 renderWindow->GetInteractor()->Render();
	 renderWindow2->GetInteractor()->Render();
	 renderWindow3->GetInteractor()->Render();
}
    bool
    operator ()(PopulationSPtr pop)
    {
        ++num_gens;
//        bool return_val = metric(pop);

        vtkIdType row_num = table->InsertNextBlankRow();
        table->SetValue(row_num, 0, num_gens);
        table->SetValue(row_num, 1, metric->getVal());

        if (table->GetNumberOfRows() > 2)
        {
            // Start interactor
            chart->ClearPlots();
            vtkPlot *line = chart->AddPlot(vtkChart::LINE);
#if VTK_MAJOR_VERSION <= 5
            line->SetInput(table, 0, 1);
#else
            line->SetInputData(table, 0, 1);
#endif
            line->SetColor(0, 255, 0, 255);
            line->SetWidth(1.0);
//            view->Render();
            //Finally render the scene
            view->GetRenderWindow()->SetMultiSamples(0);
            view->GetInteractor()->Initialize();
            view->GetInteractor()->Render();
        }
//        view->GetInteractor()->Initialize();

        return true;
    }
Beispiel #4
0
std::vector<std::string> GetColumsWithString( std::string colName, vtkSmartPointer<vtkTable> table ){
	std::vector<std::string> retVect;
	for( int i=0; i<table->GetNumberOfColumns(); ++i ){
		std::string current_column;
		current_column = table->GetColumnName(i);
		if( current_column.find(colName.c_str()) != std::string::npos ){
			retVect.push_back( current_column );
		}
	}
	return retVect;	
}
Beispiel #5
0
void FieldDataVisualizer::setActiveEdgeActor(vtkSmartPointer<vtkActor>& _edgeActor) {
	//Edge vis
	vtkSmartPointer<vtkExtractEdges> edgeExtractorTemp = vtkExtractEdges::New();
	edgeExtractorTemp->SetInputData(warpFilter->GetUnstructuredGridOutput());
	vtkSmartPointer<vtkPolyDataMapper> edgeMapperTemp = vtkPolyDataMapper::New();
	edgeMapperTemp->SetInputConnection(edgeExtractorTemp->GetOutputPort());
	_edgeActor->SetMapper(edgeMapperTemp);
	_edgeActor->GetProperty()->SetColor(0., 0., 0.);
	_edgeActor->GetProperty()->SetLineWidth(3);
	edgeMapperTemp->ScalarVisibilityOff();
}
Beispiel #6
0
 void write(data_set_type &data_set, double time, bool set_number = true, bool print = true)
 {
     m_writer->SetInput(data_set);
     std::string file_name = m_data_path;
     if(set_number) file_name += "_" + detail::file_number(m_file_counter++, 10);
     file_name += ".";
     file_name += m_writer->GetDefaultFileExtension();
     m_writer->SetFileName(file_name.c_str());
     if (print) std::cout << "Saving " << file_name << " ... ";
     m_writer->WriteNextTime(time);
     if (print) std::cout << "done." << std::endl;
 }
Beispiel #7
0
 VtkWriter(const std::string &data_path, bool write_binary = true) :
         m_file_counter(0),
         m_data_path(data_path),
         m_writer(vtkSmartPointer<vtk_writer_type>::New()),
         m_write_binary(write_binary)
 {
     vtksys::SystemTools::MakeDirectory(data_path.c_str());
     if (m_write_binary)
         m_writer->SetDataModeToBinary();
     else
         m_writer->SetDataModeToAscii();
 }
Beispiel #8
0
void FieldDataVisualizer::setActiveHueLut(vtkSmartPointer<vtkLookupTable>& _hueLut) {
	double scalarRange[2];
	myHMeshToVtkUnstructuredGrid->getVtkUnstructuredGrid()->GetPointData()->GetScalars()->GetRange(scalarRange);
	mySelectedMapper->UseLookupTableScalarRangeOn();
	// Create a lookup table to share between the mapper and the scalarbar
	_hueLut->SetTableRange(scalarRange[0], scalarRange[1]);
	_hueLut->SetHueRange(0.667, 0.0);
	_hueLut->SetValueRange(1, 1);
	_hueLut->Build();

	mySelectedMapper->SetLookupTable(_hueLut);
}
//Update the features in this table whose names match (sets doFeat)
void AssociativeFeatureCalculator::Append(vtkSmartPointer<vtkTable> table)
{
	//Compute features:
	ftk::NuclearAssociationRules *assoc;
	if( inputs_set ){
		assoc = new ftk::NuclearAssociationRules("",0,lab_im, inp_im);
		assoc->AddAssociation( input_association->GetRuleName(), "", input_association->GetOutDistance(), input_association->GetInDistance(),	input_association->IsUseWholeObject(), input_association->IsUseBackgroundSubtraction(), input_association->IsUseMultiLevelThresholding(), input_association->GetNumberOfThresholds(), input_association->GetNumberIncludedInForeground(), input_association->GetAssocType(), input_association->get_path() );
	}
	else{
		assoc = new ftk::NuclearAssociationRules("",0);
		assoc->ReadRulesFromXML(inFilename);
	}
	assoc->PrintSelf();
	assoc->Compute();	

	//Init the table (headers):
	for (int i=0; i < assoc->GetNumofAssocRules(); ++i)
	{
		vtkSmartPointer<vtkDoubleArray> column = vtkSmartPointer<vtkDoubleArray>::New();
		column->SetName( (fPrefix+assoc->GetAssociationRules().at(i).GetRuleName()).c_str() );
		column->SetNumberOfValues( table->GetNumberOfRows() );
		table->AddColumn(column);
	}

	//Now update the table:
	std::vector<unsigned short> labels = assoc->GetLabels();
	float** vals = assoc->GetAssocFeaturesList();
	//#pragma omp parallel for num_threads(4)
	for (int i=0; i<(int)labels.size(); ++i)
	{
		unsigned short id = labels.at(i);
		if(id == 0) continue;

		int row = -1;
		for(int r=0; r<table->GetNumberOfRows(); ++r)
		{
			if( table->GetValue(r,0) == id )
			{
				row = r;
				break;
			}
		}

		if(row == -1) continue;

		for (int f=0; f<assoc->GetNumofAssocRules(); ++f)
		{
			table->SetValueByName(row,(fPrefix+assoc->GetAssociationRules().at(f).GetRuleName()).c_str(), vtkVariant(vals[f][i]));
		}
	}
	delete assoc;
}
Beispiel #10
0
void cv::viz::vtkImageMatSource::copyGrayImage(const Mat &source, vtkSmartPointer<vtkImageData> output)
{
    unsigned char* dptr = reinterpret_cast<unsigned char*>(output->GetScalarPointer());
    size_t elem_step = output->GetIncrements()[1]/sizeof(unsigned char);

    for (int y = 0; y < source.rows; ++y)
    {
        unsigned char* drow = dptr + elem_step * y;
        const unsigned char *srow = source.ptr<unsigned char>(y);
        for (int x = 0; x < source.cols; ++x)
            drow[x] = *srow++;
    }
}
Beispiel #11
0
void cv::viz::vtkImageMatSource::copyRGBAImage(const Mat &source, vtkSmartPointer<vtkImageData> output)
{
    Vec4b* dptr = reinterpret_cast<Vec4b*>(output->GetScalarPointer());
    size_t elem_step = output->GetIncrements()[1]/sizeof(Vec4b);

    for (int y = 0; y < source.rows; ++y)
    {
        Vec4b* drow = dptr + elem_step * y;
        const unsigned char *srow = source.ptr<unsigned char>(y);
        for (int x = 0; x < source.cols; ++x, srow += source.channels())
            drow[x] = Vec4b(srow[2], srow[1], srow[0], srow[3]);
    }
}
Beispiel #12
0
vtkSmartPointer<vtkTable> AppendTables(vtkSmartPointer<vtkTable> table_initial,vtkSmartPointer<vtkTable> table_new )
{
	/*!
	* Adds on table to the end of another
	*/
  //!fill the table with values
  unsigned int counter = 0;
  for(vtkIdType r = 0; r < table_new->GetNumberOfRows() ; r++ )
    {
	  table_initial->InsertNextRow(table_new->GetRow(r));
    }

	return table_initial;
}
template <typename PointT> void 
pcl::visualization::PointCloudGeometryHandlerXYZ<PointT>::getGeometry (vtkSmartPointer<vtkPoints> &points) const
{
  if (!capable_)
    return;

  if (!points)
    points = vtkSmartPointer<vtkPoints>::New ();
  points->SetDataTypeToFloat ();

  vtkSmartPointer<vtkFloatArray> data = vtkSmartPointer<vtkFloatArray>::New ();
  data->SetNumberOfComponents (3);
  vtkIdType nr_points = cloud_->points.size ();

  // Add all points
  vtkIdType j = 0;    // true point index
  float* pts = static_cast<float*> (malloc (nr_points * 3 * sizeof (float)));

  // If the dataset has no invalid values, just copy all of them
  if (cloud_->is_dense)
  {
    for (vtkIdType i = 0; i < nr_points; ++i)
    {
      pts[i * 3 + 0] = cloud_->points[i].x;
      pts[i * 3 + 1] = cloud_->points[i].y;
      pts[i * 3 + 2] = cloud_->points[i].z;
    }
    data->SetArray (&pts[0], nr_points * 3, 0);
    points->SetData (data);
  }
  // Need to check for NaNs, Infs, ec
  else
  {
    for (vtkIdType i = 0; i < nr_points; ++i)
    {
      // Check if the point is invalid
      if (!pcl_isfinite (cloud_->points[i].x) || !pcl_isfinite (cloud_->points[i].y) || !pcl_isfinite (cloud_->points[i].z))
        continue;

      pts[j * 3 + 0] = cloud_->points[i].x;
      pts[j * 3 + 1] = cloud_->points[i].y;
      pts[j * 3 + 2] = cloud_->points[i].z;
      // Set j and increment
      j++;
    }
    data->SetArray (&pts[0], j * 3, 0);
    points->SetData (data);
  }
}
Beispiel #14
0
void CDialog_init::rotRz()
{
	 int temp_Rz;
     temp_Rz=m_Rz.GetPos()-m_Rz_local;
     m_Rz_local=m_Rz.GetPos();
	 translation->RotateZ(temp_Rz);
      
	  transformFilter->SetTransform(translation);
      transformFilter->Update();
	  renderWindow->GetInteractor()->Render();
	  GetDlgItem(IDC_STATIC_VIEW2)->RedrawWindow();
	  GetDlgItem(IDC_STATIC_VIEW3)->RedrawWindow();
	//  renderWindow2->GetInteractor()->Render();
	//  renderWindow3->GetInteractor()->Render();
}
void CDialog_subSTL::OnBnClickedButton4() //scaled
{
	vtkSmartPointer<vtkQuadricDecimation> decimate = vtkSmartPointer<vtkQuadricDecimation>::New();//scale method in VTK 
    decimate->SetInputConnection(STLReader->GetOutputPort());
    decimate->Update();
    vtkSmartPointer<vtkPolyData> decimated = vtkSmartPointer<vtkPolyData>::New();
    decimated->ShallowCopy(decimate->GetOutput());
	vtkSmartPointer<vtkSTLWriter> stlWriter = vtkSmartPointer<vtkSTLWriter>::New();
    stlWriter->SetFileName("test_saled.stl");
    stlWriter->SetInput(decimated); //stlWriter->SetInput(map->GetOutput());
    stlWriter->Write();
	MessageBox(_T("Scaled Done"));
	renderWindowInteractor_STL->GetRenderWindow()->Finalize(); // close renderwindow
	renderWindowInteractor_STL->TerminateApp();
}
Beispiel #16
0
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerRandom<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
{
  if (!capable_ || !cloud_)
    return (false);

  if (!scalars)
    scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
  scalars->SetNumberOfComponents (3);
  
  vtkIdType nr_points = cloud_->points.size ();
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);

  // Get a random color
  unsigned char* colors = new unsigned char[nr_points * 3];
  double r, g, b;
  pcl::visualization::getRandomColors (r, g, b);

  int r_ = static_cast<int> (pcl_lrint (r * 255.0)), 
      g_ = static_cast<int> (pcl_lrint (g * 255.0)), 
      b_ = static_cast<int> (pcl_lrint (b * 255.0));

  // Color every point
  for (vtkIdType cp = 0; cp < nr_points; ++cp)
  {
    colors[cp * 3 + 0] = static_cast<unsigned char> (r_);
    colors[cp * 3 + 1] = static_cast<unsigned char> (g_);
    colors[cp * 3 + 2] = static_cast<unsigned char> (b_);
  }
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE);
  return (true);
}
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerCustom<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
{
  if (!capable_ || !cloud_)
    return (false);

  if (!scalars)
    scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
  scalars->SetNumberOfComponents (3);
  
  vtkIdType nr_points = cloud_->points.size ();
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);

  // Get a random color
  unsigned char* colors = new unsigned char[nr_points * 3];

  // Color every point
  for (vtkIdType cp = 0; cp < nr_points; ++cp)
  {
    colors[cp * 3 + 0] = static_cast<unsigned char> (r_);
    colors[cp * 3 + 1] = static_cast<unsigned char> (g_);
    colors[cp * 3 + 2] = static_cast<unsigned char> (b_);
  }
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0);
  return (true);
}
void
getVoxelActors (pcl::PointCloud<pcl::PointXYZ>& voxelCenters,
                 double voxelSideLen, Eigen::Vector3f color,
                 vtkSmartPointer<vtkActorCollection> coll)
{
  vtkSmartPointer < vtkAppendPolyData > treeWireframe = vtkSmartPointer<vtkAppendPolyData>::New ();
  
  double s = voxelSideLen/2.0;
  
  for (const auto &point : voxelCenters.points)
  {
    double x = point.x;
    double y = point.y;
    double z = point.z;
    
    treeWireframe->AddInputData (getCuboid (x - s, x + s, y - s, y + s, z - s, z + s));
  }

  vtkSmartPointer < vtkLODActor > treeActor = vtkSmartPointer<vtkLODActor>::New ();
  
  vtkSmartPointer < vtkDataSetMapper > mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
  mapper->SetInputData (treeWireframe->GetOutput ());

  treeActor->SetMapper (mapper);
  
  treeActor->GetProperty ()->SetRepresentationToWireframe ();
  treeActor->GetProperty ()->SetColor (color[0], color[1], color[2]);
  treeActor->GetProperty ()->SetLineWidth (4);
  coll->AddItem (treeActor);
}
template <typename PointT> void
pcl::visualization::PointCloudColorHandlerRandom<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
{
  if (!capable_)
    return;

  if (!scalars)
    scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
  scalars->SetNumberOfComponents (3);
  
  vtkIdType nr_points = cloud_->points.size ();
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);

  // Get a random color
  unsigned char* colors = new unsigned char[nr_points * 3];
  double r, g, b;
  pcl::visualization::getRandomColors (r, g, b);

  int r_ = pcl_lrint (r * 255.0), g_ = pcl_lrint (g * 255.0), b_ = pcl_lrint (b * 255.0);

  // Color every point
  for (vtkIdType cp = 0; cp < nr_points; ++cp)
  {
    colors[cp * 3 + 0] = r_;
    colors[cp * 3 + 1] = g_;
    colors[cp * 3 + 2] = b_;
  }
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0);
}
bool
pcl::visualization::PointCloudColorHandlerRandom<pcl::PCLPointCloud2>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
{
  if (!capable_ || !cloud_)
    return (false);
  
  if (!scalars)
    scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
  scalars->SetNumberOfComponents (3);
  
  vtkIdType nr_points = cloud_->width * cloud_->height;
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
  
  // Get a random color
  unsigned char* colors = new unsigned char[nr_points * 3];
  double r, g, b;
  pcl::visualization::getRandomColors (r, g, b);
  
  long r_ = pcl_lrint (r * 255.0), g_ = pcl_lrint (g * 255.0), b_ = pcl_lrint (b * 255.0);

  // Color every point
  for (vtkIdType cp = 0; cp < nr_points; ++cp)
  {
    colors[cp * 3 + 0] = static_cast<unsigned char> (r_);
    colors[cp * 3 + 1] = static_cast<unsigned char> (g_);
    colors[cp * 3 + 2] = static_cast<unsigned char> (b_);
  }
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0);
  return (true);
}
Beispiel #21
0
///
///	Given a buffer of scalar values, compute a histogram
/// using VTK
///
vtkSmartPointer<vtkImageAccumulate>
RenderPanel::ComputeHistogram(vtkSmartPointer<vtkFloatArray> scalars,
                              int numScalars,
                              double range[2])
{
    // Compute a histogram for the curvs values
    vtkSmartPointer<vtkImageData> scalarData = vtkSmartPointer<vtkImageData>::New();
    vtkSmartPointer<vtkImageImport> scalarImport = vtkSmartPointer<vtkImageImport>::New();

    scalarImport->SetDataOrigin(0, 0, 0);
    scalarImport->SetWholeExtent(0, numScalars - 1, 0, 0, 0, 0);
    scalarImport->SetDataExtentToWholeExtent();
    scalarImport->SetDataScalarTypeToFloat();
    scalarImport->SetNumberOfScalarComponents(1);
    scalarImport->SetImportVoidPointer(scalars->GetPointer(0));

    vtkSmartPointer<vtkImageExtractComponents> extract = vtkSmartPointer<vtkImageExtractComponents>::New();
    extract->SetInputConnection( scalarImport->GetOutputPort() );
    extract->SetComponents( 0 );
    extract->Update();

    extract->GetOutput()->GetScalarRange(range);

    vtkSmartPointer<vtkImageAccumulate> histogram = vtkSmartPointer<vtkImageAccumulate>::New();
    histogram->SetInputConnection( extract->GetOutputPort() );
	histogram->SetComponentExtent( 0, 1000, 0, 0, 0, 0 );
	histogram->SetComponentOrigin( range[0],0,0 );
    histogram->SetComponentSpacing( (range[1] - range[0]) / 1000.0f, 0, 0 );
   
    histogram->Update();

    return histogram;
}
                /** \brief Obtain the actual color for the input dataset as vtk scalars.
      * \param[out] scalars the output scalars containing the color for the dataset
      * \return true if the operation was successful (the handler is capable and
      * the input cloud was given as a valid pointer), false otherwise
      */
                virtual bool
                getColor (vtkSmartPointer<vtkDataArray> &scalars) const
                {
                    if (!capable_ || !cloud_)
                        return (false);

                    if (!scalars)
                        scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
                    scalars->SetNumberOfComponents (3);

                    vtkIdType nr_points = vtkIdType (cloud_->points.size ());
                    reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
                    unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);

                    // Color every point
                    if (nr_points != int (rgb_->points.size ()))
                        std::fill (colors, colors + nr_points * 3, static_cast<unsigned char> (0xFF));
                    else
                        for (vtkIdType cp = 0; cp < nr_points; ++cp)
                        {
                            int idx = cp * 3;
                            colors[idx + 0] = rgb_->points[cp].r;
                            colors[idx + 1] = rgb_->points[cp].g;
                            colors[idx + 2] = rgb_->points[cp].b;
                        }
                    return (true);
                }
Beispiel #23
0
void vmtkRenderer::Initialize(vtkSmartPointer<vtkRenderWindow> renw)
{
	
	Renderer = vtkSmartPointer<vtkRenderer>::New();

	RenderWindow = renw;
	double *color =new double[3];
	color[0] = 0.0;
	color[1] = 0.1;
	color[2] = 0.3;
	Renderer->SetBackground(color);

	RenderWindowInteractor = renw->GetInteractor();
	
	interactorCamera = vtkSmartPointer<vtkvmtkInteractorStyleTrackballCamera>::New();

	//ÄܸıäÑÕÉ«
	//Renderer->SetBackground();

	RenderWindow->AddRenderer(Renderer);

	//RenderWindow->SetSize();

	//RenderWindow->SetPointSmoothing();

	//RenderWindow->SetLineSmoothing();
	
	//RenderWindow->SetPolygonSmoothing();
	//renw->SetSize(800,600);
	RenderWindowInteractor->SetInteractorStyle(interactorCamera);
	//RenderWindowInteractor->SetRenderWindow(renw);



}
void NonRigid::setUserTrans(vtkSmartPointer<vtkMatrix4x4> mat)
{
    if (!temp_mesh_vec.empty())
    {
        // convert vertices to eigen 4*n matrix
        Eigen::MatrixXd v_mat(4, temp_mesh_vec.size()/3);
        v_mat << Eigen::Map<Eigen::MatrixXd>(&temp_mesh_vec[0], 3, temp_mesh_vec.size()/3), Eigen::RowVectorXd::Ones(temp_mesh_vec.size()/3);

        // set transform
        Eigen::Matrix4d trans_mat;
        for (size_t i = 0; i < 4; ++i)
        {
            for (size_t j = 0; j < 4; ++j)
            {
                trans_mat(i, j) = mat->GetElement(i, j);
            }
        }

        Eigen::MatrixXd new_v_mat = trans_mat * v_mat;
        temp_mesh_vec.clear();
        for (size_t i = 0; i < new_v_mat.cols(); ++i)
        {
            temp_mesh_vec.push_back(new_v_mat(0, i)/new_v_mat(3, i));
            temp_mesh_vec.push_back(new_v_mat(1, i)/new_v_mat(3, i));
            temp_mesh_vec.push_back(new_v_mat(2, i)/new_v_mat(3, i));
        }
    }
}
Beispiel #25
0
void vtk_draw_view2(vtkSmartPointer<vtkRenderWindow> renderWindow,vtkSmartPointer<vtkRenderWindowInteractor> interactor)
{
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  renderWindow->AddRenderer(renderer);
  Renderers[1]=renderer;
  //renderer->RemoveLight( renderer->GetLights()->GetNextItem());
  vtkSmartPointer<vtkLight> light = vtkSmartPointer<vtkLight>::New();
  light->SetLightTypeToSceneLight();
  light->SetPosition(100, 100, 100);
  light->SetFocalPoint(-100,-100,-100); 
  light->SetColor(0.5,0.5,0);
  light->SetPositional(true); // required for vtkLightActor below
  renderer->AddLight(light);
  renderer->UpdateLightsGeometryToFollowCamera();
  light->SetSwitch(false);
  // light->SetConeAngle(10);
  // light->SetFocalPoint(lightFocalPoint[0], lightFocalPoint[1], lightFocalPoint[2]);
  // light->SetDiffuseColor(1,0,0);
  // light->SetAmbientColor(0,1,0);
  // light->SetSpecularColor(0,0,1);
  
  renderer->SetBackground(0.1, 0.2, 0.4);

  renderer->SetViewport(xmins[1],ymins[1],xmaxs[1],ymaxs[1]);
  
  //  m_source.m_display->draw_normal_points(renderer);
  m_source.m_display->draw_triangle(renderer,interactor);

  renderer->GetActiveCamera()->SetParallelProjection(1);
    
  renderer->ResetCamera();

  // renderWindow->Render();
}
template <typename PointT> void 
pcl::visualization::PointCloudColorHandlerRGBCloud<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
{
  if (!capable_)
    return;
  
  if (!scalars)
    scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
  scalars->SetNumberOfComponents (3);
    
  vtkIdType nr_points = vtkIdType (cloud_->points.size ());
  reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
  unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);
    
  // Color every point
  if (nr_points != int (rgb_->points.size ()))
    std::fill (colors, colors + nr_points * 3, static_cast<unsigned char> (0xFF));
  else
    for (vtkIdType cp = 0; cp < nr_points; ++cp)
    {
      int idx = cp * 3;
      colors[idx + 0] = rgb_->points[cp].r;
      colors[idx + 1] = rgb_->points[cp].g;
      colors[idx + 2] = rgb_->points[cp].b;
    }
}
Beispiel #27
0
template <typename PointT> bool
pcl::visualization::PointCloudColorHandlerGenericField<PointT>::getColor (vtkSmartPointer<vtkDataArray> &scalars) const
{
  if (!capable_ || !cloud_)
    return (false);

  if (!scalars)
    scalars = vtkSmartPointer<vtkFloatArray>::New ();
  scalars->SetNumberOfComponents (1);

  vtkIdType nr_points = cloud_->points.size ();
  reinterpret_cast<vtkFloatArray*>(&(*scalars))->SetNumberOfTuples (nr_points);

  typedef typename pcl::traits::fieldList<PointT>::type FieldList;

  float* colors = new float[nr_points];
  float field_data;

  int j = 0;
  // If XYZ present, check if the points are invalid
  int x_idx = -1;
  for (size_t d = 0; d < fields_.size (); ++d)
    if (fields_[d].name == "x")
      x_idx = static_cast<int> (d);

  if (x_idx != -1)
  {
    // Color every point
    for (vtkIdType cp = 0; cp < nr_points; ++cp)
    {
      // Copy the value at the specified field
      if (!pcl_isfinite (cloud_->points[cp].x) || !pcl_isfinite (cloud_->points[cp].y) || !pcl_isfinite (cloud_->points[cp].z))
        continue;

      const uint8_t* pt_data = reinterpret_cast<const uint8_t*> (&cloud_->points[cp]);
      memcpy (&field_data, pt_data + fields_[field_idx_].offset, pcl::getFieldSize (fields_[field_idx_].datatype));

      colors[j] = field_data;
      j++;
    }
  }
  else
  {
    // Color every point
    for (vtkIdType cp = 0; cp < nr_points; ++cp)
    {
      const uint8_t* pt_data = reinterpret_cast<const uint8_t*> (&cloud_->points[cp]);
      memcpy (&field_data, pt_data + fields_[field_idx_].offset, pcl::getFieldSize (fields_[field_idx_].datatype));

      if (!pcl_isfinite (field_data))
        continue;

      colors[j] = field_data;
      j++;
    }
  }
  reinterpret_cast<vtkFloatArray*>(&(*scalars))->SetArray (colors, j, 0, vtkFloatArray::VTK_DATA_ARRAY_DELETE);
  return (true);
}
Beispiel #28
0
//----------------------------------------------------------------------------------------------------
unique_ptr<carve::mesh::MeshSet<3> > CarveConnector::vtkPolyDataToMeshSet(vtkSmartPointer<vtkPolyData> &thepolydata)
{
	// First make MeshSet's points
	vector<carve::geom3d::Vector> vertices;
	vertices.resize(thepolydata->GetNumberOfPoints());

	for (vtkIdType i = 0; i < thepolydata->GetNumberOfPoints(); i++)
	{
		double p[3];
		thepolydata->GetPoint(i, p);

		vertices[i] = carve::geom::VECTOR(p[0], p[1], p[2]);
	}

	// Then make MeshSet Faces
	vtkSmartPointer<vtkCellArray> polys = thepolydata->GetPolys();
	polys->InitTraversal();

	vector<int> f;
	int numfaces = 0;
	int t = 0;

	f.resize(polys->GetSize());	// exact size: n1, id1, id2, id3, n2, id1, id2..etc
	for (int i = 0; i < polys->GetNumberOfCells(); i++)
	{
		vtkIdType n_pts;
		vtkIdType *pts = nullptr;
		polys->GetNextCell(n_pts, pts);

		f[t++] = n_pts;

		for (int j = 0; j < n_pts; j++)
			f[t++] = pts[j];

		//f[t++] = pts[0];
		//f[t++] = pts[1];
		//f[t++] = pts[2];

		//if (n_pts > 3)
		//f[t++] = pts[3];
		numfaces++;
	}
	// Construct MeshSet from vertices and faces
	unique_ptr<MeshSet<3> > first(new MeshSet<3>(vertices, numfaces, f));
	return first;
}
Beispiel #29
0
cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix)
{
    cv::Matx44f m;
    for (int i = 0; i < 4; i++)
        for (int k = 0; k < 4; k++)
            m(i, k) = vtk_matrix->GetElement(i, k);
    return m;
}
void SelectionUtilities::RemoveRowAndReMapTable(vtkIdType key, vtkSmartPointer<vtkTable> modTable, std::map< vtkIdType, vtkIdType> TableIDMap)
{
	/*!
	* remove a row from table
	* rebuild map
	*/
	std::map< vtkIdType, vtkIdType>::iterator TableIDIter = TableIDMap.find(key);
	if (TableIDIter != TableIDMap.end())
	{
		modTable->RemoveRow((*TableIDIter).second);
	}
	for (vtkIdType row = 0; row != modTable->GetNumberOfRows(); row++)
	{
		vtkIdType value = modTable->GetValue(row,0).ToTypeInt64();
		TableIDMap[value] = row;
	}
}