202 if(number_of_beams < 10 || number_of_bins < 10 || horizontal_resolution < 0||
203 horizontal_resolution > M_PI*0.3 || distance_resolution < 0.01 || vertical_resolution > M_PI*0.45)
204 throw std::runtime_error(
"invalid configuration");
206 renderer->RemoveAllViewProps();
207 sonar_wireframe->ReleaseData();
208 sonar_wireframe->RemoveAllObservers();
210 sonar_mapper.clear();
211 sonar_filter.clear();
215 sonar_wireframe = vtkSmartPointer<vtkStructuredGrid>::New();
217 this->number_of_beams = number_of_beams;
218 this->number_of_bins = number_of_bins;
221 this->horizontal_resolution = horizontal_resolution;
222 this->vertical_resolution = vertical_resolution;
223 this->distance_resolution = distance_resolution;
225 int missing = number_of_beams - sonar_data.size();
226 for(;missing > 0 ;--missing)
228 sonar_data.push_back(vtkSmartPointer<vtkUnsignedCharArray>::New());
229 sonar_grid.push_back(vtkSmartPointer<vtkStructuredGrid>::New());
232 std::vector<vtkSmartPointer<vtkStructuredGrid> >::iterator iter = sonar_grid.begin();
233 std::vector<vtkSmartPointer<vtkUnsignedCharArray> >::iterator iter2 = sonar_data.begin();
234 for(
float val=0;iter != sonar_grid.end();val+=horizontal_resolution, ++iter,++iter2)
236 setUpStructuredGrid(*iter,2,number_of_bins+1,horizontal_resolution,distance_resolution,vertical_resolution,val);
237 void *p = (*iter2)->WriteVoidPointer(0,number_of_bins);
238 memset(p,0,number_of_bins);
239 (*iter)->GetCellData()->SetScalars(*iter2);
240 (*iter2)->Modified();
245 setUpStructuredGrid(sonar_wireframe,25,number_of_bins*distance_resolution*0.5,15.0/180.0*M_PI,2,vertical_resolution);
249 vtkLookupTable *lut = vtkLookupTable::New();
250 lut->SetNumberOfColors(255);
251 lut->SetHueRange(0.55,1);
252 lut->SetValueRange(1,1.0);
253 lut->SetSaturationRange(1,1.0);
254 lut->SetTableRange(0,255);
256 iter = sonar_grid.begin();
257 for(;iter != sonar_grid.end(); ++iter)
259 vtkSmartPointer<vtkStructuredGridGeometryFilter> filter = vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
260 filter->SetInputConnection((*iter)->GetProducerPort());
261 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
262 mapper->SetInputConnection(filter->GetOutputPort());
263 mapper->SetLookupTable(lut);
264 mapper->UseLookupTableScalarRangeOn();
265 mapper->SetColorModeToMapScalars();
268 vtkSmartPointer<vtkActor> sonar_grid_actor = vtkSmartPointer<vtkActor>::New();
269 sonar_grid_actor->SetMapper(mapper);
272 sonar_filter.push_back(filter);
273 sonar_mapper.push_back(mapper);
274 sonar_actor.push_back(sonar_grid_actor);
276 renderer->AddActor(sonar_grid_actor);
281 vtkDataSetMapper *set_mapper = vtkDataSetMapper::New();
282 set_mapper->SetInputConnection(sonar_wireframe->GetProducerPort());
283 set_mapper->ScalarVisibilityOff();
285 vtkSmartPointer<vtkActor> wireframe_actor = vtkSmartPointer<vtkActor>::New();
286 wireframe_actor->SetMapper(set_mapper);
287 wireframe_actor->GetProperty()->SetColor(0.5,0.5,0.5);
288 wireframe_actor->GetProperty()->SetRepresentationToWireframe();
289 wireframe_actor->GetProperty()->SetLineWidth(1.2);
290 wireframe_actor->PickableOff();
291 wireframe_actor->SetPosition(0,0,0.1);
292 set_mapper->Delete();
294 renderer->AddActor(wireframe_actor);
297 plot_actor->ExchangeAxesOff();
298 plot_actor->SetXValuesToValue();
299 plot_actor->SetWidth(0.9);
300 plot_actor->SetXTitle(
"");
301 plot_actor->SetYTitle(
"");
302 plot_actor->SetHeight(0.50);
303 plot_actor->SetPosition(0.04,0);
304 plot_actor->PlotPointsOn();
305 plot_actor->PlotLinesOn();
306 plot_actor->SetVisibility(
false);
307 renderer->AddActor(plot_actor);
void setUpStructuredGrid(vtkSmartPointer< vtkStructuredGrid > sgrid, int number_of_beams, int number_of_bins, float horizontal_resolution, float distance_resolution, float vertical_resolution, float start_angle=0)