Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <pcl/apps/modeler/normals_actor_item.h>
00038
00039 #include <pcl/apps/modeler/cloud_mesh.h>
00040 #include <pcl/filters/filter_indices.h>
00041
00042 #include <vtkLODActor.h>
00043 #include <vtkPolyData.h>
00044 #include <vtkCellArray.h>
00045 #include <vtkDataSetMapper.h>
00046 #include <vtkPointData.h>
00047
00049 pcl::modeler::NormalsActorItem::NormalsActorItem(QTreeWidgetItem* parent,
00050 const boost::shared_ptr<CloudMesh>& cloud_mesh,
00051 const vtkSmartPointer<vtkRenderWindow>& render_window)
00052 :ChannelActorItem(parent, cloud_mesh, render_window, vtkSmartPointer<vtkLODActor>::New(), "Normals"),
00053 level_(10), scale_(0.1)
00054 {
00055 }
00056
00058 pcl::modeler::NormalsActorItem::~NormalsActorItem ()
00059 {
00060
00061 }
00062
00064 void
00065 pcl::modeler::NormalsActorItem::createNormalLines()
00066 {
00067 vtkPoints* points = poly_data_->GetPoints();
00068 vtkCellArray* lines = poly_data_->GetLines();
00069 lines->Reset();
00070
00071 CloudMesh::PointCloudConstPtr cloud = cloud_mesh_->getCloud();
00072 if (cloud->empty())
00073 return;
00074
00075 if (points->GetData() == NULL)
00076 points->SetData(vtkSmartPointer<vtkFloatArray>::New ());
00077
00078 vtkFloatArray* data = dynamic_cast<vtkFloatArray*>(points->GetData());
00079 data->SetNumberOfComponents (3);
00080
00081 if (cloud->is_dense)
00082 {
00083 vtkIdType nr_normals = static_cast<vtkIdType> ((cloud->points.size () - 1) / level_ + 1);
00084 data->SetNumberOfValues(2*3*nr_normals);
00085 for (vtkIdType i = 0, j = 0; j < nr_normals; j++, i = static_cast<vtkIdType> (j * level_))
00086 {
00087 const CloudMesh::PointT& p = cloud->points[i];
00088 data->SetValue(2*j*3 + 0, p.x);
00089 data->SetValue(2*j*3 + 1, p.y);
00090 data->SetValue(2*j*3 + 2, p.z);
00091 data->SetValue(2*j*3 + 3, float (p.x + p.normal_x*scale_));
00092 data->SetValue(2*j*3 + 4, float (p.y + p.normal_y*scale_));
00093 data->SetValue(2*j*3 + 5, float (p.z + p.normal_z*scale_));
00094
00095 lines->InsertNextCell(2);
00096 lines->InsertCellPoint(2*j);
00097 lines->InsertCellPoint(2*j + 1);
00098 }
00099 }
00100 else
00101 {
00102 pcl::IndicesPtr indices(new std::vector<int>());
00103 pcl::removeNaNFromPointCloud(*cloud, *indices);
00104
00105 vtkIdType nr_normals = static_cast<vtkIdType> ((indices->size () - 1) / level_ + 1);
00106 data->SetNumberOfValues(2*3*nr_normals);
00107 for (vtkIdType i = 0, j = 0; j < nr_normals; j++, i = static_cast<vtkIdType> (j * level_))
00108 {
00109 const CloudMesh::PointT& p= cloud->points[(*indices)[i]];
00110 data->SetValue (2*j*3 + 0, p.x);
00111 data->SetValue (2*j*3 + 1, p.y);
00112 data->SetValue (2*j*3 + 2, p.z);
00113 data->SetValue (2*j*3 + 3, float (p.x + p.normal_x*scale_));
00114 data->SetValue (2*j*3 + 4, float (p.y + p.normal_y*scale_));
00115 data->SetValue (2*j*3 + 5, float (p.z + p.normal_z*scale_));
00116
00117 lines->InsertNextCell(2);
00118 lines->InsertCellPoint(2*j);
00119 lines->InsertCellPoint(2*j + 1);
00120 }
00121 }
00122
00123 return;
00124 }
00125
00127 void
00128 pcl::modeler::NormalsActorItem::initImpl()
00129 {
00130 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
00131 points->SetDataTypeToFloat ();
00132 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
00133
00134 poly_data_->SetPoints(points);
00135 poly_data_->SetLines(lines);
00136
00137 createNormalLines();
00138
00139 vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
00140 mapper->SetInput(poly_data_);
00141
00142 vtkSmartPointer<vtkDataArray> scalars;
00143 cloud_mesh_->getColorScalarsFromField(scalars, color_scheme_);
00144 poly_data_->GetPointData ()->SetScalars (scalars);
00145 double minmax[2];
00146 scalars->GetRange(minmax);
00147 mapper->SetScalarRange(minmax);
00148
00149 mapper->SetColorModeToMapScalars();
00150 mapper->SetScalarModeToUsePointData();
00151
00152 vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>(dynamic_cast<vtkLODActor*>(actor_.GetPointer()));
00153 actor->SetMapper(mapper);
00154 }
00155
00157 void
00158 pcl::modeler::NormalsActorItem::updateImpl()
00159 {
00160 createNormalLines();
00161
00162 vtkSmartPointer<vtkDataArray> scalars;
00163 cloud_mesh_->getColorScalarsFromField(scalars, color_scheme_);
00164 poly_data_->GetPointData ()->SetScalars (scalars);
00165 double minmax[2];
00166 scalars->GetRange(minmax);
00167 actor_->GetMapper()->SetScalarRange(minmax);
00168
00169 poly_data_->Update();
00170
00171 return;
00172 }
00173
00175 void
00176 pcl::modeler::NormalsActorItem::prepareContextMenu(QMenu* ) const
00177 {
00178
00179 }
00180
00182 void
00183 pcl::modeler::NormalsActorItem::prepareProperties(ParameterDialog* )
00184 {
00185
00186 }
00187
00189 void
00190 pcl::modeler::NormalsActorItem::setProperties()
00191 {
00192
00193 }