Exemple #1
0
unsigned long mitk::Mesh::GetNewCellId( int t )
{
  long nextCellId = -1;
  ConstCellIterator it = m_PointSetSeries[t]->GetCells()->Begin();
  ConstCellIterator end = m_PointSetSeries[t]->GetCells()->End();

  while (it!=end)
  {
    nextCellId = it.Index();
    ++it;
  }
  ++nextCellId;
  return nextCellId;
}
Exemple #2
0
int mitk::Mesh::SearchFirstCell(unsigned long pointId, int t)
{
  // iterate through all cells and find the cell the given pointId is inside
  ConstCellIterator it = m_PointSetSeries[t]->GetCells()->Begin();
  ConstCellIterator end = m_PointSetSeries[t]->GetCells()->End();
  while (it != end)
  {
    PointIdIterator position = std::find(it->Value()->PointIdsBegin(), it->Value()->PointIdsEnd(), pointId);

    if (position != it->Value()->PointIdsEnd())
    {
      return it->Index();
    }
    ++it;
  }
  return -1;
}
Exemple #3
0
//search a line that is close enough according to the given position
bool mitk::Mesh::SearchLine( Point3D point, float distance,
  unsigned long &lineId, unsigned long &cellId, int t )
{
  //returns true if a line is found
  ScalarType bestDist = distance;

  //iterate through all cells.
  ConstCellIterator cellIt = m_PointSetSeries[t]->GetCells()->Begin();
  ConstCellIterator cellEnd = m_PointSetSeries[t]->GetCells()->End();
  while( cellIt != cellEnd)
  {
    if (cellIt.Value()->GetNumberOfPoints() >1)
    {
      //then iterate through all indexes of points in it->Value()
      PointIdIterator inAIt = cellIt.Value()->PointIdsBegin(); // first point
      PointIdIterator inBIt = cellIt.Value()->PointIdsBegin(); // second point
      PointIdIterator inEnd = cellIt.Value()->PointIdsEnd();

      ++inAIt; //so it points to the point before inBIt

      int currentLineId = 0;
      while(inAIt != inEnd)
      {
        mitk::PointSet::PointType pointA, pointB;
        if ( m_PointSetSeries[t]->GetPoint((*inAIt), &pointA) &&
          m_PointSetSeries[t]->GetPoint((*inBIt), &pointB))
        {
          auto  line = new Line<CoordinateType>();
          line->SetPoints(pointA, pointB);
          double thisDistance = line->Distance(point);
          if (thisDistance < bestDist)
          {
            cellId = cellIt->Index();
            lineId = currentLineId;
            bestDist = thisDistance;
          }
        }
        ++inAIt;
        ++inBIt;
        ++currentLineId;
      }

      // If the cell is closed, then check the line from the last index to
      // the first index if inAIt points to inEnd, then inBIt points to the
      // last index.
      CellDataType cellData;
      bool dataOk = m_PointSetSeries[t]->GetCellData(cellIt->Index(), &cellData);
      if (dataOk)
      {
        if (cellData.closed)
        {
          // get the points
          PointIdIterator inAIt = cellIt.Value()->PointIdsBegin();//first point
          // inBIt points to last.
          mitk::PointSet::PointType pointA, pointB;
          if ( m_PointSetSeries[t]->GetPoint((*inAIt), &pointA) &&
            m_PointSetSeries[t]->GetPoint((*inBIt), &pointB))
          {
            auto  line = new Line<CoordinateType>();
            line->SetPoints(pointA, pointB);
            double thisDistance = line->Distance(point);
            if (thisDistance < bestDist)
            {
              cellId = cellIt->Index();
              lineId = currentLineId;
              bestDist = thisDistance;
            }
          }
        }
      }
    }
    ++cellIt;
  }
  return (bestDist < distance);
}