@ -849,53 +849,53 @@ bool cv::viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename,
bool cv : : viz : : Viz3d : : VizImpl : : addPolylineFromPolygonMesh ( const Mesh3d & mesh , const std : : string & id )
bool cv : : viz : : Viz3d : : VizImpl : : addPolylineFromPolygonMesh ( const Mesh3d & mesh , const std : : string & id )
{
{
CV_Assert ( mesh . cloud . rows = = 1 & & mesh . cloud . type ( ) = = CV_32FC3 ) ;
// CV_Assert(mesh.cloud.rows == 1 && mesh.cloud.type() == CV_32FC3);
//
ShapeActorMap : : iterator am_it = shape_actor_map_ - > find ( id ) ;
// ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
if ( am_it ! = shape_actor_map_ - > end ( ) )
// if (am_it != shape_actor_map_->end ())
return std : : cout < < " [addPolylineFromPolygonMesh] A shape with id < " < < id < < " > already exists! Please choose a different id and retry. \n " < < std : : endl , false ;
// return std::cout << "[addPolylineFromPolygonMesh] A shape with id <"<< id << " > already exists! Please choose a different id and retry.\n" << std::endl, false;
//
vtkSmartPointer < vtkPoints > poly_points = vtkSmartPointer < vtkPoints > : : New ( ) ;
// vtkSmartPointer<vtkPoints> poly_points = vtkSmartPointer<vtkPoints>::New ();
poly_points - > SetNumberOfPoints ( mesh . cloud . size ( ) . area ( ) ) ;
// poly_points->SetNumberOfPoints (mesh.cloud.size().area());
//
const cv : : Point3f * cdata = mesh . cloud . ptr < cv : : Point3f > ( ) ;
// const cv::Point3f *cdata = mesh.cloud.ptr<cv::Point3f>();
for ( int i = 0 ; i < mesh . cloud . cols ; + + i )
// for (int i = 0; i < mesh.cloud.cols; ++i)
poly_points - > InsertPoint ( i , cdata [ i ] . x , cdata [ i ] . y , cdata [ i ] . z ) ;
// poly_points->InsertPoint (i, cdata[i].x, cdata[i].y,cdata[i].z);
//
//
// Create a cell array to store the lines in and add the lines to it
// // Create a cell array to store the lines in and add the lines to it
vtkSmartPointer < vtkCellArray > cells = vtkSmartPointer < vtkCellArray > : : New ( ) ;
// vtkSmartPointer <vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New ();
vtkSmartPointer < vtkPolyData > polyData ;
// vtkSmartPointer <vtkPolyData> polyData;
allocVtkPolyData ( polyData ) ;
// allocVtkPolyData (polyData);
//
for ( size_t i = 0 ; i < mesh . polygons . size ( ) ; i + + )
// for (size_t i = 0; i < mesh.polygons.size (); i++)
{
// {
vtkSmartPointer < vtkPolyLine > polyLine = vtkSmartPointer < vtkPolyLine > : : New ( ) ;
// vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
polyLine - > GetPointIds ( ) - > SetNumberOfIds ( mesh . polygons [ i ] . vertices . size ( ) ) ;
// polyLine->GetPointIds()->SetNumberOfIds(mesh.polygons[i].vertices.size());
for ( unsigned int k = 0 ; k < mesh . polygons [ i ] . vertices . size ( ) ; k + + )
// for(unsigned int k = 0; k < mesh.polygons[i].vertices.size(); k++)
{
// {
polyLine - > GetPointIds ( ) - > SetId ( k , mesh . polygons [ i ] . vertices [ k ] ) ;
// polyLine->GetPointIds()->SetId(k,mesh. polygons[i].vertices[k]);
}
// }
//
cells - > InsertNextCell ( polyLine ) ;
// cells->InsertNextCell (polyLine);
}
// }
//
// Add the points to the dataset
// // Add the points to the dataset
polyData - > SetPoints ( poly_points ) ;
// polyData->SetPoints (poly_points);
//
// Add the lines to the dataset
// // Add the lines to the dataset
polyData - > SetLines ( cells ) ;
// polyData->SetLines (cells);
//
// Setup actor and mapper
// // Setup actor and mapper
vtkSmartPointer < vtkPolyDataMapper > mapper = vtkSmartPointer < vtkPolyDataMapper > : : New ( ) ;
// vtkSmartPointer < vtkPolyDataMapper > mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
mapper - > SetInput ( polyData ) ;
// mapper->SetInput (polyData);
//
vtkSmartPointer < vtkActor > actor = vtkSmartPointer < vtkActor > : : New ( ) ;
// vtkSmartPointer <vtkActor> actor = vtkSmartPointer<vtkActor>::New ();
actor - > SetMapper ( mapper ) ;
// actor->SetMapper (mapper);
renderer_ - > AddActor ( actor ) ;
// renderer_->AddActor(actor);
//
// Save the pointer/ID pair to the global actor map
// // Save the pointer/ID pair to the global actor map
( * shape_actor_map_ ) [ id ] = actor ;
// (*shape_actor_map_)[id] = actor;
return ( true ) ;
return ( true ) ;
}
}
@ -1019,304 +1019,305 @@ void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize
bool cv : : viz : : Viz3d : : VizImpl : : addPolygonMesh ( const Mesh3d & mesh , const Mat & mask , const std : : string & id )
bool cv : : viz : : Viz3d : : VizImpl : : addPolygonMesh ( const Mesh3d & mesh , const Mat & mask , const std : : string & id )
{
{
CV_Assert ( mesh . cloud . type ( ) = = CV_32FC3 & & mesh . cloud . rows = = 1 & & ! mesh . polygons . empty ( ) ) ;
// CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());
CV_Assert ( mesh . colors . empty ( ) | | ( ! mesh . colors . empty ( ) & & mesh . colors . size ( ) = = mesh . cloud . size ( ) & & mesh . colors . type ( ) = = CV_8UC3 ) ) ;
// CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3));
CV_Assert ( mask . empty ( ) | | ( ! mask . empty ( ) & & mask . size ( ) = = mesh . cloud . size ( ) & & mask . type ( ) = = CV_8U ) ) ;
// CV_Assert(mask.empty() || (!mask.empty() && mask.size() == mesh.cloud.size() && mask.type() == CV_8U));
//
if ( cloud_actor_map_ - > find ( id ) ! = cloud_actor_map_ - > end ( ) )
// if (cloud_actor_map_->find (id) != cloud_actor_map_->end ())
return std : : cout < < " [addPolygonMesh] A shape with id < " < < id < < " > already exists! Please choose a different id and retry. " < < std : : endl , false ;
// return std::cout << "[addPolygonMesh] A shape with id <" << id << "> already exists! Please choose a different id and retry." << std::endl, false;
//
// int rgb_idx = -1;
// // int rgb_idx = -1;
// std::vector<sensor_msgs::PointField> fields;
// // std::vector<sensor_msgs::PointField> fields;
//
//
// rgb_idx = cv::viz::getFieldIndex (*cloud, "rgb", fields);
// // rgb_idx = temp_viz::getFieldIndex (*cloud, "rgb", fields);
// if (rgb_idx == -1)
// // if (rgb_idx == -1)
// rgb_idx = cv::viz::getFieldIndex (*cloud, "rgba", fields);
// // rgb_idx = temp_viz::getFieldIndex (*cloud, "rgba", fields);
//
vtkSmartPointer < vtkUnsignedCharArray > colors_array ;
// vtkSmartPointer<vtkUnsignedCharArray> colors_array;
# if 1
// #if 1
if ( ! mesh . colors . empty ( ) )
// if (!mesh.colors.empty())
{
// {
colors_array = vtkSmartPointer < vtkUnsignedCharArray > : : New ( ) ;
// colors_array = vtkSmartPointer<vtkUnsignedCharArray>::New ();
colors_array - > SetNumberOfComponents ( 3 ) ;
// colors_array->SetNumberOfComponents (3);
colors_array - > SetName ( " Colors " ) ;
// colors_array->SetName ("Colors");
//
const unsigned char * data = mesh . colors . ptr < unsigned char > ( ) ;
// const unsigned char* data = mesh.colors.ptr<unsigned char>();
//
//TODO check mask
// //TODO check mask
CV_Assert ( mask . empty ( ) ) ; //because not implemented;
// CV_Assert(mask.empty()); //because not implemented;
//
for ( int i = 0 ; i < mesh . colors . cols ; + + i )
// for(int i = 0; i < mesh.colors.cols; ++i)
colors_array - > InsertNextTupleValue ( & data [ i * 3 ] ) ;
// colors_array->InsertNextTupleValue(&data[i*3]);
//
// cv::viz::RGB rgb_data;
// // temp_viz::RGB rgb_data;
// for (size_t i = 0; i < cloud->size (); ++i)
// // for (size_t i = 0; i < cloud->size (); ++i)
// {
// // {
// if (!isFinite (cloud->points[i]))
// // if (!isFinite (cloud->points[i]))
// continue;
// // continue;
// memcpy (&rgb_data, reinterpret_cast<const char*> (&cloud->points[i]) + fields[rgb_idx].offset, sizeof (cv::viz::RGB));
// // memcpy (&rgb_data, reinterpret_cast<const char*> (&cloud->points[i]) + fields[rgb_idx].offset, sizeof (temp_viz::RGB));
// unsigned char color[3];
// // unsigned char color[3];
// color[0] = rgb_data.r;
// // color[0] = rgb_data.r;
// color[1] = rgb_data.g;
// // color[1] = rgb_data.g;
// color[2] = rgb_data.b;
// // color[2] = rgb_data.b;
// colors->InsertNextTupleValue (color);
// // colors->InsertNextTupleValue (color);
// }
// // }
}
// }
# endif
// #endif
//
// Create points from polyMesh.cloud
// // Create points from polyMesh.cloud
vtkSmartPointer < vtkPoints > points = vtkSmartPointer < vtkPoints > : : New ( ) ;
// vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ();
vtkIdType nr_points = mesh . cloud . size ( ) . area ( ) ;
// vtkIdType nr_points = mesh.cloud.size().area();
//
points - > SetNumberOfPoints ( nr_points ) ;
// points->SetNumberOfPoints (nr_points);
//
//
// Get a pointer to the beginning of the data array
// // Get a pointer to the beginning of the data array
float * data = static_cast < vtkFloatArray * > ( points - > GetData ( ) ) - > GetPointer ( 0 ) ;
// float *data = static_cast<vtkFloatArray*> (points->GetData ())->GetPointer (0);
//
//
std : : vector < int > lookup ;
// std::vector<int> lookup;
// If the dataset is dense (no NaNs)
// // If the dataset is dense (no NaNs)
if ( mask . empty ( ) )
// if (mask.empty())
{
// {
cv : : Mat hdr ( mesh . cloud . size ( ) , CV_32FC3 , ( void * ) data ) ;
// cv::Mat hdr(mesh.cloud.size(), CV_32FC3, (void*)data);
mesh . cloud . copyTo ( hdr ) ;
// mesh.cloud.copyTo(hdr);
}
// }
else
// else
{
// {
lookup . resize ( nr_points ) ;
// lookup.resize (nr_points);
//
const unsigned char * mdata = mask . ptr < unsigned char > ( ) ;
// const unsigned char *mdata = mask.ptr<unsigned char>();
const cv : : Point3f * cdata = mesh . cloud . ptr < cv : : Point3f > ( ) ;
// const cv::Point3f *cdata = mesh.cloud.ptr<cv::Point3f>();
cv : : Point3f * out = reinterpret_cast < cv : : Point3f * > ( data ) ;
// cv::Point3f* out = reinterpret_cast<cv::Point3f*>(data);
//
int j = 0 ; // true point index
// int j = 0; // true point index
for ( int i = 0 ; i < nr_points ; + + i )
// for (int i = 0; i < nr_points; ++i)
if ( mdata [ i ] )
// if(mdata[i])
{
// {
lookup [ i ] = j ;
// lookup[i] = j;
out [ j + + ] = cdata [ i ] ;
// out[j++] = cdata[i];
}
// }
nr_points = j ;
// nr_points = j;
points - > SetNumberOfPoints ( nr_points ) ;
// points->SetNumberOfPoints (nr_points);
}
// }
//
// Get the maximum size of a polygon
// // Get the maximum size of a polygon
int max_size_of_polygon = - 1 ;
// int max_size_of_polygon = -1;
for ( size_t i = 0 ; i < mesh . polygons . size ( ) ; + + i )
// for (size_t i = 0; i < mesh.polygons.size (); ++i)
if ( max_size_of_polygon < static_cast < int > ( mesh . polygons [ i ] . vertices . size ( ) ) )
// if (max_size_of_polygon < static_cast<int> (mesh.polygons[i].vertices.size ()))
max_size_of_polygon = static_cast < int > ( mesh . polygons [ i ] . vertices . size ( ) ) ;
// max_size_of_polygon = static_cast<int> (mesh.polygons[i].vertices.size ());
//
vtkSmartPointer < vtkLODActor > actor ;
// vtkSmartPointer<vtkLODActor> actor;
//
if ( mesh . polygons . size ( ) > 1 )
// if (mesh.polygons.size () > 1)
{
// {
// Create polys from polyMesh.polygons
// // Create polys from polyMesh.polygons
vtkSmartPointer < vtkCellArray > cell_array = vtkSmartPointer < vtkCellArray > : : New ( ) ;
// vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New ();
vtkIdType * cell = cell_array - > WritePointer ( mesh . polygons . size ( ) , mesh . polygons . size ( ) * ( max_size_of_polygon + 1 ) ) ;
// vtkIdType *cell = cell_array->WritePointer (mesh.polygons.size (), mesh.polygons.size () * (max_size_of_polygon + 1));
int idx = 0 ;
// int idx = 0;
if ( lookup . size ( ) > 0 )
// if (lookup.size () > 0)
{
// {
for ( size_t i = 0 ; i < mesh . polygons . size ( ) ; + + i , + + idx )
// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx)
{
// {
size_t n_points = mesh . polygons [ i ] . vertices . size ( ) ;
// size_t n_points = mesh.polygons[i].vertices.size ();
* cell + + = n_points ;
// *cell++ = n_points;
//cell_array->InsertNextCell (n_points);
// //cell_array->InsertNextCell (n_points);
for ( size_t j = 0 ; j < n_points ; j + + , + + idx )
// for (size_t j = 0; j < n_points; j++, ++idx)
* cell + + = lookup [ mesh . polygons [ i ] . vertices [ j ] ] ;
// *cell++ = lookup[mesh.polygons[i].vertices[j]];
//cell_array->InsertCellPoint (lookup[vertices[i].vertices[j]]);
// //cell_array->InsertCellPoint (lookup[vertices[i].vertices[j]]);
}
// }
}
// }
else
// else
{
// {
for ( size_t i = 0 ; i < mesh . polygons . size ( ) ; + + i , + + idx )
// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx)
{
// {
size_t n_points = mesh . polygons [ i ] . vertices . size ( ) ;
// size_t n_points = mesh.polygons[i].vertices.size ();
* cell + + = n_points ;
// *cell++ = n_points;
//cell_array->InsertNextCell (n_points);
// //cell_array->InsertNextCell (n_points);
for ( size_t j = 0 ; j < n_points ; j + + , + + idx )
// for (size_t j = 0; j < n_points; j++, ++idx)
* cell + + = mesh . polygons [ i ] . vertices [ j ] ;
// *cell++ = mesh.polygons[i].vertices[j];
//cell_array->InsertCellPoint (vertices[i].vertices[j]);
// //cell_array->InsertCellPoint (vertices[i].vertices[j]);
}
// }
}
// }
vtkSmartPointer < vtkPolyData > polydata ;
// vtkSmartPointer<vtkPolyData> polydata;
allocVtkPolyData ( polydata ) ;
// allocVtkPolyData (polydata);
cell_array - > GetData ( ) - > SetNumberOfValues ( idx ) ;
// cell_array->GetData ()->SetNumberOfValues (idx);
cell_array - > Squeeze ( ) ;
// cell_array->Squeeze ();
polydata - > SetStrips ( cell_array ) ;
// polydata->SetStrips (cell_array);
polydata - > SetPoints ( points ) ;
// polydata->SetPoints (points);
//
if ( colors_array )
// if (colors_array)
polydata - > GetPointData ( ) - > SetScalars ( colors_array ) ;
// polydata->GetPointData ()->SetScalars (colors_array);
//
createActorFromVTKDataSet ( polydata , actor , false ) ;
// createActorFromVTKDataSet (polydata, actor, false);
}
// }
else
// else
{
// {
vtkSmartPointer < vtkPolygon > polygon = vtkSmartPointer < vtkPolygon > : : New ( ) ;
// vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New ();
size_t n_points = mesh . polygons [ 0 ] . vertices . size ( ) ;
// size_t n_points = mesh.polygons[0].vertices.size ();
polygon - > GetPointIds ( ) - > SetNumberOfIds ( n_points - 1 ) ;
// polygon->GetPointIds ()->SetNumberOfIds (n_points - 1);
//
if ( lookup . size ( ) > 0 )
// if (lookup.size () > 0)
{
// {
for ( size_t j = 0 ; j < n_points - 1 ; + + j )
// for (size_t j = 0; j < n_points - 1; ++j)
polygon - > GetPointIds ( ) - > SetId ( j , lookup [ mesh . polygons [ 0 ] . vertices [ j ] ] ) ;
// polygon->GetPointIds ()->SetId (j, lookup[mesh.polygons[0].vertices[j]]);
}
// }
else
// else
{
// {
for ( size_t j = 0 ; j < n_points - 1 ; + + j )
// for (size_t j = 0; j < n_points - 1; ++j)
polygon - > GetPointIds ( ) - > SetId ( j , mesh . polygons [ 0 ] . vertices [ j ] ) ;
// polygon->GetPointIds ()->SetId (j, mesh.polygons[0].vertices[j]);
}
// }
vtkSmartPointer < vtkUnstructuredGrid > poly_grid ;
// vtkSmartPointer<vtkUnstructuredGrid> poly_grid;
allocVtkUnstructuredGrid ( poly_grid ) ;
// allocVtkUnstructuredGrid (poly_grid);
poly_grid - > Allocate ( 1 , 1 ) ;
// poly_grid->Allocate (1, 1);
poly_grid - > InsertNextCell ( polygon - > GetCellType ( ) , polygon - > GetPointIds ( ) ) ;
// poly_grid->InsertNextCell (polygon->GetCellType (), polygon->GetPointIds ());
poly_grid - > SetPoints ( points ) ;
// poly_grid->SetPoints (points);
poly_grid - > Update ( ) ;
// poly_grid->Update ();
if ( colors_array )
// if (colors_array)
poly_grid - > GetPointData ( ) - > SetScalars ( colors_array ) ;
// poly_grid->GetPointData ()->SetScalars (colors_array);
//
createActorFromVTKDataSet ( poly_grid , actor , false ) ;
// createActorFromVTKDataSet (poly_grid, actor, false);
}
// }
renderer_ - > AddActor ( actor ) ;
// renderer_->AddActor (actor);
actor - > GetProperty ( ) - > SetRepresentationToSurface ( ) ;
// actor->GetProperty ()->SetRepresentationToSurface ();
// Backface culling renders the visualization slower, but guarantees that we see all triangles
// // Backface culling renders the visualization slower, but guarantees that we see all triangles
actor - > GetProperty ( ) - > BackfaceCullingOff ( ) ;
// actor->GetProperty ()->BackfaceCullingOff ();
actor - > GetProperty ( ) - > SetInterpolationToFlat ( ) ;
// actor->GetProperty ()->SetInterpolationToFlat ();
actor - > GetProperty ( ) - > EdgeVisibilityOff ( ) ;
// actor->GetProperty ()->EdgeVisibilityOff ();
actor - > GetProperty ( ) - > ShadingOff ( ) ;
// actor->GetProperty ()->ShadingOff ();
//
// Save the pointer/ID pair to the global actor map
// // Save the pointer/ID pair to the global actor map
( * cloud_actor_map_ ) [ id ] . actor = actor ;
// (*cloud_actor_map_)[id].actor = actor;
//if (vertices.size () > 1)
// //if (vertices.size () > 1)
// (*cloud_actor_map_)[id].cells = static_cast<vtkPolyDataMapper*>(actor->GetMapper ())->GetInput ()->GetVerts ()->GetData ();
// // (*cloud_actor_map_)[id].cells = static_cast<vtkPolyDataMapper*>(actor->GetMapper ())->GetInput ()->GetVerts ()->GetData ();
//
const Eigen : : Vector4f & sensor_origin = Eigen : : Vector4f : : Zero ( ) ;
// const Eigen::Vector4f& sensor_origin = Eigen::Vector4f::Zero ();
const Eigen : : Quaternion < float > & sensor_orientation = Eigen : : Quaternionf : : Identity ( ) ;
// const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternionf::Identity ();
//
// Save the viewpoint transformation matrix to the global actor map
// // Save the viewpoint transformation matrix to the global actor map
vtkSmartPointer < vtkMatrix4x4 > transformation = vtkSmartPointer < vtkMatrix4x4 > : : New ( ) ;
// vtkSmartPointer<vtkMatrix4x4> transformation = vtkSmartPointer<vtkMatrix4x4>::New();
convertToVtkMatrix ( sensor_origin , sensor_orientation , transformation ) ;
// convertToVtkMatrix (sensor_origin, sensor_orientation, transformation);
( * cloud_actor_map_ ) [ id ] . viewpoint_transformation_ = transformation ;
// (*cloud_actor_map_)[id].viewpoint_transformation_ = transformation;
//
return ( true ) ;
// return (true);
return true ;
}
}
bool cv : : viz : : Viz3d : : VizImpl : : updatePolygonMesh ( const Mesh3d & mesh , const cv : : Mat & mask , const std : : string & id )
bool cv : : viz : : Viz3d : : VizImpl : : updatePolygonMesh ( const Mesh3d & mesh , const cv : : Mat & mask , const std : : string & id )
{
{
CV_Assert ( mesh . cloud . type ( ) = = CV_32FC3 & & mesh . cloud . rows = = 1 & & ! mesh . polygons . empty ( ) ) ;
// CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());
CV_Assert ( mesh . colors . empty ( ) | | ( ! mesh . colors . empty ( ) & & mesh . colors . size ( ) = = mesh . cloud . size ( ) & & mesh . colors . type ( ) = = CV_8UC3 ) ) ;
// CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3));
CV_Assert ( mask . empty ( ) | | ( ! mask . empty ( ) & & mask . size ( ) = = mesh . cloud . size ( ) & & mask . type ( ) = = CV_8U ) ) ;
// CV_Assert(mask.empty() || (!mask.empty() && mask.size() == mesh.cloud.size() && mask.type() == CV_8U));
//
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
// // Check to see if this ID entry already exists (has it been already added to the visualizer?)
CloudActorMap : : iterator am_it = cloud_actor_map_ - > find ( id ) ;
// CloudActorMap::iterator am_it = cloud_actor_map_->find (id);
if ( am_it = = cloud_actor_map_ - > end ( ) )
// if (am_it == cloud_actor_map_->end ())
return ( false ) ;
// return (false);
//
// Get the current poly data
// // Get the current poly data
vtkSmartPointer < vtkPolyData > polydata = static_cast < vtkPolyDataMapper * > ( am_it - > second . actor - > GetMapper ( ) ) - > GetInput ( ) ;
// vtkSmartPointer<vtkPolyData> polydata = static_cast<vtkPolyDataMapper*>(am_it->second.actor->GetMapper ())->GetInput ();
if ( ! polydata )
// if (!polydata)
return ( false ) ;
// return (false);
vtkSmartPointer < vtkCellArray > cells = polydata - > GetStrips ( ) ;
// vtkSmartPointer<vtkCellArray> cells = polydata->GetStrips ();
if ( ! cells )
// if (!cells)
return ( false ) ;
// return (false);
vtkSmartPointer < vtkPoints > points = polydata - > GetPoints ( ) ;
// vtkSmartPointer<vtkPoints> points = polydata->GetPoints ();
// Copy the new point array in
// // Copy the new point array in
vtkIdType nr_points = mesh . cloud . size ( ) . area ( ) ;
// vtkIdType nr_points = mesh.cloud.size().area();
points - > SetNumberOfPoints ( nr_points ) ;
// points->SetNumberOfPoints (nr_points);
//
// Get a pointer to the beginning of the data array
// // Get a pointer to the beginning of the data array
float * data = ( static_cast < vtkFloatArray * > ( points - > GetData ( ) ) ) - > GetPointer ( 0 ) ;
// float *data = (static_cast<vtkFloatArray*> (points->GetData ()))->GetPointer (0);
//
int ptr = 0 ;
// int ptr = 0;
std : : vector < int > lookup ;
// std::vector<int> lookup;
// If the dataset is dense (no NaNs)
// // If the dataset is dense (no NaNs)
if ( mask . empty ( ) )
// if (mask.empty())
{
// {
cv : : Mat hdr ( mesh . cloud . size ( ) , CV_32FC3 , ( void * ) data ) ;
// cv::Mat hdr(mesh.cloud.size(), CV_32FC3, (void*)data);
mesh . cloud . copyTo ( hdr ) ;
// mesh.cloud.copyTo(hdr);
//
}
// }
else
// else
{
// {
lookup . resize ( nr_points ) ;
// lookup.resize (nr_points);
//
const unsigned char * mdata = mask . ptr < unsigned char > ( ) ;
// const unsigned char *mdata = mask.ptr<unsigned char>();
const cv : : Point3f * cdata = mesh . cloud . ptr < cv : : Point3f > ( ) ;
// const cv::Point3f *cdata = mesh.cloud.ptr<cv::Point3f>();
cv : : Point3f * out = reinterpret_cast < cv : : Point3f * > ( data ) ;
// cv::Point3f* out = reinterpret_cast<cv::Point3f*>(data);
//
int j = 0 ; // true point index
// int j = 0; // true point index
for ( int i = 0 ; i < nr_points ; + + i )
// for (int i = 0; i < nr_points; ++i)
if ( mdata [ i ] )
// if(mdata[i])
{
// {
lookup [ i ] = j ;
// lookup[i] = j;
out [ j + + ] = cdata [ i ] ;
// out[j++] = cdata[i];
}
// }
nr_points = j ;
// nr_points = j;
points - > SetNumberOfPoints ( nr_points ) ; ;
// points->SetNumberOfPoints (nr_points);;
}
// }
//
// Update colors
// // Update colors
vtkUnsignedCharArray * colors_array = vtkUnsignedCharArray : : SafeDownCast ( polydata - > GetPointData ( ) - > GetScalars ( ) ) ;
// vtkUnsignedCharArray* colors_array = vtkUnsignedCharArray::SafeDownCast (polydata->GetPointData ()->GetScalars ());
//
if ( ! mesh . colors . empty ( ) & & colors_array )
// if (!mesh.colors.empty() && colors_array)
{
// {
if ( mask . empty ( ) )
// if (mask.empty())
{
// {
const unsigned char * data = mesh . colors . ptr < unsigned char > ( ) ;
// const unsigned char* data = mesh.colors.ptr<unsigned char>();
for ( int i = 0 ; i < mesh . colors . cols ; + + i )
// for(int i = 0; i < mesh.colors.cols; ++i)
colors_array - > InsertNextTupleValue ( & data [ i * 3 ] ) ;
// colors_array->InsertNextTupleValue(&data[i*3]);
}
// }
else
// else
{
// {
const unsigned char * color = mesh . colors . ptr < unsigned char > ( ) ;
// const unsigned char* color = mesh.colors.ptr<unsigned char>();
const unsigned char * mdata = mask . ptr < unsigned char > ( ) ;
// const unsigned char* mdata = mask.ptr<unsigned char>();
//
int j = 0 ;
// int j = 0;
for ( int i = 0 ; i < mesh . colors . cols ; + + i )
// for(int i = 0; i < mesh.colors.cols; ++i)
if ( mdata [ i ] )
// if (mdata[i])
colors_array - > SetTupleValue ( j + + , & color [ i * 3 ] ) ;
// colors_array->SetTupleValue (j++, &color[i*3]);
//
}
// }
}
// }
//
// Get the maximum size of a polygon
// // Get the maximum size of a polygon
int max_size_of_polygon = - 1 ;
// int max_size_of_polygon = -1;
for ( size_t i = 0 ; i < mesh . polygons . size ( ) ; + + i )
// for (size_t i = 0; i < mesh.polygons.size (); ++i)
if ( max_size_of_polygon < static_cast < int > ( mesh . polygons [ i ] . vertices . size ( ) ) )
// if (max_size_of_polygon < static_cast<int> (mesh.polygons[i].vertices.size ()))
max_size_of_polygon = static_cast < int > ( mesh . polygons [ i ] . vertices . size ( ) ) ;
// max_size_of_polygon = static_cast<int> (mesh.polygons[i].vertices.size ());
//
// Update the cells
// // Update the cells
cells = vtkSmartPointer < vtkCellArray > : : New ( ) ;
// cells = vtkSmartPointer<vtkCellArray>::New ();
vtkIdType * cell = cells - > WritePointer ( mesh . polygons . size ( ) , mesh . polygons . size ( ) * ( max_size_of_polygon + 1 ) ) ;
// vtkIdType *cell = cells->WritePointer (mesh.polygons.size (), mesh.polygons.size () * (max_size_of_polygon + 1));
int idx = 0 ;
// int idx = 0;
if ( lookup . size ( ) > 0 )
// if (lookup.size () > 0)
{
// {
for ( size_t i = 0 ; i < mesh . polygons . size ( ) ; + + i , + + idx )
// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx)
{
// {
size_t n_points = mesh . polygons [ i ] . vertices . size ( ) ;
// size_t n_points = mesh.polygons[i].vertices.size ();
* cell + + = n_points ;
// *cell++ = n_points;
for ( size_t j = 0 ; j < n_points ; j + + , cell + + , + + idx )
// for (size_t j = 0; j < n_points; j++, cell++, ++idx)
* cell = lookup [ mesh . polygons [ i ] . vertices [ j ] ] ;
// *cell = lookup[mesh.polygons[i].vertices[j]];
}
// }
}
// }
else
// else
{
// {
for ( size_t i = 0 ; i < mesh . polygons . size ( ) ; + + i , + + idx )
// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx)
{
// {
size_t n_points = mesh . polygons [ i ] . vertices . size ( ) ;
// size_t n_points = mesh.polygons[i].vertices.size ();
* cell + + = n_points ;
// *cell++ = n_points;
for ( size_t j = 0 ; j < n_points ; j + + , cell + + , + + idx )
// for (size_t j = 0; j < n_points; j++, cell++, ++idx)
* cell = mesh . polygons [ i ] . vertices [ j ] ;
// *cell = mesh.polygons[i].vertices[j];
}
// }
}
// }
cells - > GetData ( ) - > SetNumberOfValues ( idx ) ;
// cells->GetData ()->SetNumberOfValues (idx);
cells - > Squeeze ( ) ;
// cells->Squeeze ();
// Set the the vertices
// // Set the the vertices
polydata - > SetStrips ( cells ) ;
// polydata->SetStrips (cells);
polydata - > Update ( ) ;
// polydata->Update ();
return ( true ) ;
return ( true ) ;
}
}