Esempio n. 1
0
void WorldDownloadManager::findExtraCubesForBoundingBox(const Eigen::Vector3f& current_cube_min,
  const Eigen::Vector3f& current_cube_max,const Eigen::Vector3f& bbox_min,const Eigen::Vector3f& bbox_max,Vector3fVector& cubes_centers,
  bool& extract_current)
{
  const Eigen::Vector3f & cube_size = current_cube_max - current_cube_min;
  cubes_centers.clear();
  extract_current = false;

  const Eigen::Vector3f relative_act_bbox_min = bbox_min - current_cube_min;
  const Eigen::Vector3f relative_act_bbox_max = bbox_max - current_cube_min;
  const Eigen::Vector3i num_cubes_plus = Eigen::Vector3f(floor3f(Eigen::Vector3f(relative_act_bbox_max.array() / cube_size.array())
    - (Eigen::Vector3f::Ones() * 0.0001))).cast<int>();
  const Eigen::Vector3i num_cubes_minus = Eigen::Vector3f(floor3f(Eigen::Vector3f(relative_act_bbox_min.array() / cube_size.array())
    + (Eigen::Vector3f::Ones() * 0.0001))).cast<int>();
  for (int z = num_cubes_minus.z(); z <= num_cubes_plus.z(); z++)
    for (int y = num_cubes_minus.y(); y <= num_cubes_plus.y(); y++)
      for (int x = num_cubes_minus.x(); x <= num_cubes_plus.x(); x++)
      {
        const Eigen::Vector3i cube_index(x,y,z);
        if ((cube_index.array() == Eigen::Vector3i::Zero().array()).all())
        {
          extract_current = true;
          continue;
        }

        const Eigen::Vector3f relative_cube_origin = cube_index.cast<float>().array() * cube_size.array();
        const Eigen::Vector3f cube_center = relative_cube_origin + current_cube_min + (cube_size * 0.5);
        cubes_centers.push_back(cube_center);
      }
}
Esempio n. 2
0
HashedId::HashedId(const Eigen::Vector3i&pos,const int&edgeLen,const int&no) {

    _id[0]=edgeLen;
    _id[1]=pos.x();
    _id[2]=pos.y();
    _id[3]=pos.z();
    _no=no;
}
void CollisionSpace::propagatePositive(
    std::vector<std::vector<CollisionSpaceCell*> >& bucket_queue) {
  double max_distance_sq = getMaxtDistSq();

  // now process the queue:
  cout << "process the Queue : " << bucket_queue.size() << endl;
  for (unsigned int i = 0; i < bucket_queue.size(); ++i) {
    std::vector<CollisionSpaceCell*>::iterator list_it =
        bucket_queue[i].begin();

    while (list_it != bucket_queue[i].end()) {
      CollisionSpaceCell* vptr = *list_it;

      // TODO: no idea why this happens
      if (vptr == NULL) {
        continue;
      }

      // Get the cell location in grid
      Eigen::Vector3i loc = getCellCoord(vptr);

      int D = i;
      if (D > 1) D = 1;
      // avoid a possible segfault situation:
      if (vptr->m_UpdateDirection < 0 || vptr->m_UpdateDirection > 26) {
        cout << "Invalid update direction detected: " << vptr->m_UpdateDirection
             << endl;

        ++list_it;
        continue;
      }

      // select the neighborhood list based on the update direction:
      std::vector<std::vector<int> >& neighborhood =
          m_Neighborhoods[D][vptr->m_UpdateDirection];

      // Look in the neighbouring cells and update distance
      for (unsigned int n = 0; n < neighborhood.size(); n++) {
        Eigen::Vector3i direction;
        direction.x() = neighborhood[n][0];
        direction.y() = neighborhood[n][1];
        direction.z() = neighborhood[n][2];

        Eigen::Vector3i neigh_loc = loc + direction;
        CollisionSpaceCell* neighbour = getCellSpaceCell(neigh_loc);
        if (!neighbour) continue;

        double new_distance_sq_float =
            (vptr->m_ClosestPoint - neigh_loc).squaredNorm();

        int new_distance_sq = new_distance_sq_float;
        if (new_distance_sq > max_distance_sq) {
          cout << "new_distance_sq : " << new_distance_sq << endl;
          continue;
        }

        if (new_distance_sq < neighbour->m_DistanceSquare) {
          neighbour->m_DistanceSquare = new_distance_sq;
          neighbour->m_ClosestPoint = vptr->m_ClosestPoint;
          neighbour->m_UpdateDirection =
              getDirectionNumber(direction[0], direction[1], direction[2]);

          // and put it in the queue
          bucket_queue[new_distance_sq].push_back(neighbour);
        }
      }
      ++list_it;
    }
    bucket_queue[i].clear();
  }
}
Esempio n. 4
0
vtkVolume * VTKDialog::cubeVolume(Cube *cube)
{
  qDebug() << "Cube dimensions: " << cube->dimensions().x()
           << cube->dimensions().y() << cube->dimensions().z();

  qDebug() << "min/max:" << cube->minValue() << cube->maxValue();
  qDebug() << cube->data()->size();

  vtkNew<vtkImageData> data;
  data->SetNumberOfScalarComponents(1);
  Eigen::Vector3i dim = cube->dimensions();
  data->SetExtent(0, dim.x()-1, 0, dim.y()-1, 0, dim.z()-1);

  data->SetOrigin(cube->min().x(), cube->min().y(), cube->min().z());
  data->SetSpacing(cube->spacing().data());

  data->SetScalarTypeToDouble();
  data->AllocateScalars();
  data->Update();

  double *dataPtr = static_cast<double *>(data->GetScalarPointer());
  std::vector<double> *cubePtr = cube->data();

  for (int i = 0; i < dim.x(); ++i)
    for (int j = 0; j < dim.y(); ++j)
      for (int k = 0; k < dim.z(); ++k) {
        dataPtr[(k * dim.y() + j) * dim.x() + i] =
            (*cubePtr)[(i * dim.y() + j) * dim.z() + k];
      }

  double range[2];
  data->Update();
  range[0] = data->GetScalarRange()[0];
  range[1] = data->GetScalarRange()[1];
//  a->GetRange(range);
  qDebug() << "ImageData range: " << range[0] << range[1];

  vtkNew<vtkImageShiftScale> t;
  t->SetInput(data.GetPointer());
  t->SetShift(-range[0]);
  double magnitude = range[1] - range[0];
  if(magnitude == 0.0)
    {
    magnitude = 1.0;
    }
  t->SetScale(255.0/magnitude);
  t->SetOutputScalarTypeToDouble();

  qDebug() << "magnitude: " << magnitude;

  t->Update();

  vtkNew<vtkSmartVolumeMapper> volumeMapper;
  vtkNew<vtkVolumeProperty> volumeProperty;
  vtkVolume *volume = vtkVolume::New();

  volumeMapper->SetBlendModeToComposite();
//  volumeMapper->SetBlendModeToComposite(); // composite first
  volumeMapper->SetInputConnection(t->GetOutputPort());

  volumeProperty->ShadeOff();
  volumeProperty->SetInterpolationTypeToLinear();

  vtkNew<vtkPiecewiseFunction> compositeOpacity;
  vtkNew<vtkColorTransferFunction> color;
  if (cube->cubeType() == Cube::MO) {
    compositeOpacity->AddPoint(  0.00, 0.0);
    compositeOpacity->AddPoint( 63.75, 0.5);
    compositeOpacity->AddPoint(127.50, 0.0);
    compositeOpacity->AddPoint(192.25, 0.5);
    compositeOpacity->AddPoint(255.00, 0.0);

    color->AddRGBPoint(  0.00, 0.0, 0.0, 0.0);
    color->AddRGBPoint( 63.75, 1.0, 0.0, 0.0);
    color->AddRGBPoint(127.50, 0.0, 0.2, 0.0);
    color->AddRGBPoint(191.25, 0.0, 0.0, 1.0);
    color->AddRGBPoint(255.00, 0.0, 0.0, 0.0);
  }
  else {
    compositeOpacity->AddPoint(  0.00, 0.00);
    compositeOpacity->AddPoint(  1.75, 0.30);
    compositeOpacity->AddPoint(  2.50, 0.50);
    compositeOpacity->AddPoint(192.25, 0.85);
    compositeOpacity->AddPoint(255.00, 0.90);

    color->AddRGBPoint(  0.00, 0.0, 0.0, 1.0);
    color->AddRGBPoint( 63.75, 0.0, 0.0, 0.8);
    color->AddRGBPoint(127.50, 0.0, 0.0, 0.5);
    color->AddRGBPoint(191.25, 0.0, 0.0, 0.2);
    color->AddRGBPoint(255.00, 0.0, 0.0, 0.0);
  }

  volumeProperty->SetScalarOpacity(compositeOpacity.GetPointer()); // composite first.
  volumeProperty->SetColor(color.GetPointer());

  volume->SetMapper(volumeMapper.GetPointer());
  volume->SetProperty(volumeProperty.GetPointer());

  return volume;
}