예제 #1
0
파일: roi.cpp 프로젝트: KimTranDong/mrtrix3
        void ROI::draw (const Projection& projection, bool is_3D, int, int)
        {
          if (is_3D) return;

          if (!is_3D) {
            // set up OpenGL environment:
            gl::Enable (gl::BLEND);
            gl::Disable (gl::DEPTH_TEST);
            gl::DepthMask (gl::FALSE_);
            gl::ColorMask (gl::TRUE_, gl::TRUE_, gl::TRUE_, gl::TRUE_);
            gl::BlendFunc (gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
            gl::BlendEquation (gl::FUNC_ADD);
          }

          for (int i = 0; i < list_model->rowCount(); ++i) {
            if (list_model->items[i]->show && !hide_all_button->isChecked()) {
              ROI_Item* roi = dynamic_cast<ROI_Item*>(list_model->items[i].get());
              //if (is_3D) 
              //window.get_current_mode()->overlays_for_3D.push_back (image);
              //else
              roi->render (shader, projection, projection.depth_of (window().focus()));
            }
          }

          if (!is_3D) {
            // restore OpenGL environment:
            gl::Disable (gl::BLEND);
            gl::Enable (gl::DEPTH_TEST);
            gl::DepthMask (gl::TRUE_);
          }
        }
예제 #2
0
        // Draw without setting up matrices/no crosshairs/no orientation labels
        void Slice::draw_plane_primitive (int axis, Displayable::Shader& shader_program, Projection& with_projection)
        {
          // render image:
          if (visible) {
            if (snap_to_image())
              image()->render2D (shader_program, with_projection, axis, slice (axis));
            else
              image()->render3D (shader_program, with_projection, with_projection.depth_of (focus()));
          }

          render_tools (with_projection, false, axis, slice (axis));
        }
예제 #3
0
파일: overlay.cpp 프로젝트: boegel/mrtrix3
        void Overlay::draw (const Projection& projection, bool is_3D, int, int)
        {
          ASSERT_GL_MRVIEW_CONTEXT_IS_CURRENT;
          if (!is_3D) {
            // set up OpenGL environment:
            gl::Enable (gl::BLEND);
            gl::Disable (gl::DEPTH_TEST);
            gl::DepthMask (gl::FALSE_);
            gl::ColorMask (gl::TRUE_, gl::TRUE_, gl::TRUE_, gl::TRUE_);
            gl::BlendFunc (gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
            gl::BlendEquation (gl::FUNC_ADD);
          }

          bool need_to_update = false;
          for (int i = 0; i < image_list_model->rowCount(); ++i) {
            if (image_list_model->items[i]->show && !hide_all_button->isChecked()) {
              Overlay::Item* image = dynamic_cast<Overlay::Item*>(image_list_model->items[i].get());
              need_to_update |= !std::isfinite (image->intensity_min());
              image->transparent_intensity = image->opaque_intensity = image->intensity_min();
              if (is_3D) 
                window().get_current_mode()->overlays_for_3D.push_back (image);
              else
                image->render3D (image->slice_shader, projection, projection.depth_of (window().focus()));
            }
          }

          if (need_to_update)
            update_selection();

          if (!is_3D) {
            // restore OpenGL environment:
            gl::Disable (gl::BLEND);
            gl::Enable (gl::DEPTH_TEST);
            gl::DepthMask (gl::TRUE_);
          }
          ASSERT_GL_MRVIEW_CONTEXT_IS_CURRENT;
        }
예제 #4
0
        void AbstractFixel::update_interp_image_buffer (const Projection& projection,
                                                const MR::Image::ConstHeader &fixel_header,
                                                const MR::Image::Transform &header_transform)
        {
          // Code below "inspired" by ODF::draw
          Point<> p (Window::main->target());
          p += projection.screen_normal() * (projection.screen_normal().dot (Window::main->focus() - p));
          p = header_transform.scanner2voxel (p);

          if (fixel_tool.do_lock_to_grid) {
            p[0] = (int)std::round (p[0]);
            p[1] = (int)std::round (p[1]);
            p[2] = (int)std::round (p[2]);
          }

          p = header_transform.voxel2scanner (p);

          const MR::Image::Info& header_info = fixel_header.info();

          Point<> x_dir = projection.screen_to_model_direction (1.0f, 0.0f, projection.depth_of (p));
          x_dir.normalise();
          x_dir = header_transform.scanner2image_dir (x_dir);
          x_dir[0] *= header_info.vox(0);
          x_dir[1] *= header_info.vox(1);
          x_dir[2] *= header_info.vox(2);
          x_dir = header_transform.image2scanner_dir (x_dir);

          Point<> y_dir = projection.screen_to_model_direction (0.0f, 1.0f, projection.depth_of (p));
          y_dir.normalise();
          y_dir = header_transform.scanner2image_dir (y_dir);
          y_dir[0] *= header_info.vox(0);
          y_dir[1] *= header_info.vox(1);
          y_dir[2] *= header_info.vox(2);
          y_dir = header_transform.image2scanner_dir (y_dir);

          Point<> x_width = projection.screen_to_model_direction (projection.width()/2.0f, 0.0f, projection.depth_of (p));
          int nx = std::ceil (x_width.norm() / x_dir.norm());
          Point<> y_width = projection.screen_to_model_direction (0.0f, projection.height()/2.0f, projection.depth_of (p));
          int ny = std::ceil (y_width.norm() / y_dir.norm());

          regular_grid_buffer_pos.clear();
          regular_grid_buffer_dir.clear();
          regular_grid_buffer_val.clear();

          for (int y = -ny; y <= ny; ++y) {
            for (int x = -nx; x <= nx; ++x) {
              Point<> scanner_pos = p + float(x)*x_dir + float(y)*y_dir;
              Point<> voxel_pos = header_transform.scanner2voxel(scanner_pos);

              // Round to nearest neighbour
              voxel_pos[0] = (int)std::round (voxel_pos[0]);
              voxel_pos[1] = (int)std::round (voxel_pos[1]);
              voxel_pos[2] = (int)std::round (voxel_pos[2]);

              // Find and add point indices that correspond to projected voxel
              const auto &voxel_indices = voxel_to_indices_map[voxel_pos];

              // Load all corresponding fixel data into separate buffer
              // We can't reuse original buffer because off-axis rendering means that
              // two or more points in our regular grid may correspond to the same nearest voxel
              for(const GLsizei index : voxel_indices) {
                regular_grid_buffer_pos.push_back(scanner_pos);
                regular_grid_buffer_dir.push_back(buffer_dir[index]);
                regular_grid_buffer_val.push_back(buffer_val[2 * index]);
                regular_grid_buffer_val.push_back(buffer_val[(2 * index) + 1]);
              }
            }
          }

          if(!regular_grid_buffer_pos.size())
            return;

          regular_grid_vao.bind();
          regular_grid_vertex_buffer.bind (gl::ARRAY_BUFFER);
          gl::BufferData (gl::ARRAY_BUFFER, regular_grid_buffer_pos.size() * sizeof(Point<float>),
                          &regular_grid_buffer_pos[0], gl::DYNAMIC_DRAW);
          gl::EnableVertexAttribArray (0);
          gl::VertexAttribPointer (0, 3, gl::FLOAT, gl::FALSE_, 0, (void*)0);

          // fixel directions
          regular_grid_dir_buffer.bind (gl::ARRAY_BUFFER);
          gl::BufferData (gl::ARRAY_BUFFER, regular_grid_buffer_dir.size() * sizeof(Point<float>),
                          &regular_grid_buffer_dir[0], gl::DYNAMIC_DRAW);
          gl::EnableVertexAttribArray (1);
          gl::VertexAttribPointer (1, 3, gl::FLOAT, gl::FALSE_, 0, (void*)0);

          // fixel sizes and values
          regular_grid_val_buffer.bind (gl::ARRAY_BUFFER);
          gl::BufferData (gl::ARRAY_BUFFER, regular_grid_buffer_val.size() * sizeof(float),
                          &regular_grid_buffer_val[0], gl::DYNAMIC_DRAW);
          gl::EnableVertexAttribArray (2);
          gl::VertexAttribPointer (2, 2, gl::FLOAT, gl::FALSE_, 0, (void*)0);
        }