Example #1
0
        void Fixel::load_image ()
        {
          for (size_t dim = 0; dim < 3; ++dim) {
            slice_fixel_indices[dim].resize (fixel_vox.dim(dim));
            slice_fixel_sizes[dim].resize (fixel_vox.dim(dim));
            slice_fixel_counts[dim].resize (fixel_vox.dim(dim), 0);
          }

          MR::Image::LoopInOrder loop (fixel_vox);
          std::vector<Point<float> > buffer_dir;
          std::vector<float> buffer_val;
          buffer_dir.push_back(Point<float>());
          buffer_val.push_back(NAN);
          Point<float> voxel_pos;
          for (loop.start (fixel_vox); loop.ok(); loop.next (fixel_vox)) {
            for (size_t f = 0; f != fixel_vox.value().size(); ++f) {
              if (fixel_vox.value()[f].value > value_max)
                value_max = fixel_vox.value()[f].value;
              if (fixel_vox.value()[f].value < value_min)
                value_min = fixel_vox.value()[f].value;
              for (size_t dim = 0; dim < 3; ++dim) {
                slice_fixel_indices[dim][fixel_vox[dim]].push_back (buffer_dir.size() - 1);
                slice_fixel_sizes[dim][fixel_vox[dim]].push_back(2);
                slice_fixel_counts[dim][fixel_vox[dim]]++;
              }
              header_transform.voxel2scanner (fixel_vox, voxel_pos);
              buffer_dir.push_back (voxel_pos);
              buffer_dir.push_back (fixel_vox.value()[f].dir);
              buffer_val.push_back (fixel_vox.value()[f].value);
              buffer_val.push_back (fixel_vox.value()[f].value);
            }
          }
          buffer_dir.push_back (Point<float>());
          buffer_val.push_back (NAN);
          this->set_windowing (value_min, value_max);
          greaterthan = value_max;
          lessthan = value_min;

          // voxel centres and fixel directions
          gl::GenBuffers (1, &vertex_buffer);
          gl::BindBuffer (gl::ARRAY_BUFFER, vertex_buffer);
          gl::BufferData (gl::ARRAY_BUFFER, buffer_dir.size() * sizeof(Point<float>), &buffer_dir[0][0], gl::STATIC_DRAW);
          gl::GenVertexArrays (1, &vertex_array_object);
          gl::BindVertexArray (vertex_array_object);
          gl::EnableVertexAttribArray (0);
          gl::VertexAttribPointer (0, 3, gl::FLOAT, gl::FALSE_, 0, (void*)(3*sizeof(float)));
          gl::EnableVertexAttribArray (1);
          gl::VertexAttribPointer (1, 3, gl::FLOAT, gl::FALSE_, 0, (void*)0);
          gl::EnableVertexAttribArray (2);
          gl::VertexAttribPointer (2, 3, gl::FLOAT, gl::FALSE_, 0, (void*)(6*sizeof(float)));

          // fixel values
          gl::GenBuffers (1, &value_buffer);
          gl::BindBuffer (gl::ARRAY_BUFFER, value_buffer);
          gl::BufferData (gl::ARRAY_BUFFER, buffer_val.size() * sizeof(float), &buffer_val[0], gl::STATIC_DRAW);
          gl::EnableVertexAttribArray (3);
          gl::VertexAttribPointer (3, 1, gl::FLOAT, gl::FALSE_, 0, (void*)(sizeof(float)));
        }
Example #2
0
        void Fixel::load_image_buffer()
        {
          for (size_t dim = 0; dim < 3; ++dim) {
            ssize_t dim_size = fixel_vox.dim(dim);
            slice_fixel_indices[dim].resize (dim_size);
            slice_fixel_sizes[dim].resize (dim_size);
            slice_fixel_counts[dim].resize (dim_size, 0);
          }

          MR::Image::LoopInOrder loop (fixel_vox);

          Point<float> voxel_pos;
          for (auto l = loop (fixel_vox); l; ++l) {
            for (size_t f = 0; f != fixel_vox.value().size(); ++f) {
              if (fixel_vox.value()[f].value > value_max)
                value_max = fixel_vox.value()[f].value;
              if (fixel_vox.value()[f].value < value_min)
                value_min = fixel_vox.value()[f].value;
            }
          }
          for (loop.start (fixel_vox); loop.ok(); loop.next (fixel_vox)) {
            for (size_t f = 0; f != fixel_vox.value().size(); ++f) {
              header_transform.voxel2scanner (fixel_vox, voxel_pos);
              buffer_pos.push_back (voxel_pos);
              buffer_dir.push_back (fixel_vox.value()[f].dir);
              buffer_val.push_back (fixel_vox.value()[f].size);
              buffer_val.push_back (fixel_vox.value()[f].value);

              GLint point_index = buffer_pos.size() - 1;

              for (size_t dim = 0; dim < 3; ++dim) {
                slice_fixel_indices[dim][fixel_vox[dim]].push_back (point_index);
                slice_fixel_sizes[dim][fixel_vox[dim]].push_back(1);
                slice_fixel_counts[dim][fixel_vox[dim]]++;
              }

              voxel_to_indices_map[Point<int>(fixel_vox[0], fixel_vox[1], fixel_vox[2])].push_back(point_index);
            }
          }

          this->set_windowing (value_min, value_max);
          greaterthan = value_max;
          lessthan = value_min;
        }