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
00038 #include <pcl/visualization/common/shapes.h>
00039 #include <pcl/common/angles.h>
00040 #include <vtkLineSource.h>
00041 #include <vtkTubeFilter.h>
00042 #include <vtkConeSource.h>
00043 #include <vtkTransformPolyDataFilter.h>
00044 #include <vtkTransform.h>
00045 #include <vtkSphereSource.h>
00046 #include <vtkDiskSource.h>
00047 #include <vtkPlaneSource.h>
00048 #include <vtkCubeSource.h>
00049
00051 vtkSmartPointer<vtkDataSet>
00052 pcl::visualization::createCylinder (const pcl::ModelCoefficients &coefficients, int numsides)
00053 {
00054 vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New ();
00055 line->SetPoint1 (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
00056 line->SetPoint2 (coefficients.values[3]+coefficients.values[0], coefficients.values[4]+coefficients.values[1], coefficients.values[5]+coefficients.values[2]);
00057
00058 vtkSmartPointer<vtkTubeFilter> tuber = vtkSmartPointer<vtkTubeFilter>::New ();
00059 tuber->SetInputConnection (line->GetOutputPort ());
00060 tuber->SetRadius (coefficients.values[6]);
00061 tuber->SetNumberOfSides (numsides);
00062
00063 return (tuber->GetOutput ());
00064 }
00065
00067 vtkSmartPointer<vtkDataSet>
00068 pcl::visualization::createSphere (const pcl::ModelCoefficients &coefficients, int res)
00069 {
00070
00071 vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
00072 t->Identity (); t->Translate (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
00073
00074 vtkSmartPointer<vtkSphereSource> s_sphere = vtkSmartPointer<vtkSphereSource>::New ();
00075 s_sphere->SetRadius (coefficients.values[3]);
00076 s_sphere->SetPhiResolution (res);
00077 s_sphere->SetThetaResolution (res);
00078 s_sphere->LatLongTessellationOff ();
00079
00080 vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
00081 tf->SetTransform (t);
00082 tf->SetInputConnection (s_sphere->GetOutputPort ());
00083
00084 return (tf->GetOutput ());
00085 }
00086
00088 vtkSmartPointer<vtkDataSet>
00089 pcl::visualization::createCube (const pcl::ModelCoefficients &coefficients)
00090 {
00091
00092 vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
00093 t->Identity ();
00094 t->Translate (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
00095
00096 Eigen::AngleAxisf a (Eigen::Quaternionf (coefficients.values[6], coefficients.values[3],
00097 coefficients.values[4], coefficients.values[5]));
00098 t->RotateWXYZ (pcl::rad2deg (a.angle ()), a.axis ()[0], a.axis ()[1], a.axis ()[2]);
00099
00100 vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New ();
00101 cube->SetXLength (coefficients.values[7]);
00102 cube->SetYLength (coefficients.values[8]);
00103 cube->SetZLength (coefficients.values[9]);
00104
00105 vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
00106 tf->SetTransform (t);
00107 tf->SetInputConnection (cube->GetOutputPort ());
00108
00109 return (tf->GetOutput ());
00110 }
00111
00113 vtkSmartPointer<vtkDataSet>
00114 pcl::visualization::createCube (const Eigen::Vector3f &translation, const Eigen::Quaternionf &rotation,
00115 double width, double height, double depth)
00116 {
00117
00118 vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
00119 t->Identity ();
00120 t->Translate (translation.x (), translation.y (), translation.z ());
00121
00122 Eigen::AngleAxisf a (rotation);
00123 t->RotateWXYZ (pcl::rad2deg (a.angle ()), a.axis ()[0], a.axis ()[1], a.axis ()[2]);
00124
00125 vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New ();
00126 cube->SetXLength (width);
00127 cube->SetYLength (height);
00128 cube->SetZLength (depth);
00129
00130 vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
00131 tf->SetTransform (t);
00132 tf->SetInputConnection (cube->GetOutputPort ());
00133
00134 return (tf->GetOutput ());
00135 }
00136
00138 vtkSmartPointer<vtkDataSet>
00139 pcl::visualization::createCube (double x_min, double x_max,
00140 double y_min, double y_max,
00141 double z_min, double z_max)
00142 {
00143 vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
00144
00145 vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New ();
00146 cube->SetBounds (x_min, x_max, y_min, y_max, z_min, z_max);
00147
00148 return (cube->GetOutput ());
00149 }
00150
00152 vtkSmartPointer<vtkDataSet>
00153 pcl::visualization::createLine (const pcl::ModelCoefficients &coefficients)
00154 {
00155 vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New ();
00156 line->SetPoint1 (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
00157 line->SetPoint2 (coefficients.values[3] + coefficients.values[0],
00158 coefficients.values[4] + coefficients.values[1],
00159 coefficients.values[5] + coefficients.values[2]);
00160 line->Update ();
00161
00162 return (line->GetOutput ());
00163 }
00164
00166 vtkSmartPointer<vtkDataSet>
00167 pcl::visualization::createPlane (const pcl::ModelCoefficients &coefficients)
00168 {
00169 vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
00170 plane->SetNormal (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
00171
00172 double norm_sqr = coefficients.values[0] * coefficients.values[0]
00173 + coefficients.values[1] * coefficients.values[1]
00174 + coefficients.values[2] * coefficients.values[2];
00175
00176 plane->Push (-coefficients.values[3] / sqrt(norm_sqr));
00177 return (plane->GetOutput ());
00178 }
00179
00181 vtkSmartPointer<vtkDataSet>
00182 pcl::visualization::createPlane (const pcl::ModelCoefficients &coefficients, double x, double y, double z)
00183 {
00184 vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
00185
00186
00187 double norm_sqr = 1.0 / (coefficients.values[0] * coefficients.values[0] +
00188 coefficients.values[1] * coefficients.values[1] +
00189 coefficients.values[2] * coefficients.values[2] );
00190
00191
00192
00193
00194
00195
00196
00197 plane->SetNormal (coefficients.values[0], coefficients.values[1], coefficients.values[2]);
00198
00199 double t = x * coefficients.values[0] + y * coefficients.values[1] + z * coefficients.values[2] + coefficients.values[3];
00200 x -= coefficients.values[0] * t * norm_sqr;
00201 y -= coefficients.values[1] * t * norm_sqr;
00202 z -= coefficients.values[2] * t * norm_sqr;
00203 plane->SetCenter (x, y, z);
00204
00205 return (plane->GetOutput ());
00206 }
00207
00208
00210 vtkSmartPointer<vtkDataSet>
00211 pcl::visualization::create2DCircle (const pcl::ModelCoefficients &coefficients, double z)
00212 {
00213 vtkSmartPointer<vtkDiskSource> disk = vtkSmartPointer<vtkDiskSource>::New ();
00214
00215 disk->SetCircumferentialResolution (100);
00216 disk->SetInnerRadius (coefficients.values[2] - 0.001);
00217 disk->SetOuterRadius (coefficients.values[2] + 0.001);
00218 disk->SetCircumferentialResolution (20);
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
00234 t->Identity ();
00235 t->Translate (coefficients.values[0], coefficients.values[1], z);
00236
00237 vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
00238 tf->SetTransform (t);
00239 tf->SetInputConnection (disk->GetOutputPort ());
00240
00241
00242
00243
00244 return (tf->GetOutput ());
00245 }
00246
00248 vtkSmartPointer<vtkDataSet>
00249 pcl::visualization::createCone (const pcl::ModelCoefficients &coefficients)
00250 {
00251 vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New ();
00252 cone->SetHeight (1.0);
00253 cone->SetCenter (coefficients.values[0] + coefficients.values[3] * 0.5,
00254 coefficients.values[1] + coefficients.values[1] * 0.5,
00255 coefficients.values[2] + coefficients.values[2] * 0.5);
00256 cone->SetDirection (-coefficients.values[3], -coefficients.values[4], -coefficients.values[5]);
00257 cone->SetResolution (100);
00258 cone->SetAngle (coefficients.values[6]);
00259
00260 return (cone->GetOutput ());
00261 }
00262
00264 vtkSmartPointer<vtkDataSet>
00265 pcl::visualization::createSphere (const Eigen::Vector4f ¢er, double radius, int res)
00266 {
00267
00268 vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New ();
00269 t->Identity ();
00270 t->Translate (center[0], center[1], center[2]);
00271
00272 vtkSmartPointer<vtkSphereSource> s_sphere = vtkSmartPointer<vtkSphereSource>::New ();
00273 s_sphere->SetRadius (radius);
00274 s_sphere->SetPhiResolution (res);
00275 s_sphere->SetThetaResolution (res);
00276 s_sphere->LatLongTessellationOff ();
00277
00278 vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New ();
00279 tf->SetTransform (t);
00280 tf->SetInputConnection (s_sphere->GetOutputPort ());
00281 tf->Update ();
00282
00283 return (tf->GetOutput ());
00284 }
00285
00287 vtkSmartPointer<vtkDataSet>
00288 pcl::visualization::createLine (const Eigen::Vector4f &pt1, const Eigen::Vector4f &pt2)
00289 {
00290 vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New ();
00291 line->SetPoint1 (pt1.x (), pt1.y (), pt1.z ());
00292 line->SetPoint2 (pt2.x (), pt2.y (), pt2.z ());
00293 line->Update ();
00294
00295 return (line->GetOutput ());
00296 }
00298 void
00299 pcl::visualization::allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata)
00300 {
00301 polydata = vtkSmartPointer<vtkUnstructuredGrid>::New ();
00302 }
00303
00304