void vtkInteractorStyleQuench::ResetView() { double viewUp[3], focalpt[3],position[3]; FindPokedRenderer(0,0); vtkCamera *camera = this->CurrentRenderer->GetActiveCamera(); camera->GetViewUp(viewUp); camera->GetFocalPoint(focalpt); camera->GetPosition(position); int idx=0; double rad=0; for(int i = 0; i < 3; i++) { position[i]-=focalpt[i]; rad+=position[i]*position[i]; } rad = sqrt(rad); position[0]/=rad; position[1]/=rad; position[2]/=rad; AlignToAxis(viewUp); idx=AlignToAxis(position); position[idx]*=rad; camera->SetViewUp(viewUp); camera->SetPosition(position); CurrentRenderer->GetRenderWindow()->Render(); }
void vtkInteractorStyleQuench::Init(SceneWindow *_pSceneWindow) { // _editing_voi = false; _interaction_mode = INTERACTION_IDLE; // connect the render window and wxVTK window _pSceneWindow->SetInteractorStyle(this); vtkRenderWindow *pRenderWindow = _pSceneWindow->GetRenderWindow(); _renderer = vtkRenderer::New(); pRenderWindow->AddRenderer(_renderer); pRenderWindow->LineSmoothingOff(); pRenderWindow->PolygonSmoothingOff(); pRenderWindow->SetAAFrames(0); pRenderWindow->SetSize(200,200); vtkCamera *camera = vtkCamera::New(); _renderer->SetActiveCamera(camera); camera->Delete(); FindPokedRenderer(0,0); CurrentRenderer->SetBackground(0.74, 0.74, 0.66); _volViz = new qVolumeViz(_renderer); _pathwayViz = new qPathwayViz(_renderer); _voiViz = new qROIViz(_renderer); _GestureInteractor = new qGestureInteractor(_renderer); _voiEditor = new qROIEditor(_renderer, _volViz); pp = vtkWorldPointPicker :: New(); _voiEditor->SetEditingROIMode(false); }
void vtkInteractorStyleQuench::OnRightButtonUp() { _interaction_mode = INTERACTION_IDLE; _right_button_down = 0; if(State == VTKIS_DOLLY) EndDolly(); // check if the timer is running if(IsRunning() == false) return; // Stop the timer Stop(); FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); _mousedown_x = Interactor->GetEventPosition()[0]; _mousedown_y = abs(Interactor->GetEventPosition()[1]); if(_pathwayViz->OnRightButtonUp(_mousedown_x, _mousedown_y)) return ; if(_voiViz->OnRightButton(_mousedown_x, _mousedown_y)) return; if(_volViz->OnRightButtonUp(_mousedown_x, _mousedown_y)) return ; }
void pcl::visualization::PCLHistogramVisualizerInteractorStyle::OnKeyDown () { if (!init_) { pcl::console::print_error ("[PCLHistogramVisualizerInteractorStyle] Interactor style not initialized. Please call Initialize () before continuing.\n"); return; } FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); //fprintf (stderr, "Key sym: %s\n", Interactor->GetKeySym ()); // ---[ Check the rest of the key codes switch (Interactor->GetKeyCode ()) { case 'q': case 'Q': { Interactor->ExitCallback (); return; } // Switch representation to wireframe default: { Superclass::OnKeyDown (); } } Interactor->Render (); }
void vtkInteractorStyleQuench::OnRightButtonDown() { _mouse_moved = false; _right_button_down = 1; wxCommandEvent nullEvent; FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); if (CurrentRenderer == NULL) return; _mousedown_x = Interactor->GetEventPosition()[0]; _mousedown_y = abs(Interactor->GetEventPosition()[1]); //cerr << "here" << endl; if (_voiEditor->GetEditingROIMode() && _voiEditor->ClickInsideTomogram(_mousedown_x, _mousedown_y)) { _voiEditor->OnRightDown(_mousedown_x, _mousedown_y); _interaction_mode = INTERACTION_ROI_EDIT; return; } Start( 100 ); //if(-1==_Scene->GetPathwayViz()->ProcessRightButtonDown(mousedown_x,mousedown_y)) //StartDolly(); //else // frame->OnScorePanelToggle(nullEvent); }
bool pcl::visualization::PCLVisualizerInteractorStyle::saveCameraParameters (const std::string &file) { FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); ofstream ofs_cam (file.c_str ()); if (!ofs_cam.is_open ()) { return (false); } vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera (); double clip[2], focal[3], pos[3], view[3]; cam->GetClippingRange (clip); cam->GetFocalPoint (focal); cam->GetPosition (pos); cam->GetViewUp (view); int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); int *win_size = Interactor->GetRenderWindow ()->GetSize (); ofs_cam << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" << pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" << cam->GetViewAngle () / 180.0 * M_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] << endl; ofs_cam.close (); return (true); }
void vtkInteractorStyleQuench::OnMiddleButtonDown() { _mouse_moved = false; FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); if (CurrentRenderer == NULL) return; StartPan(); }
void cv::viz::InteractorStyle::zoomOut() { FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); // Zoom out StartDolly(); double factor = 10.0 * -0.2 * .5; Dolly(std::pow(1.1, factor)); EndDolly(); }
void pcl::visualization::PCLVisualizerInteractorStyle::zoomOut () { FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); // Zoom out StartDolly (); double factor = 10.0 * -0.2 * .5; Dolly (pow (1.1, factor)); EndDolly (); }
void pcl::visualization::PCLVisualizerInteractorStyle::saveScreenshot (const std::string &file) { FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); wif_->SetInput (Interactor->GetRenderWindow ()); wif_->Modified (); // Update the WindowToImageFilter snapshot_writer_->Modified (); snapshot_writer_->SetFileName (file.c_str ()); snapshot_writer_->Write (); }
void cv::viz::InteractorStyle::saveScreenshot(const String &file) { FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); vtkSmartPointer<vtkWindowToImageFilter> wif = vtkSmartPointer<vtkWindowToImageFilter>::New(); wif->SetInput(Interactor->GetRenderWindow()); vtkSmartPointer<vtkPNGWriter> snapshot_writer = vtkSmartPointer<vtkPNGWriter>::New(); snapshot_writer->SetInputConnection(wif->GetOutputPort()); snapshot_writer->SetFileName(file.c_str()); snapshot_writer->Write(); cout << "Screenshot successfully captured (" << file.c_str() << ")" << endl; }
void cv::viz::InteractorStyle::OnChar() { // Make sure we ignore the same events we handle in OnKeyDown to avoid calling things twice FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); if (Interactor->GetKeyCode() >= '0' && Interactor->GetKeyCode() <= '9') return; String key(Interactor->GetKeySym()); if (key.find("XF86ZoomIn") != String::npos) zoomIn(); else if (key.find("XF86ZoomOut") != String::npos) zoomOut(); int keymod = Interactor->GetAltKey(); switch (Interactor->GetKeyCode()) { // All of the options below simply exit case 'h': case 'H': case 'l': case 'L': case 'p': case 'P': case 'j': case 'J': case 'c': case 'C': case 43: // KEY_PLUS case 45: // KEY_MINUS case 'f': case 'F': case 'g': case 'G': case 'o': case 'O': case 'u': case 'U': case 'q': case 'Q': { break; } // S and R have a special !ALT case case 'r': case 'R': case 's': case 'S': { if (!keymod) Superclass::OnChar(); break; } default: { Superclass::OnChar(); break; } } }
void pcl::visualization::PCLVisualizerInteractorStyle::getCameraParameters (pcl::visualization::Camera &camera) { FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera (); cam->GetClippingRange (camera.clip); cam->GetFocalPoint (camera.focal); cam->GetPosition (camera.pos); cam->GetViewUp (camera.view); camera.fovy = cam->GetViewAngle () / 180.0 * M_PI; int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); int *win_size = Interactor->GetRenderWindow ()->GetSize (); camera.window_pos[0] = win_pos[0]; camera.window_pos[1] = win_pos[1]; camera.window_size[0] = win_size[0]; camera.window_size[1] = win_size[1]; }
void vtkInteractorStyleQuench::OnLeftButtonDown() { _mouse_moved = false; _left_button_down=1; FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); _mousedown_x = this->Interactor->GetEventPosition()[0]; _mousedown_y = abs(this->Interactor->GetEventPosition()[1]); if(_voiEditor->GetEditingROIMode() && _voiEditor->ClickInsideTomogram(_mousedown_x, _mousedown_y)) { _voiEditor->OnLeftDown(_mousedown_x, _mousedown_y); _interaction_mode = INTERACTION_ROI_EDIT; return; } if(_pathwayViz->OnLeftDown(_mousedown_x, _mousedown_y)) { _interaction_mode = INTERACTION_PATHWAYS; return; } if (this->Interactor->GetControlKey() || ((wxVTKRenderWindowInteractor*)Interactor)->bCmdDwn) { _GestureInteractor->BeginSelect(_mousedown_x, _mousedown_y); //NotifyAllListeners(PEvent ( new EventRefreshViz(true) ) ); //_renderer->GetRenderWindow()->Render(); _interaction_mode = INTERACTION_DRAW_GESTURE; return; } // xxxdla trying to fix bug with interactions //if( _voiViz->OnLeftDown(_mousedown_x, _mousedown_y) ) // return ; Interactor->GetShiftKey()?StartPan():StartRotate(); }
void vtkInteractorStyleQuench::Serialize(std::ostream &myStream, int version) { // Bogus renderer poke just to get the current renderer FindPokedRenderer(0,0); // Save Camera double pos[3]; double viewup[3]; double focalpt[3]; vtkCamera *camera = CurrentRenderer->GetActiveCamera(); camera->GetPosition(pos); camera->GetViewUp(viewup); camera->GetFocalPoint(focalpt); // Save camera state myStream << "Camera Position: " << pos[0] << "," << pos[1] << "," << pos[2] << std::endl; myStream << "Camera View Up: " << viewup[0] << "," << viewup[1] << "," << viewup[2] << std::endl; myStream << "Camera Focal Point: " << focalpt[0] << "," << focalpt[1] << "," << focalpt[2] << std::endl; _voiViz ->Serialize(myStream, version); _volViz ->Serialize(myStream, version); _pathwayViz->Serialize(myStream, version); }
void vtkInteractorStyleQuench::Deserialize(istream &myStream, int version) { // Restore the entire state of the system. double pos[3]; double viewup[3]; double focalpt[3]; // Restore Camera GetQStateVector3<double>(myStream,pos); // Camera Position GetQStateVector3<double>(myStream,viewup); // Camera View Up GetQStateVector3<double>(myStream,focalpt); // Camera Focal Pt. // Bogus renderer poke just to get the current renderer FindPokedRenderer(0,0); vtkCamera *camera = CurrentRenderer->GetActiveCamera(); camera->SetPosition(pos); camera->SetViewUp(viewup); camera->SetFocalPoint(focalpt); camera->ComputeViewPlaneNormal(); _voiViz ->Deserialize(myStream, version); _volViz ->Deserialize(myStream, version); _pathwayViz ->Deserialize(myStream, version); //// DTIPathwayAssignment *assignment = new DTIPathwayAssignment (this->whole_database->getNumFibers(), DTI_COLOR_UNASSIGNED); //// for (int i = 0; i < this->whole_database->getNumFibers(); i++) { //// int val; //// myStream >> val; //// assignment->setValue(i, (DTIPathwayGroupID) val); //// } //// SetAssignment (assignment); //// this->frame->AssignmentMade(assignment); //// // Must do this in case the border was being displayed in the scene before we restore //// // has nothing to do with the saved border condition //// if(this->TomoBorderActor!=NULL) //// DisplayTomoBorder(this->TomoBorderActor->GetVisibility()); // //// // Restore query filter op // //// setFilterOp ((DTIQueryOperation) filterOp); //// _query_processor->setROIFilter (filter_qString); // //// this->SetScenePathways(); //// myStream.close(); //// redraw(); // //// _camera_interpolator = vtkCameraInterpolator::New(); //// _camera_interpolator->SetInterpolationType (vtkCameraInterpolator::INTERPOLATION_TYPE_SPLINE); //// _camera_interpolator->AddCamera (0, camera); //// vtkCamera *destinationCamera = vtkCamera::New(); //// unsigned int dim[4]; //// double voxSize[3]; // //// GetCurrentBackground()->getDimension (dim[0], dim[1], dim[2], dim[3]); //// GetCurrentBackground()->getVoxelSize (voxSize[0], voxSize[1], voxSize[2]); //// float center[3] = {0, -15, 5}; //center not at AC, but rather at center of //// // typical brain (#'s are in mm) //// // center[0] = dim[0]*voxSize[0]*0.5; //// // center[1] = dim[1]*voxSize[1]*0.5; //// // center[2] = dim[2]*voxSize[2]*0.5; // //// destinationCamera->SetViewUp (0, 0, 1); // //// destinationCamera->SetPosition (center[0] + dim[0]*voxSize[0]*(3), //// center[1], //// center[2]); // //// destinationCamera->SetFocalPoint (center[0],center[1],center[2]); //// destinationCamera->ComputeViewPlaneNormal(); //// destinationCamera->Modified(); //// //camera_controls->NextPosition (destinationCamera, dim, voxSize); //// // camera_controls->NextPosition (destinationCamera, dim, voxSize); //// // camera_controls->NextPosition (destinationCamera, dim, voxSize); //// _camera_interpolator->AddCamera (1, destinationCamera); }
void cv::viz::InteractorStyle::OnKeyDown() { CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_); FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); // Save the initial windows width/height if (win_size_[0] == -1 || win_size_[1] == -1) win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize()); bool alt = Interactor->GetAltKey() != 0; std::string key(Interactor->GetKeySym()); if (key.find("XF86ZoomIn") != std::string::npos) zoomIn(); else if (key.find("XF86ZoomOut") != std::string::npos) zoomOut(); switch (Interactor->GetKeyCode()) { case 'h': case 'H': { std::cout << "| Help:\n" "-------\n" " p, P : switch to a point-based representation\n" " w, W : switch to a wireframe-based representation (where available)\n" " s, S : switch to a surface-based representation (where available)\n" "\n" " j, J : take a .PNG snapshot of the current window view\n" " k, K : export scene to Wavefront .obj format\n" " ALT + k, K : export scene to VRML format\n" " c, C : display current camera/window parameters\n" " f, F : fly to point mode, hold the key and move mouse where to fly\n" "\n" " e, E : exit the interactor\n" " q, Q : stop and call VTK's TerminateApp\n" "\n" " +/- : increment/decrement overall point size\n" " +/- [+ ALT] : zoom in/out \n" "\n" " r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n" "\n" " ALT + s, S : turn stereo mode on/off\n" " ALT + f, F : switch between maximized window mode and original size\n" "\n" << std::endl; break; } // Switch representation to points case 'p': case 'P': { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); apart->GetProperty()->SetRepresentationToPoints(); } break; } // Save a PNG snapshot case 'j': case 'J': saveScreenshot(cv::format("screenshot-%d.png", (unsigned int)time(0))); break; // Export scene as in obj or vrml format case 'k': case 'K': { String format = alt ? "scene-%d.vrml" : "scene-%d"; exportScene(cv::format(format.c_str(), (unsigned int)time(0))); break; } // display current camera settings/parameters case 'c': case 'C': { vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera(); Vec2d clip(cam->GetClippingRange()); Vec3d focal(cam->GetFocalPoint()), pos(cam->GetPosition()), view(cam->GetViewUp()); Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition()); Vec2i win_size(Interactor->GetRenderWindow()->GetSize()); double angle = cam->GetViewAngle () / 180.0 * CV_PI; String data = cv::format("clip(%f,%f) focal(%f,%f,%f) pos(%f,%f,%f) view(%f,%f,%f) angle(%f) winsz(%d,%d) winpos(%d,%d)", clip[0], clip[1], focal[0], focal[1], focal[2], pos[0], pos[1], pos[2], view[0], view[1], view[2], angle, win_size[0], win_size[1], win_pos[0], win_pos[1]); std::cout << data.c_str() << std::endl; break; } case '=': { zoomIn(); break; } case 43: // KEY_PLUS { if (alt) zoomIn(); else { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); float psize = apart->GetProperty()->GetPointSize(); if (psize < 63.0f) apart->GetProperty()->SetPointSize(psize + 1.0f); } } break; } case 45: // KEY_MINUS { if (alt) zoomOut(); else { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); float psize = apart->GetProperty()->GetPointSize(); if (psize > 1.0f) apart->GetProperty()->SetPointSize(psize - 1.0f); } } break; } // Switch between maximize and original window size case 'f': case 'F': { if (alt) { Vec2i screen_size(Interactor->GetRenderWindow()->GetScreenSize()); Vec2i win_size(Interactor->GetRenderWindow()->GetSize()); // Is window size = max? if (win_size == max_win_size_) { Interactor->GetRenderWindow()->SetSize(win_size_.val); Interactor->GetRenderWindow()->SetPosition(win_pos_.val); Interactor->GetRenderWindow()->Render(); Interactor->Render(); } // Set to max else { win_pos_ = Vec2i(Interactor->GetRenderWindow()->GetPosition()); win_size_ = win_size; Interactor->GetRenderWindow()->SetSize(screen_size.val); Interactor->GetRenderWindow()->Render(); Interactor->Render(); max_win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize()); } } else { AnimState = VTKIS_ANIM_ON; Interactor->GetPicker()->Pick(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1], 0.0, CurrentRenderer); vtkSmartPointer<vtkAbstractPropPicker> picker = vtkAbstractPropPicker::SafeDownCast(Interactor->GetPicker()); if (picker) if (picker->GetPath()) Interactor->FlyTo(CurrentRenderer, picker->GetPickPosition()); AnimState = VTKIS_ANIM_OFF; } break; } // 's'/'S' w/out ALT case 's': case 'S': { if (alt) { vtkSmartPointer<vtkRenderWindow> window = Interactor->GetRenderWindow(); if (!window->GetStereoRender()) { static Vec2i red_blue(4, 3), magenta_green(2, 5); window->SetAnaglyphColorMask (stereo_anaglyph_mask_default_ ? red_blue.val : magenta_green.val); stereo_anaglyph_mask_default_ = !stereo_anaglyph_mask_default_; } window->SetStereoRender(!window->GetStereoRender()); Interactor->Render(); } else Superclass::OnKeyDown(); break; } case 'o': case 'O': { vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera(); cam->SetParallelProjection(!cam->GetParallelProjection()); CurrentRenderer->Render(); break; } // Overwrite the camera reset case 'r': case 'R': { if (!alt) { Superclass::OnKeyDown(); break; } WidgetActorMap::iterator it = widget_actor_map_->begin(); // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault. for (; it != widget_actor_map_->end(); ++it) { vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); if (actor && actor->GetUserMatrix()) break; } vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera(); // if a valid transformation was found, use it otherwise fall back to default view point. if (it != widget_actor_map_->end()) { vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix(); cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2), m->GetElement(1, 3) - m->GetElement(1, 2), m->GetElement(2, 3) - m->GetElement(2, 2)); cam->SetViewUp (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1)); cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3)); } else { cam->SetPosition(0, 0, 0); cam->SetFocalPoint(0, 0, 1); cam->SetViewUp(0, -1, 0); } // go to the next actor for the next key-press event. if (it != widget_actor_map_->end()) ++it; else it = widget_actor_map_->begin(); CurrentRenderer->SetActiveCamera(cam); CurrentRenderer->ResetCameraClippingRange(); CurrentRenderer->Render(); break; } case 'q': case 'Q': { Interactor->ExitCallback(); return; } default: { Superclass::OnKeyDown(); break; } } KeyboardEvent event(KeyboardEvent::KEY_DOWN, Interactor->GetKeySym(), Interactor->GetKeyCode(), getModifiers()); if (keyboardCallback_) keyboardCallback_(event, keyboard_callback_cookie_); Interactor->Render(); }
void vtkInteractorStyleQuench::OnMouseWheelForward() { FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); _volViz->MoveActiveImage( 1); NotifyAllListeners(PEvent ( new Event(UPDATE_SURFACE_MODE_GEOMETRY) )); }
void pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown () { if (!init_) { pcl::console::print_error ("[PCLVisualizerInteractorStyle] Interactor style not initialized. Please call Initialize () before continuing.\n"); return; } if (!rens_) { pcl::console::print_error ("[PCLVisualizerInteractorStyle] No renderer collection given! Use SetRendererCollection () before continuing.\n"); return; } FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); if (wif_->GetInput () == NULL) { wif_->SetInput (Interactor->GetRenderWindow ()); wif_->Modified (); snapshot_writer_->Modified (); } // Save the initial windows width/height if (win_height_ == -1 || win_width_ == -1) { int *win_size = Interactor->GetRenderWindow ()->GetSize (); win_height_ = win_size[0]; win_width_ = win_size[1]; } // Get the status of special keys (Cltr+Alt+Shift) bool shift = Interactor->GetShiftKey (); bool ctrl = Interactor->GetControlKey (); bool alt = Interactor->GetAltKey (); bool keymod = false; switch (modifier_) { case INTERACTOR_KB_MOD_ALT: { keymod = alt; break; } case INTERACTOR_KB_MOD_CTRL: { keymod = ctrl; break; } case INTERACTOR_KB_MOD_SHIFT: { keymod = shift; break; } } // ---[ Check the rest of the key codes // Switch between point color/geometry handlers if (Interactor->GetKeySym () && Interactor->GetKeySym ()[0] >= '0' && Interactor->GetKeySym ()[0] <= '9') { CloudActorMap::iterator it; int index = Interactor->GetKeySym ()[0] - '0' - 1; if (index == -1) index = 9; // Add 10 more for CTRL+0..9 keys if (ctrl) index += 10; // Geometry ? if (keymod) { for (it = actors_->begin (); it != actors_->end (); ++it) { CloudActor *act = &(*it).second; if (index >= static_cast<int> (act->geometry_handlers.size ())) continue; // Save the geometry handler index for later usage act->geometry_handler_index_ = index; // Create the new geometry PointCloudGeometryHandler<sensor_msgs::PointCloud2>::ConstPtr geometry_handler = act->geometry_handlers[index]; // Use the handler to obtain the geometry vtkSmartPointer<vtkPoints> points; geometry_handler->getGeometry (points); // Set the vertices vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New (); for (vtkIdType i = 0; i < static_cast<vtkIdType> (points->GetNumberOfPoints ()); ++i) vertices->InsertNextCell (static_cast<vtkIdType>(1), &i); // Create the data vtkSmartPointer<vtkPolyData> data = vtkSmartPointer<vtkPolyData>::New (); data->SetPoints (points); data->SetVerts (vertices); // Modify the mapper if (use_vbos_) { vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ()); mapper->SetInput (data); // Modify the actor act->actor->SetMapper (mapper); } else { vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ()); mapper->SetInput (data); // Modify the actor act->actor->SetMapper (mapper); } act->actor->Modified (); } } else { for (it = actors_->begin (); it != actors_->end (); ++it) { CloudActor *act = &(*it).second; // Check for out of bounds if (index >= static_cast<int> (act->color_handlers.size ())) continue; // Save the color handler index for later usage act->color_handler_index_ = index; // Get the new color PointCloudColorHandler<sensor_msgs::PointCloud2>::ConstPtr color_handler = act->color_handlers[index]; vtkSmartPointer<vtkDataArray> scalars; color_handler->getColor (scalars); double minmax[2]; scalars->GetRange (minmax); // Update the data vtkPolyData *data = static_cast<vtkPolyData*>(act->actor->GetMapper ()->GetInput ()); data->GetPointData ()->SetScalars (scalars); data->Update (); // Modify the mapper if (use_vbos_) { vtkVertexBufferObjectMapper* mapper = static_cast<vtkVertexBufferObjectMapper*>(act->actor->GetMapper ()); mapper->SetScalarRange (minmax); mapper->SetScalarModeToUsePointData (); mapper->SetInput (data); // Modify the actor act->actor->SetMapper (mapper); } else { vtkPolyDataMapper* mapper = static_cast<vtkPolyDataMapper*>(act->actor->GetMapper ()); mapper->SetScalarRange (minmax); mapper->SetScalarModeToUsePointData (); mapper->SetInput (data); // Modify the actor act->actor->SetMapper (mapper); } act->actor->Modified (); } } Interactor->Render (); return; } std::string key (Interactor->GetKeySym ()); if (key.find ("XF86ZoomIn") != std::string::npos) zoomIn (); else if (key.find ("XF86ZoomOut") != std::string::npos) zoomOut (); switch (Interactor->GetKeyCode ()) { case 'h': case 'H': { pcl::console::print_info ("| Help:\n" "-------\n" " p, P : switch to a point-based representation\n" " w, W : switch to a wireframe-based representation (where available)\n" " s, S : switch to a surface-based representation (where available)\n" "\n" " j, J : take a .PNG snapshot of the current window view\n" " c, C : display current camera/window parameters\n" " f, F : fly to point mode\n" "\n" " e, E : exit the interactor\n" " q, Q : stop and call VTK's TerminateApp\n" "\n" " +/- : increment/decrement overall point size\n" " +/- [+ ALT] : zoom in/out \n" "\n" " g, G : display scale grid (on/off)\n" " u, U : display lookup table (on/off)\n" "\n" " r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n" "\n" " ALT + s, S : turn stereo mode on/off\n" " ALT + f, F : switch between maximized window mode and original size\n" "\n" " l, L : list all available geometric and color handlers for the current actor map\n" " ALT + 0..9 [+ CTRL] : switch between different geometric handlers (where available)\n" " 0..9 [+ CTRL] : switch between different color handlers (where available)\n" "\n" " SHIFT + left click : select a point\n" ); break; } // Get the list of available handlers case 'l': case 'L': { // Iterate over the entire actors list and extract the geomotry/color handlers list for (CloudActorMap::iterator it = actors_->begin (); it != actors_->end (); ++it) { std::list<std::string> geometry_handlers_list, color_handlers_list; CloudActor *act = &(*it).second; for (size_t i = 0; i < act->geometry_handlers.size (); ++i) geometry_handlers_list.push_back (act->geometry_handlers[i]->getFieldName ()); for (size_t i = 0; i < act->color_handlers.size (); ++i) color_handlers_list.push_back (act->color_handlers[i]->getFieldName ()); if (!geometry_handlers_list.empty ()) { int i = 0; pcl::console::print_info ("List of available geometry handlers for actor "); pcl::console::print_value ("%s: ", (*it).first.c_str ()); for (std::list<std::string>::iterator git = geometry_handlers_list.begin (); git != geometry_handlers_list.end (); ++git) pcl::console::print_value ("%s(%d) ", (*git).c_str (), ++i); pcl::console::print_info ("\n"); } if (!color_handlers_list.empty ()) { int i = 0; pcl::console::print_info ("List of available color handlers for actor "); pcl::console::print_value ("%s: ", (*it).first.c_str ()); for (std::list<std::string>::iterator cit = color_handlers_list.begin (); cit != color_handlers_list.end (); ++cit) pcl::console::print_value ("%s(%d) ", (*cit).c_str (), ++i); pcl::console::print_info ("\n"); } } break; } // Switch representation to points case 'p': case 'P': { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors (); vtkCollectionSimpleIterator ait; for (ac->InitTraversal (ait); vtkActor* actor = ac->GetNextActor (ait); ) { for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) { vtkSmartPointer<vtkActor> apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ()); apart->GetProperty ()->SetRepresentationToPoints (); } } break; } // Save a PNG snapshot with the current screen case 'j': case 'J': { char cam_fn[80], snapshot_fn[80]; unsigned t = static_cast<unsigned> (time (0)); sprintf (snapshot_fn, "screenshot-%d.png" , t); saveScreenshot (snapshot_fn); sprintf (cam_fn, "screenshot-%d.cam", t); ofstream ofs_cam; ofs_cam.open (cam_fn); vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera (); double clip[2], focal[3], pos[3], view[3]; cam->GetClippingRange (clip); cam->GetFocalPoint (focal); cam->GetPosition (pos); cam->GetViewUp (view); int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); int *win_size = Interactor->GetRenderWindow ()->GetSize (); ofs_cam << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" << pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" << cam->GetViewAngle () / 180.0 * M_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] << endl; ofs_cam.close (); pcl::console::print_info ("Screenshot (%s) and camera information (%s) successfully captured.\n", snapshot_fn, cam_fn); break; } // display current camera settings/parameters case 'c': case 'C': { vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera (); double clip[2], focal[3], pos[3], view[3]; cam->GetClippingRange (clip); cam->GetFocalPoint (focal); cam->GetPosition (pos); cam->GetViewUp (view); int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); int *win_size = Interactor->GetRenderWindow ()->GetSize (); std::cerr << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" << pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" << cam->GetViewAngle () / 180.0 * M_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] << endl; break; } case '=': { zoomIn(); break; } case 43: // KEY_PLUS { if(alt) zoomIn (); else { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors (); vtkCollectionSimpleIterator ait; for (ac->InitTraversal (ait); vtkActor* actor = ac->GetNextActor (ait); ) { for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) { vtkSmartPointer<vtkActor> apart = reinterpret_cast <vtkActor*> (path->GetLastNode ()->GetViewProp ()); float psize = apart->GetProperty ()->GetPointSize (); if (psize < 63.0f) apart->GetProperty ()->SetPointSize (psize + 1.0f); } } } break; } case 45: // KEY_MINUS { if(alt) zoomOut (); else { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors (); vtkCollectionSimpleIterator ait; for (ac->InitTraversal (ait); vtkActor* actor = ac->GetNextActor (ait); ) { for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) { vtkSmartPointer<vtkActor> apart = static_cast<vtkActor*> (path->GetLastNode ()->GetViewProp ()); float psize = apart->GetProperty ()->GetPointSize (); if (psize > 1.0f) apart->GetProperty ()->SetPointSize (psize - 1.0f); } } } break; } // Switch between maximize and original window size case 'f': case 'F': { if (keymod) { // Get screen size int *temp = Interactor->GetRenderWindow ()->GetScreenSize (); int scr_size[2]; scr_size[0] = temp[0]; scr_size[1] = temp[1]; // Get window size temp = Interactor->GetRenderWindow ()->GetSize (); int win_size[2]; win_size[0] = temp[0]; win_size[1] = temp[1]; // Is window size = max? if (win_size[0] == max_win_height_ && win_size[1] == max_win_width_) { // Set the previously saved 'current' window size Interactor->GetRenderWindow ()->SetSize (win_height_, win_width_); // Set the previously saved window position Interactor->GetRenderWindow ()->SetPosition (win_pos_x_, win_pos_y_); Interactor->GetRenderWindow ()->Render (); Interactor->Render (); } // Set to max else { int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); // Save the current window position win_pos_x_ = win_pos[0]; win_pos_y_ = win_pos[1]; // Save the current window size win_height_ = win_size[0]; win_width_ = win_size[1]; // Set the maximum window size Interactor->GetRenderWindow ()->SetSize (scr_size[0], scr_size[1]); Interactor->GetRenderWindow ()->Render (); Interactor->Render (); int *win_size = Interactor->GetRenderWindow ()->GetSize (); // Save the maximum window size max_win_height_ = win_size[0]; max_win_width_ = win_size[1]; } } else { AnimState = VTKIS_ANIM_ON; vtkAssemblyPath *path = NULL; Interactor->GetPicker ()->Pick (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1], 0.0, CurrentRenderer); vtkAbstractPropPicker *picker; if ((picker = vtkAbstractPropPicker::SafeDownCast (Interactor->GetPicker ()))) path = picker->GetPath (); if (path != NULL) Interactor->FlyTo (CurrentRenderer, picker->GetPickPosition ()); AnimState = VTKIS_ANIM_OFF; } break; } // 's'/'S' w/out ALT case 's': case 'S': { if (keymod) { int stereo_render = Interactor->GetRenderWindow ()->GetStereoRender (); if (!stereo_render) { if (stereo_anaglyph_mask_default_) { Interactor->GetRenderWindow ()->SetAnaglyphColorMask (4, 3); stereo_anaglyph_mask_default_ = false; } else { Interactor->GetRenderWindow ()->SetAnaglyphColorMask (2, 5); stereo_anaglyph_mask_default_ = true; } } Interactor->GetRenderWindow ()->SetStereoRender (!stereo_render); Interactor->GetRenderWindow ()->Render (); Interactor->Render (); } else Superclass::OnKeyDown (); break; } // Display a grid/scale over the screen case 'g': case 'G': { if (!grid_enabled_) { grid_actor_->TopAxisVisibilityOn (); CurrentRenderer->AddViewProp (grid_actor_); grid_enabled_ = true; } else { CurrentRenderer->RemoveViewProp (grid_actor_); grid_enabled_ = false; } break; } case 'o': case 'O': { vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera (); int flag = cam->GetParallelProjection (); cam->SetParallelProjection (!flag); CurrentRenderer->SetActiveCamera (cam); CurrentRenderer->Render (); break; } // Display a LUT actor on screen case 'u': case 'U': { CloudActorMap::iterator it; for (it = actors_->begin (); it != actors_->end (); ++it) { CloudActor *act = &(*it).second; vtkScalarsToColors* lut = act->actor->GetMapper ()->GetLookupTable (); lut_actor_->SetLookupTable (lut); lut_actor_->Modified (); } if (!lut_enabled_) { CurrentRenderer->AddActor (lut_actor_); lut_actor_->SetVisibility (true); lut_enabled_ = true; } else { CurrentRenderer->RemoveActor (lut_actor_); lut_enabled_ = false; } CurrentRenderer->Render (); break; } // Overwrite the camera reset case 'r': case 'R': { if (!keymod) { Superclass::OnKeyDown (); break; } vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera (); static CloudActorMap::iterator it = actors_->begin (); // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault. bool found_transformation = false; for (unsigned idx = 0; idx < actors_->size (); ++idx, ++it) { if (it == actors_->end ()) it = actors_->begin (); const CloudActor& actor = it->second; if (actor.viewpoint_transformation_.GetPointer ()) { found_transformation = true; break; } } // if a valid transformation was found, use it otherwise fall back to default view point. if (found_transformation) { const CloudActor& actor = it->second; cam->SetPosition (actor.viewpoint_transformation_->GetElement (0, 3), actor.viewpoint_transformation_->GetElement (1, 3), actor.viewpoint_transformation_->GetElement (2, 3)); cam->SetFocalPoint (actor.viewpoint_transformation_->GetElement (0, 3) - actor.viewpoint_transformation_->GetElement (0, 2), actor.viewpoint_transformation_->GetElement (1, 3) - actor.viewpoint_transformation_->GetElement (1, 2), actor.viewpoint_transformation_->GetElement (2, 3) - actor.viewpoint_transformation_->GetElement (2, 2)); cam->SetViewUp (actor.viewpoint_transformation_->GetElement (0, 1), actor.viewpoint_transformation_->GetElement (1, 1), actor.viewpoint_transformation_->GetElement (2, 1)); } else { cam->SetPosition (0, 0, 0); cam->SetFocalPoint (0, 0, 1); cam->SetViewUp (0, -1, 0); } // go to the next actor for the next key-press event. if (it != actors_->end ()) ++it; else it = actors_->begin (); CurrentRenderer->SetActiveCamera (cam); CurrentRenderer->ResetCameraClippingRange (); CurrentRenderer->Render (); break; } case 'q': case 'Q': { Interactor->ExitCallback (); return; } default: { Superclass::OnKeyDown (); break; } } KeyboardEvent event (true, Interactor->GetKeySym (), Interactor->GetKeyCode (), Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); keyboard_signal_ (event); rens_->Render (); Interactor->Render (); }
void pcl::visualization::PCLVisualizerInteractorStyle::OnChar () { // Make sure we ignore the same events we handle in OnKeyDown to avoid calling things twice FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); if (Interactor->GetKeyCode () >= '0' && Interactor->GetKeyCode () <= '9') return; std::string key (Interactor->GetKeySym ()); if (key.find ("XF86ZoomIn") != std::string::npos) zoomIn (); else if (key.find ("XF86ZoomOut") != std::string::npos) zoomOut (); bool keymod = false; switch (modifier_) { case INTERACTOR_KB_MOD_ALT: { keymod = Interactor->GetAltKey (); break; } case INTERACTOR_KB_MOD_CTRL: { keymod = Interactor->GetControlKey (); break; } case INTERACTOR_KB_MOD_SHIFT: { keymod = Interactor->GetShiftKey (); break; } } switch (Interactor->GetKeyCode ()) { // All of the options below simply exit case 'h': case 'H': case 'l': case 'L': case 'p': case 'P': case 'j': case 'J': case 'c': case 'C': case 43: // KEY_PLUS case 45: // KEY_MINUS case 'f': case 'F': case 'g': case 'G': case 'o': case 'O': case 'u': case 'U': case 'q': case 'Q': { break; } // S and R have a special !ALT case case 'r': case 'R': case 's': case 'S': { if (!keymod) Superclass::OnChar (); break; } default: { Superclass::OnChar (); break; } } }