//Schnittpunktbestimmung der zwei Kreise --> mögliche Tangentenpunkte.........
void weg::BestimmeSchnittpunkte(double P_x, double P_y, double Q_x, double Q_y, double r1, double r2, double *res1, double *res2, double *res3, double *res4 )
{
     r1 = abs(r1);
     r2 = abs(r2);

     //Kein Schnittpunkt
     SetPoints(0);

//     double abc = BetragVektor(P_x,P_y,Q_x,Q_y);

//     //Kreise innerhalb
//     if(abc <= abs(r1-r2))
//          return;

//     //Kreise ausserhalb
//     if(abc > abs(r1 + r2))
//          return;

//     //Unendlich Schnittpunkte
//     if((P_x - Q_x == 0) && (P_y - Q_y == 0))
//          return;


     //ggf. Koordinaten tauschen, um Division durch Null vermeiden
     if(Q_x == P_x)
     {
          SetPoints(2);

          double a = (P_x - Q_x)/(Q_y - P_y);
          double b = ( (r1*r1 - r2*r2)- (P_y*P_y - Q_y*Q_y) - (P_x*P_x - Q_x*Q_x)  )/(2*Q_y - 2*P_y); // =((r1^2 -r2^2) - (y^2 - y^2) - 0 ) / (2 * (y - y))
          double e = a*a+1;
          double f = (2*a*(b-P_y))-(2*P_x);
          double g = (b-P_y)*(b-P_y) -r1*r1 + P_x*P_x;

          *res1 = (-f + sqrt(f*f - 4*e*g) )/(2*e);
          *res3 = (-f - sqrt(f*f - 4*e*g) )/(2*e);
          *res2 = *res1 * a + b;
          *res4 = *res3 * a + b;
     }
     else
     {
          SetPoints(2);

          double a = (P_y - Q_y)/(Q_x - P_x);
          double b = ( (r1*r1 - r2*r2)- (P_x*P_x - Q_x*Q_x) -  (P_y*P_y - Q_y*Q_y)  )/(2*Q_x - 2*P_x);
          double e = a*a+1;
          double f = (2*a*(b-P_x))-(2*P_y);
          double g = (b-P_x)*(b-P_x) -r1*r1 + P_y*P_y;

          *res2 = (-f + sqrt(f*f - 4*e*g) )/(2*e);
          *res4 = (-f - sqrt(f*f - 4*e*g) )/(2*e);
          *res1 = *res2 * a + b;
          *res3 = *res4 * a + b;

     }

     if(*res2 == *res4 && *res1 == *res3)
          SetPoints(1);
}
Example #2
0
bool cProbabDistrib::SetDefString(const AString & a_DefString)
{
	AStringVector Points = StringSplitAndTrim(a_DefString, ";");
	if (Points.empty())
	{
		return false;
	}
	cPoints Pts;
	for (AStringVector::const_iterator itr = Points.begin(), end = Points.end(); itr != end; ++itr)
	{
		AStringVector Split = StringSplitAndTrim(*itr, ",");
		if (Split.size() != 2)
		{
			// Bad format
			return false;
		}
		int Value = atoi(Split[0].c_str());
		int Prob  = atoi(Split[1].c_str());
		if (
			((Value == 0) && (Split[0] != "0")) ||
			((Prob  == 0) && (Split[1] != "0"))
		)
		{
			// Number parse error
			return false;
		}
		Pts.push_back(cPoint(Value, Prob));
	}  // for itr - Points[]
	
	SetPoints(Pts);
	return true;
}
Example #3
0
    std::tuple<vtkSmartPointer<vtkPolyData>, vtkSmartPointer<vtkCellArray>, vtkSmartPointer<vtkFloatArray>> genvtkPolyData()
    {
        auto points = vtkSmartPointer<vtkPoints>::New();
        points->InsertNextPoint(0, 0, 0);
        points->InsertNextPoint(0, 1, 0);
        points->InsertNextPoint(1, 1, 0);

        auto poly = vtkSmartPointer<vtkPolyData>::New();
        poly->SetPoints(points);

        auto indices = vtkSmartPointer<vtkCellArray>::New();
        indices->InsertNextCell(3);
        indices->InsertCellPoint(0);
        indices->InsertCellPoint(1);
        indices->InsertCellPoint(2);

        auto vectors = vtkSmartPointer<vtkFloatArray>::New();
        vectors->SetName(vectorName());
        vectors->SetNumberOfComponents(3);
        vectors->SetNumberOfTuples(1);
        vectors->SetTypedComponent(0, 0, 0);
        vectors->SetTypedComponent(0, 1, 0);
        vectors->SetTypedComponent(0, 2, 1);

        return { poly, indices, vectors };
    }
Example #4
0
CCurve::CCurve(const CCurve& from) :
	Pen(from.Pen),
	Brush(from.Brush)
{
	SetToDefaults();
	SetColor(from.Color);
	SetPoints(from.Points, from.NumPoints);
}
Example #5
0
CCurve::CCurve(const POINT* Points, int numPoints, COLORREF color) :
	Pen(color),
	Brush(color)
{
	SetToDefaults();
	SetColor(color);
	SetPoints(Points, numPoints);
}
void CIppsSignalDC::Draw()
{
   SetMinMax();
   SetPoints();
   if (m_pSignal->Complex())
      DrawComplex();
   else
      DrawReal();
}
Example #7
0
void CGameScore::KeyValue(KeyValueData *pkvd)
{
	if (FStrEq(pkvd->szKeyName, "points"))
	{
		SetPoints(atoi(pkvd->szValue));
		pkvd->fHandled = TRUE;
	}
	else
		CRulePointEntity::KeyValue(pkvd);
}
Example #8
0
bool CGameScore::KeyValue( const char *szKeyName, const char *szValue )
{
	if (FStrEq(szKeyName, "points"))
	{
		SetPoints( atoi(szValue) );
	}
	else
		return BaseClass::KeyValue( szKeyName, szValue );

	return true;
}
Example #9
0
CCurve& CCurve::operator = (const CCurve& from)
{
	if (this != &from)
	{ // Check for a = a case
		SetPoints(from.Points, from.NumPoints);
		iCurrent = (NumPoints-1)/2;
		Pen = from.Pen;
		Brush = from.Brush;
		Color = from.Color;
	}

	return *this;
}
Example #10
0
int AssignPointAttributeToCoordinatesFilter::RequestData(
    vtkInformation * /*request*/,
    vtkInformationVector ** inputVector,
    vtkInformationVector * outputVector)
{
    auto inData = vtkPointSet::SafeDownCast(inputVector[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
    auto outData = vtkPointSet::SafeDownCast(outputVector->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));

    auto previousPointCoords = inData->GetPoints()->GetData();
    vtkDataArray * pointsToAssign = nullptr;

    if (!this->AttributeArrayToAssign.empty())
    {
        auto newPoints = inData->GetPointData()->GetArray(this->AttributeArrayToAssign.c_str());
        if (!newPoints)
        {
            vtkErrorMacro("Array to assign not found in input data: " + this->AttributeArrayToAssign);
            return 0;
        }

        if (newPoints->GetNumberOfComponents() != 3
            || newPoints->GetNumberOfTuples() != inData->GetNumberOfPoints())
        {
            vtkErrorMacro("Component/Tuple count mismatching in selected data array: " + this->AttributeArrayToAssign);
            return 0;
        }
        pointsToAssign = newPoints;
    }

    outData->ShallowCopy(inData);

    if (pointsToAssign)
    {
        vtkNew<vtkPoints> newPoints;
        newPoints->SetData(pointsToAssign);
        outData->SetPoints(newPoints.Get());
    }

    // pass current point coordinates as point attribute
    if (previousPointCoords)
    {
        outData->GetPointData()->AddArray(previousPointCoords);
    }

    if (auto currentCoords = pointsToAssign ? pointsToAssign : previousPointCoords)
    {
        outData->GetPointData()->SetActiveScalars(currentCoords->GetName());
    }

    return 1;
}
Example #11
0
    static vtkSmartPointer<vtkPolyData> genPolyDataSet()
    {
        auto poly = vtkSmartPointer<vtkPolyData>::New();
        auto points = vtkSmartPointer<vtkPoints>::New();

        points->InsertNextPoint(0, 0, 0);
        points->InsertNextPoint(0, 1, 0);
        points->InsertNextPoint(1, 1, 0);
        poly->SetPoints(points);
        std::array<vtkIdType, 3> pointIds = { 0, 1, 2 };
        poly->Allocate(static_cast<vtkIdType>(pointIds.size()));
        poly->InsertNextCell(VTK_TRIANGLE, static_cast<int>(pointIds.size()), pointIds.data());

        return poly;
    }
Example #12
0
void write_vtk_file(const Domain<lattice_model>& domain, const std::string& output_dir,
        const std::string& output_filename, uint64_t t)
{
    const auto xl = domain.xlength();
    const auto yl = domain.ylength();
    const auto zl = domain.zlength();
    // Compute point coordinates
    auto points = vtkSmartPointer<vtkPoints>::New();
    compute_coordinates(domain, points);

    // Compute velocity and density vectors
    auto velocities = vtkSmartPointer<vtkDoubleArray>::New();
    auto densities = vtkSmartPointer<vtkDoubleArray>::New();

    velocities->SetNumberOfComponents(lattice_model::D);
    densities->SetNumberOfComponents(1);

    velocities->SetName("Velocity");
    densities->SetName("Density");

    for (auto z = 1u; z < zl + 1; ++z) {
        for (auto y = 1u; y < yl + 1; ++y) {
            for (auto x = 1u; x < xl + 1; ++x) {
                auto current_cell = domain.cell(x, y, z);
                auto density = current_cell.density();
                auto vel = current_cell.velocity(density);

                densities->InsertNextTuple1(density);
                velocities->InsertNextTuple3(vel[0], vel[1], vel[2]);
            }
        }
    }

    // Create a grid and write coordinates and velocity/density
    auto structuredGrid = vtkSmartPointer<vtkStructuredGrid>::New();
    structuredGrid->SetDimensions(xl, yl, zl);
    structuredGrid->SetPoints(points);
    structuredGrid->GetPointData()->SetVectors(velocities);
    structuredGrid->GetPointData()->SetScalars(densities);
    // Save filename as a combination of passed filename and timestep
    std::stringstream sstr;
    sstr << output_dir << "/" << output_filename << "." << t << ".vts";
    // Write file
    auto writer = vtkSmartPointer<vtkXMLStructuredGridWriter>::New();
    writer->SetFileName(sstr.str().c_str());
    writer->SetInput(structuredGrid);
    writer->Write();
}
Example #13
0
void Triangle::SetPosition(const Vector2D& position) {
    double deltaX = position.GetX() - GetX();
    double deltaY = position.GetY() - GetY();

    double aX = GetPointA().GetX() + deltaX;
    double bX = GetPointB().GetX() + deltaX;
    double cX = GetPointC().GetX() + deltaX;

    double aY = GetPointA().GetY() + deltaY;
    double bY = GetPointB().GetY() + deltaY;
    double cY = GetPointC().GetY() + deltaY;

    SetPoints(aX, aY, bX, bY, cX, cY);
    
    _position = Vector2D((aX + bX + cX) / 3.0, (aY + bY + cY) / 3.0);

}
Example #14
0
void CGUILine::Resize(float _sx, float _sy)
{
	float lsx, lsy;
	GetSize(lsx,lsy);

	CheckResize(_sx,_sy);

	if(lsy==1)
	{
		if(left_right)
			SetPoints(x,y,x+_sx-1,y);
		else
			SetPoints(x+_sx-1,y,x,y);
		//SetSize(_sx,0);
	}else if(lsx==1)
	{
		if(up_down)
			SetPoints(x,y,x,y+_sy-1);
		else
			SetPoints(x,y+_sy-1,x,y);
		//SetSize(0,_sy);
	}else if(up_down)
	{
		if(left_right)
			SetPoints(x,y,x+_sx-1,y+_sy-1);
		else
			SetPoints(x+_sx-1,y,x,y+_sy-1);
		//SetSize(_sx,_sy);
	}else if(!up_down)
	{
		if(left_right)
			SetPoints(x,y+_sy-1,x+_sx-1,y);
		else
			SetPoints(x+_sx-1,y+_sy-1,x,y);
		//SetSize(_sx,_sy);
	}
}
Example #15
0
void Triangle::SetPointC(const Vector2D& position) {
    SetPoints(GetPointA(), GetPointB(), Point(position));
}
Example #16
0
void CGameScore::Spawn( void )
{
	int iScore = Points();
	BaseClass::Spawn();
	SetPoints( iScore );
}
Example #17
0
void Triangle::SetPointC(const Point& C) {
    SetPoints(GetPointA(), GetPointB(), C);
}
Example #18
0
File: mitkMesh.cpp Project: 0r/MITK
//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);
}
Example #19
0
/**
Create the vtkStructuredGrid from the provided workspace
@param progressUpdating: Reporting object to pass progress information up the
stack.
@return fully constructed vtkDataSet.
*/
vtkSmartPointer<vtkDataSet>
vtkMDHistoLineFactory::create(ProgressAction &progressUpdating) const {
  auto product =
      tryDelegatingCreation<MDHistoWorkspace, 1>(m_workspace, progressUpdating);
  if (product != nullptr) {
    return product;
  } else {
    g_log.warning() << "Factory " << this->getFactoryTypeName()
                    << " is being used. You are viewing data with less than "
                       "three dimensions in the VSI. \n";

    Mantid::Kernel::ReadLock lock(*m_workspace);
    const int nBinsX =
        static_cast<int>(m_workspace->getXDimension()->getNBins());

    const coord_t minX = m_workspace->getXDimension()->getMinimum();

    coord_t incrementX = m_workspace->getXDimension()->getBinWidth();

    const int imageSize = nBinsX;
    vtkNew<vtkPoints> points;
    points->Allocate(static_cast<int>(imageSize));

    vtkNew<vtkFloatArray> signal;
    signal->Allocate(imageSize);
    signal->SetName(vtkDataSetFactory::ScalarName.c_str());
    signal->SetNumberOfComponents(1);

    UnstructuredPoint unstructPoint;
    const int nPointsX = nBinsX;
    Column column(nPointsX);

    NullCoordTransform transform;
    // Mantid::API::CoordTransform* transform =
    // m_workspace->getTransformFromOriginal();
    Mantid::coord_t in[3];
    Mantid::coord_t out[3];

    double progressFactor = 0.5 / double(nBinsX);
    double progressOffset = 0.5;

    // Loop through dimensions
    for (int i = 0; i < nPointsX; i++) {
      progressUpdating.eventRaised(progressFactor * double(i));
      in[0] = minX +
              static_cast<coord_t>(i) * incrementX; // Calculate increment in x;

      float signalScalar =
          static_cast<float>(m_workspace->getSignalNormalizedAt(i));

      if (!std::isfinite(signalScalar)) {
        // Flagged so that topological and scalar data is not applied.
        unstructPoint.isSparse = true;
      } else {
        if (i < (nBinsX - 1)) {
          signal->InsertNextValue(static_cast<float>(signalScalar));
        }
        unstructPoint.isSparse = false;
      }

      transform.apply(in, out);

      unstructPoint.pointId = points->InsertNextPoint(out);
      column[i] = unstructPoint;
    }

    points->Squeeze();
    signal->Squeeze();

    auto visualDataSet = vtkSmartPointer<vtkUnstructuredGrid>::New();
    visualDataSet->Allocate(imageSize);
    visualDataSet->SetPoints(points.GetPointer());
    visualDataSet->GetCellData()->SetScalars(signal.GetPointer());

    for (int i = 0; i < nBinsX - 1; i++) {
      progressUpdating.eventRaised((progressFactor * double(i)) +
                                   progressOffset);
      // Only create topologies for those cells which are not sparse.
      if (!column[i].isSparse) {
        vtkLine *line = vtkLine::New();
        line->GetPointIds()->SetId(0, column[i].pointId);
        line->GetPointIds()->SetId(1, column[i + 1].pointId);
        visualDataSet->InsertNextCell(VTK_LINE, line->GetPointIds());
      }
    }

    visualDataSet->Squeeze();

    // Hedge against empty data sets
    if (visualDataSet->GetNumberOfPoints() <= 0) {
      vtkNullUnstructuredGrid nullGrid;
      visualDataSet = nullGrid.createNullData();
    }

    vtkSmartPointer<vtkDataSet> dataset = visualDataSet;
    return dataset;
  }
}
Example #20
0
BOOL CVecPolygon::Track(CDPoint point, UINT uiTool, CUndoManager* pUndoMan, CSnapper* pSnapper)
{
   if(m_bTrackAsShape)
   {
      CPtrList list;
      list.AddHead(this);
      CSuperTracker st(list);
      if(HasPicture())
         st.SetTrackRetainProportions();
      if(st.Track(GetTopContainer()->GetWnd(), point, 
         HitTest(point) == HT_ON_POINT ? CSuperTracker::Style_Size: CSuperTracker::Style_Move, pSnapper))
      {
         pUndoMan->AddToStack(this, UAT_RESTORE_OB_FROM_LIGHT_DUMP);
         SetRectScaleAndOffsetByScreen(st.m_rect, st.m_rectOrigianl);
         return TRUE;
      }
   }
   else
   {
      CPolygonTracker rt(m_t_lpPoints, m_uiNumOfPoints, TRACKER_STYLE);
      int iHit = rt.HitTestPoints(point);
      BOOL bTrackResoult;
      if(iHit >= CPolygonTracker::hitDot)
      {//track only the selected point and the points next to it
         ASSERT(m_uiNumOfPoints>=3);
         int aPointLocation[3];
         CDPOINT aPointsData[3];
         if(iHit == 0)
         {  
            aPointLocation[0] = m_uiNumOfPoints-1;
            aPointLocation[1] = 0;
            aPointLocation[2] = 1;
         }
         else if(iHit == (int)m_uiNumOfPoints-1)
         {
            aPointLocation[0] = m_uiNumOfPoints-2;
            aPointLocation[1] = m_uiNumOfPoints-1;
            aPointLocation[2] = 0;
         }
         else
         {
            aPointLocation[0] = iHit-1;
            aPointLocation[1] = iHit;
            aPointLocation[2] = iHit+1;
         }

         for(int i=0; i<3; i++)
            aPointsData[i] = m_t_lpPoints[aPointLocation[i]];

         CLineTracker localTracker(aPointsData, 3);
         bTrackResoult = localTracker.Track(GetTopContainer()->GetWnd(), point, pSnapper);
         if(bTrackResoult)
         {
            for(int i=0; i<3; i++)
               m_t_lpPoints[aPointLocation[i]] = aPointsData[i];
         }
      }
      else
      {
         if(HasPicture())
            rt.SetTrackRetainProportions();
         bTrackResoult = rt.Track(GetTopContainer()->GetWnd(), point, pSnapper);
      }

      if(bTrackResoult)
      {
         pUndoMan->AddToStack(this, UAT_RESTORE_OB_FROM_LIGHT_DUMP);
         LPCDPOINT dpoints = new CDPOINT[m_uiNumOfPoints];
         for(UINT ui = 0; ui < m_uiNumOfPoints; ui++)
         {
            dpoints[ui].x = m_t_lpPoints[ui].x;
            dpoints[ui].y = m_t_lpPoints[ui].y;
            dpoints[ui] -= m_t_Offset;
            dpoints[ui] /= m_t_Scaler;
         }
         SetPoints(dpoints, m_uiNumOfPoints);

         delete []dpoints;

         return TRUE;
      }
   }

   return FALSE;
}
void mitk::BoundingShapeVtkMapper2D::GenerateDataForRenderer(BaseRenderer *renderer)
{
  const DataNode::Pointer node = GetDataNode();
  if (node == nullptr)
    return;

  LocalStorage *localStorage = m_Impl->LocalStorageHandler.GetLocalStorage(renderer);

  // either update if GeometryData was modified or if the zooming was performed
  bool needGenerateData = localStorage->IsUpdateRequired(
    renderer, this, GetDataNode()); // true; // localStorage->GetLastGenerateDataTime() < node->GetMTime() ||
  // localStorage->GetLastGenerateDataTime() < node->GetData()->GetMTime();
  // //localStorage->IsGenerateDataRequired(renderer, this, GetDataNode());

  double scale = renderer->GetScaleFactorMMPerDisplayUnit();

  if (std::abs(scale - localStorage->m_ZoomFactor) > 0.001)
  {
    localStorage->m_ZoomFactor = scale;
    needGenerateData = true;
  }

  if (needGenerateData)
  {
    bool visible = true;
    GetDataNode()->GetVisibility(visible, renderer, "visible");

    if (!visible)
    {
      localStorage->m_Actor->VisibilityOff();
      return;
    }
    GeometryData::Pointer shape = static_cast<GeometryData *>(node->GetData());
    if (shape == nullptr)
      return;

    mitk::BaseGeometry::Pointer geometry = shape->GetGeometry();
    mitk::Vector3D spacing = geometry->GetSpacing();

    // calculate cornerpoints and extent from geometry with visualization offset
    std::vector<Point3D> cornerPoints = GetCornerPoints(geometry, true);
    Point3D p0 = cornerPoints[0];
    Point3D p1 = cornerPoints[1];
    Point3D p2 = cornerPoints[2];
    Point3D p4 = cornerPoints[4];
    Point3D extent;
    extent[0] =
      sqrt((p0[0] - p4[0]) * (p0[0] - p4[0]) + (p0[1] - p4[1]) * (p0[1] - p4[1]) + (p0[2] - p4[2]) * (p0[2] - p4[2]));
    extent[1] =
      sqrt((p0[0] - p2[0]) * (p0[0] - p2[0]) + (p0[1] - p2[1]) * (p0[1] - p2[1]) + (p0[2] - p2[2]) * (p0[2] - p2[2]));
    extent[2] =
      sqrt((p0[0] - p1[0]) * (p0[0] - p1[0]) + (p0[1] - p1[1]) * (p0[1] - p1[1]) + (p0[2] - p1[2]) * (p0[2] - p1[2]));

    // calculate center based on half way of the distance between two opposing cornerpoints
    mitk::Point3D center = CalcAvgPoint(cornerPoints[7], cornerPoints[0]);

    if (m_Impl->HandlePropertyList.size() == 6)
    {
      // set handle positions
      Point3D pointLeft = CalcAvgPoint(cornerPoints[5], cornerPoints[6]);
      Point3D pointRight = CalcAvgPoint(cornerPoints[1], cornerPoints[2]);
      Point3D pointTop = CalcAvgPoint(cornerPoints[0], cornerPoints[6]);
      Point3D pointBottom = CalcAvgPoint(cornerPoints[7], cornerPoints[1]);
      Point3D pointFront = CalcAvgPoint(cornerPoints[2], cornerPoints[7]);
      Point3D pointBack = CalcAvgPoint(cornerPoints[4], cornerPoints[1]);

      m_Impl->HandlePropertyList[0].SetPosition(pointLeft);
      m_Impl->HandlePropertyList[1].SetPosition(pointRight);
      m_Impl->HandlePropertyList[2].SetPosition(pointTop);
      m_Impl->HandlePropertyList[3].SetPosition(pointBottom);
      m_Impl->HandlePropertyList[4].SetPosition(pointFront);
      m_Impl->HandlePropertyList[5].SetPosition(pointBack);
    }

    // caculate face normals
    double result0[3], result1[3], result2[3];
    double a[3], b[3];
    a[0] = (cornerPoints[5][0] - cornerPoints[6][0]);
    a[1] = (cornerPoints[5][1] - cornerPoints[6][1]);
    a[2] = (cornerPoints[5][2] - cornerPoints[6][2]);

    b[0] = (cornerPoints[5][0] - cornerPoints[4][0]);
    b[1] = (cornerPoints[5][1] - cornerPoints[4][1]);
    b[2] = (cornerPoints[5][2] - cornerPoints[4][2]);

    vtkMath::Cross(a, b, result0);

    a[0] = (cornerPoints[0][0] - cornerPoints[6][0]);
    a[1] = (cornerPoints[0][1] - cornerPoints[6][1]);
    a[2] = (cornerPoints[0][2] - cornerPoints[6][2]);

    b[0] = (cornerPoints[0][0] - cornerPoints[2][0]);
    b[1] = (cornerPoints[0][1] - cornerPoints[2][1]);
    b[2] = (cornerPoints[0][2] - cornerPoints[2][2]);

    vtkMath::Cross(a, b, result1);

    a[0] = (cornerPoints[2][0] - cornerPoints[7][0]);
    a[1] = (cornerPoints[2][1] - cornerPoints[7][1]);
    a[2] = (cornerPoints[2][2] - cornerPoints[7][2]);

    b[0] = (cornerPoints[2][0] - cornerPoints[6][0]);
    b[1] = (cornerPoints[2][1] - cornerPoints[6][1]);
    b[2] = (cornerPoints[2][2] - cornerPoints[6][2]);

    vtkMath::Cross(a, b, result2);

    vtkMath::Normalize(result0);
    vtkMath::Normalize(result1);
    vtkMath::Normalize(result2);

    // create cube for rendering bounding box
    auto cube = vtkCubeSource::New();
    cube->SetXLength(extent[0] / spacing[0]);
    cube->SetYLength(extent[1] / spacing[1]);
    cube->SetZLength(extent[2] / spacing[2]);

    // calculates translation based on offset+extent not on the transformation matrix
    vtkSmartPointer<vtkMatrix4x4> imageTransform = geometry->GetVtkTransform()->GetMatrix();
    auto translation = vtkSmartPointer<vtkTransform>::New();
    translation->Translate(center[0] - imageTransform->GetElement(0, 3),
      center[1] - imageTransform->GetElement(1, 3),
      center[2] - imageTransform->GetElement(2, 3));

    auto transform = vtkSmartPointer<vtkTransform>::New();
    transform->SetMatrix(imageTransform);
    transform->PostMultiply();
    transform->Concatenate(translation);
    transform->Update();
    cube->Update();

    auto transformFilter = vtkSmartPointer<vtkTransformFilter>::New();
    transformFilter->SetInputData(cube->GetOutput());
    transformFilter->SetTransform(transform);
    transformFilter->Update();
    cube->Delete();

    vtkSmartPointer<vtkPolyData> polydata = transformFilter->GetPolyDataOutput();
    if (polydata == nullptr || (polydata->GetNumberOfPoints() < 1))
    {
      localStorage->m_Actor->VisibilityOff();
      localStorage->m_HandleActor->VisibilityOff();
      localStorage->m_SelectedHandleActor->VisibilityOff();
      return;
    }

    // estimate current image plane to decide whether the cube is visible or not
    const PlaneGeometry *planeGeometry = renderer->GetCurrentWorldPlaneGeometry();
    if ((planeGeometry == nullptr) || (!planeGeometry->IsValid()) || (!planeGeometry->HasReferenceGeometry()))
      return;

    double origin[3];
    origin[0] = planeGeometry->GetOrigin()[0];
    origin[1] = planeGeometry->GetOrigin()[1];
    origin[2] = planeGeometry->GetOrigin()[2];

    double normal[3];
    normal[0] = planeGeometry->GetNormal()[0];
    normal[1] = planeGeometry->GetNormal()[1];
    normal[2] = planeGeometry->GetNormal()[2];

    //    MITK_INFO << "normal1 " << normal[0] << " " << normal[1] << " " << normal[2];
    localStorage->m_CuttingPlane->SetOrigin(origin);
    localStorage->m_CuttingPlane->SetNormal(normal);

    // add cube polydata to local storage
    localStorage->m_Cutter->SetInputData(polydata);
    localStorage->m_Cutter->SetGenerateCutScalars(1);
    localStorage->m_Cutter->Update();

    if (localStorage->m_PropAssembly->GetParts()->IsItemPresent(localStorage->m_HandleActor))
      localStorage->m_PropAssembly->RemovePart(localStorage->m_HandleActor);
    if (localStorage->m_PropAssembly->GetParts()->IsItemPresent(localStorage->m_Actor))
      localStorage->m_PropAssembly->RemovePart(localStorage->m_Actor);

    vtkCoordinate *tcoord = vtkCoordinate::New();
    tcoord->SetCoordinateSystemToWorld();
    localStorage->m_HandleMapper->SetTransformCoordinate(tcoord);
    tcoord->Delete();

    if (localStorage->m_Cutter->GetOutput()->GetNumberOfPoints() > 0) // if plane is visible in the renderwindow
    {
      mitk::DoubleProperty::Pointer handleSizeProperty =
        dynamic_cast<mitk::DoubleProperty *>(this->GetDataNode()->GetProperty("Bounding Shape.Handle Size Factor"));

      ScalarType initialHandleSize;
      if (handleSizeProperty != nullptr)
        initialHandleSize = handleSizeProperty->GetValue();
      else
        initialHandleSize = 1.0 / 40.0;

      mitk::Point2D displaySize = renderer->GetDisplaySizeInMM();
      double handleSize = ((displaySize[0] + displaySize[1]) / 2.0) * initialHandleSize;

      auto appendPoly = vtkSmartPointer<vtkAppendPolyData>::New();
      unsigned int i = 0;

      // add handles and their assigned properties to the local storage
      mitk::IntProperty::Pointer activeHandleId =
        dynamic_cast<mitk::IntProperty *>(node->GetProperty("Bounding Shape.Active Handle ID"));

      bool visible = false;
      bool selected = false;
      for (auto handle : localStorage->m_Handles)
      {
        Point3D handleCenter = m_Impl->HandlePropertyList[i].GetPosition();

        handle->SetRadius(handleSize);
        handle->SetCenter(handleCenter[0], handleCenter[1], handleCenter[2]);

        vtkMath::Normalize(normal);
        double angle = vtkMath::DegreesFromRadians(acos(vtkMath::Dot(normal, result0)));
        double angle1 = vtkMath::DegreesFromRadians(acos(vtkMath::Dot(normal, result1)));
        double angle2 = vtkMath::DegreesFromRadians(acos(vtkMath::Dot(normal, result2)));

        // show handles only if the corresponding face is aligned to the render window
        if ((((std::abs(angle - 0) < 0.001) || (std::abs(angle - 180) < 0.001)) && i != 0 && i != 1) ||
          (((std::abs(angle1 - 0) < 0.001) || (std::abs(angle1 - 180) < 0.001)) && i != 2 && i != 3) ||
          (((std::abs(angle2 - 0) < 0.001) || (std::abs(angle2 - 180) < 0.001)) && i != 4 && i != 5))
        {
          if (activeHandleId == nullptr)
          {
            appendPoly->AddInputConnection(handle->GetOutputPort());
          }
          else
          {
            if ((activeHandleId->GetValue() != m_Impl->HandlePropertyList[i].GetIndex()))
            {
              appendPoly->AddInputConnection(handle->GetOutputPort());
            }
            else
            {
              handle->Update();
              localStorage->m_SelectedHandleMapper->SetInputData(handle->GetOutput());
              localStorage->m_SelectedHandleActor->VisibilityOn();
              selected = true;
            }
          }
          visible = true;
        }

        i++;
      }

      if (visible)
      {
        appendPoly->Update();
      }
      else
      {
        localStorage->m_HandleActor->VisibilityOff();
        localStorage->m_SelectedHandleActor->VisibilityOff();
      }

      auto stripper = vtkSmartPointer<vtkStripper>::New();
      stripper->SetInputData(localStorage->m_Cutter->GetOutput());
      stripper->Update();

      auto cutPolyData = vtkSmartPointer<vtkPolyData>::New();
      cutPolyData->SetPoints(stripper->GetOutput()->GetPoints());
      cutPolyData->SetPolys(stripper->GetOutput()->GetLines());

      localStorage->m_Actor->GetMapper()->SetInputDataObject(cutPolyData);
      mitk::ColorProperty::Pointer selectedColor = dynamic_cast<mitk::ColorProperty *>(node->GetProperty("color"));
      if (selectedColor != nullptr)
      {
        mitk::Color color = selectedColor->GetColor();
        localStorage->m_Actor->GetProperty()->SetColor(color[0], color[1], color[2]);
      }

      if (activeHandleId != nullptr)
      {
        localStorage->m_HandleActor->GetProperty()->SetColor(1, 0, 0);
      }
      else
      {
        localStorage->m_HandleActor->GetProperty()->SetColor(1, 1, 1);
      }
      localStorage->m_HandleActor->GetMapper()->SetInputDataObject(appendPoly->GetOutput());

      // add parts to the overall storage
      localStorage->m_PropAssembly->AddPart(localStorage->m_Actor);
      localStorage->m_PropAssembly->AddPart(localStorage->m_HandleActor);
      if (selected)
      {
        localStorage->m_PropAssembly->AddPart(localStorage->m_SelectedHandleActor);
      }

      localStorage->m_PropAssembly->VisibilityOn();
      localStorage->m_Actor->VisibilityOn();
      localStorage->m_HandleActor->VisibilityOn();
    }
    else
    {
      localStorage->m_PropAssembly->VisibilityOff();
      localStorage->m_Actor->VisibilityOff();
      localStorage->m_HandleActor->VisibilityOff();
      localStorage->m_SelectedHandleActor->VisibilityOff();
      localStorage->UpdateGenerateDataTime();
    }
    localStorage->UpdateGenerateDataTime();
  }
}
Example #22
0
void Triangle::SetPointB(const Point& B) {
    SetPoints(GetPointA(), B, GetPointC());
}
Example #23
0
void Triangle::SetPoints(const Vector2D& pointA, const Vector2D& pointB, const Vector2D& pointC) {
    SetPoints(Point(pointA), Point(pointB), Point(pointC));
}
Example #24
0
void Triangle::SetPoints(double xA, double yA, double xB, double yB, double xC, double yC) {
    SetPoints(Vector2D(xA, yA), Vector2D(xB, yB), Vector2D(xC, yC));
}
Example #25
0
void PickCallbackFunction(vtkObject* caller, long unsigned int vtkNotUsed(eventId),
	void* clientData, void* vtkNotUsed(callData))
{
	vtkAreaPicker *areaPicker = static_cast<vtkAreaPicker*>(caller);
	iARenderer *ren = static_cast<iARenderer*>(clientData);
	ren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->RemoveActor(ren->selectedActor);

	auto extractSelection = vtkSmartPointer<vtkExtractSelectedFrustum>::New();
	extractSelection->SetInputData(0, ren->getRenderObserver()->GetImageData());
	extractSelection->PreserveTopologyOff();
	extractSelection->SetFrustum(areaPicker->GetFrustum());
	extractSelection->Update();

	if (!extractSelection->GetOutput()->GetNumberOfElements(vtkUnstructuredGrid::CELL))
	{
		ren->emitNoSelectedCells();
		return;
	}
	
	if (ren->GetInteractor()->GetControlKey() &&
		!ren->GetInteractor()->GetShiftKey())
	{
		// Adds cells to selection
		auto append = vtkSmartPointer<vtkAppendFilter>::New();
		append->AddInputData(ren->finalSelection);
		append->AddInputData(extractSelection->GetOutput());
		append->Update();
		ren->finalSelection->ShallowCopy(append->GetOutput());
	}
	else if (ren->GetInteractor()->GetControlKey() &&
		ren->GetInteractor()->GetShiftKey())
	{
		// Removes cells from selection 
		auto newfinalSel = vtkSmartPointer<vtkUnstructuredGrid>::New();
		newfinalSel->Allocate(1, 1);
		newfinalSel->SetPoints(ren->finalSelection->GetPoints());
		auto currSel = vtkSmartPointer<vtkUnstructuredGrid>::New();
		currSel->ShallowCopy(extractSelection->GetOutput());
		double f_Cell[DIM] = { 0,0,0 }, c_Cell[DIM] = { 0,0,0 };
		double* spacing = ren->getRenderObserver()->GetImageData()->GetSpacing();

		for (vtkIdType i = 0; i < ren->finalSelection->GetNumberOfCells(); ++i)
		{
			bool addCell = true;
			GetCellCenter(ren->finalSelection, i, f_Cell, spacing);
			for (vtkIdType j = 0; j < currSel->GetNumberOfCells(); ++j)
			{
				GetCellCenter(currSel, j, c_Cell, spacing);
				if (f_Cell[0] == c_Cell[0] &&
					f_Cell[1] == c_Cell[1] &&
					f_Cell[2] == c_Cell[2])
				{
					addCell = false;
					break;
				}
			}
			if (addCell)
				newfinalSel->InsertNextCell(ren->finalSelection->GetCell(i)->GetCellType(),
					ren->finalSelection->GetCell(i)->GetPointIds());
		}		
		ren->finalSelection->ShallowCopy(newfinalSel);
	}
	else
	{
		// New selection
		ren->finalSelection->ShallowCopy(extractSelection->GetOutput());
	}
	ren->selectedMapper->Update();
	ren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(ren->selectedActor);
	ren->emitSelectedCells(ren->finalSelection);
}
Example #26
0
void Player::Reset()
{
	m_paddle.Reset();
	SetPoints(0);
	SetLives(DEFAULT_LIVES);
}
Example #27
0
void Triangle::SetPointA(const Point& A) {
    SetPoints(A, GetPointB(), GetPointC());
}
Example #28
0
/**
Create the vtkStructuredGrid from the provided workspace
@param progressUpdating: Reporting object to pass progress information up the
stack.
@return fully constructed vtkDataSet.
*/
vtkSmartPointer<vtkDataSet>
vtkMDLineFactory::create(ProgressAction &progressUpdating) const {
  auto product = tryDelegatingCreation<IMDEventWorkspace, 1>(m_workspace,
                                                             progressUpdating);
  if (product != nullptr) {
    return product;
  } else {
    g_log.warning() << "Factory " << this->getFactoryTypeName()
                    << " is being used. You are viewing data with less than "
                       "three dimensions in the VSI. \n";

    IMDEventWorkspace_sptr imdws =
        doInitialize<IMDEventWorkspace, 1>(m_workspace);
    // Acquire a scoped read-only lock to the workspace (prevent segfault from
    // algos modifying ws)
    Mantid::Kernel::ReadLock lock(*imdws);

    const size_t nDims = imdws->getNumDims();
    size_t nNonIntegrated = imdws->getNonIntegratedDimensions().size();

    /*
    Write mask array with correct order for each internal dimension.
    */
    auto masks = Mantid::Kernel::make_unique<bool[]>(nDims);
    for (size_t i_dim = 0; i_dim < nDims; ++i_dim) {
      bool bIntegrated = imdws->getDimension(i_dim)->getIsIntegrated();
      masks[i_dim] =
          !bIntegrated; // TRUE for unmaksed, integrated dimensions are masked.
    }

    // Ensure destruction in any event.
    boost::scoped_ptr<IMDIterator> it(
        createIteratorWithNormalization(m_normalizationOption, imdws.get()));

    // Create 2 points per box.
    vtkNew<vtkPoints> points;
    points->SetNumberOfPoints(it->getDataSize() * 2);

    // One scalar per box
    vtkNew<vtkFloatArray> signals;
    signals->Allocate(it->getDataSize());
    signals->SetName(vtkDataSetFactory::ScalarName.c_str());
    signals->SetNumberOfComponents(1);

    size_t nVertexes;

    auto visualDataSet = vtkSmartPointer<vtkUnstructuredGrid>::New();
    visualDataSet->Allocate(it->getDataSize());

    vtkNew<vtkIdList> linePointList;
    linePointList->SetNumberOfIds(2);

    Mantid::API::CoordTransform const *transform = NULL;
    if (m_useTransform) {
      transform = imdws->getTransformToOriginal();
    }

    Mantid::coord_t out[1];
    auto useBox = std::vector<bool>(it->getDataSize());

    double progressFactor = 0.5 / double(it->getDataSize());
    double progressOffset = 0.5;

    size_t iBox = 0;
    do {
      progressUpdating.eventRaised(double(iBox) * progressFactor);

      Mantid::signal_t signal_normalized = it->getNormalizedSignal();
      if (std::isfinite(signal_normalized) &&
          m_thresholdRange->inRange(signal_normalized)) {
        useBox[iBox] = true;
        signals->InsertNextValue(static_cast<float>(signal_normalized));

        auto coords = std::unique_ptr<coord_t[]>(
            it->getVertexesArray(nVertexes, nNonIntegrated, masks.get()));

        // Iterate through all coordinates. Candidate for speed improvement.
        for (size_t v = 0; v < nVertexes; ++v) {
          coord_t *coord = coords.get() + v * 1;
          size_t id = iBox * 2 + v;
          if (m_useTransform) {
            transform->apply(coord, out);
            points->SetPoint(id, out[0], 0, 0);
          } else {
            points->SetPoint(id, coord[0], 0, 0);
          }
        }
      } // valid number of vertexes returned
      else {
        useBox[iBox] = false;
      }
      ++iBox;
    } while (it->next());

    for (size_t ii = 0; ii < it->getDataSize(); ++ii) {
      progressUpdating.eventRaised((double(ii) * progressFactor) +
                                   progressOffset);

      if (useBox[ii] == true) {
        vtkIdType pointIds = ii * 2;

        linePointList->SetId(0, pointIds + 0); // xyx
        linePointList->SetId(1, pointIds + 1); // dxyz
        visualDataSet->InsertNextCell(VTK_LINE, linePointList.GetPointer());
      } // valid number of vertexes returned
    }

    signals->Squeeze();
    points->Squeeze();

    visualDataSet->SetPoints(points.GetPointer());
    visualDataSet->GetCellData()->SetScalars(signals.GetPointer());
    visualDataSet->Squeeze();

    // Hedge against empty data sets
    if (visualDataSet->GetNumberOfPoints() <= 0) {
      vtkNullUnstructuredGrid nullGrid;
      visualDataSet = nullGrid.createNullData();
    }

    vtkSmartPointer<vtkDataSet> dataset = visualDataSet;
    return dataset;
  }
}
        std::string dump(Mesh* mesh, int step, std::string fileName) const
        {
            auto _mesh = dynamic_cast<MeshType*>(mesh);
            assert_true(_mesh);

            LOG_DEBUG("Writing snapshot for mesh \"" << _mesh->getId() << "\" at step " << step << " to file " << fileName);

            auto grid = vtkSmartPointer<GridType>::New();
            auto points = vtkSmartPointer<vtkPoints>::New();

            auto contact = vtkSmartPointer<vtkIntArray>::New();
            contact->SetName("contact");

            auto border = vtkSmartPointer<vtkIntArray>::New();
            border->SetName("border");

            auto used = vtkSmartPointer<vtkIntArray>::New();
            used->SetName("used");

            auto norm = vtkSmartPointer<vtkDoubleArray>::New();
            norm->SetName("norm");
            norm->SetNumberOfComponents(3);

            auto vel = vtkSmartPointer<vtkDoubleArray>::New();
            vel->SetName("velocity");
            vel->SetNumberOfComponents(3);

            auto crack = vtkSmartPointer<vtkDoubleArray>::New();
            crack->SetName("crack");
            crack->SetNumberOfComponents(3);

            auto sxx = vtkSmartPointer<vtkDoubleArray>::New();
            sxx->SetName("sxx");

            auto sxy = vtkSmartPointer<vtkDoubleArray>::New();
            sxy->SetName("sxy");

            auto sxz = vtkSmartPointer<vtkDoubleArray>::New();
            sxz->SetName("sxz");

            auto syy = vtkSmartPointer<vtkDoubleArray>::New();
            syy->SetName("syy");

            auto syz = vtkSmartPointer<vtkDoubleArray>::New();
            syz->SetName("syz");

            auto szz = vtkSmartPointer<vtkDoubleArray>::New();
            szz->SetName("szz");

            auto compression = vtkSmartPointer<vtkDoubleArray>::New();
            compression->SetName("compression");

            auto tension = vtkSmartPointer<vtkDoubleArray>::New();
            tension->SetName("tension");

            auto shear = vtkSmartPointer<vtkDoubleArray>::New();
            shear->SetName("shear");

            auto deviator = vtkSmartPointer<vtkDoubleArray>::New();
            deviator->SetName("deviator");

            auto matId = vtkSmartPointer<vtkIntArray>::New();
            matId->SetName("materialID");

            auto rho = vtkSmartPointer<vtkDoubleArray>::New();
            rho->SetName("rho");

            auto mpiState = vtkSmartPointer<vtkIntArray>::New();
            mpiState->SetName("mpiState");

            auto nodePublicFlags = vtkSmartPointer<vtkIntArray>::New ();
            nodePublicFlags->SetName ("publicFlags");

            auto nodePrivateFlags = vtkSmartPointer<vtkIntArray>::New ();
            nodePrivateFlags->SetName ("privateFlags");

            auto nodeErrorFlags = vtkSmartPointer<vtkIntArray>::New ();
            nodeErrorFlags->SetName ("errorFlags");

            auto nodeNumber = vtkSmartPointer<vtkIntArray>::New ();
            nodeNumber->SetName ("nodeNumber");

            auto nodeBorderConditionId = vtkSmartPointer<vtkIntArray>::New ();
            nodeBorderConditionId->SetName ("borderConditionId");

            auto nodeContactConditionId = vtkSmartPointer<vtkIntArray>::New();
            nodeContactConditionId->SetName("contactState");

            auto contactDestroyed = vtkSmartPointer<vtkIntArray>::New();
            contactDestroyed->SetName("failedContacts");

            auto nodeDestroyed = vtkSmartPointer<vtkIntArray>::New();
            nodeDestroyed->SetName("failedNodes");

            auto nodeFailureMeasure = vtkSmartPointer<vtkDoubleArray>::New();
            nodeFailureMeasure->SetName("failureMeasure");

            float _norm[3];

            dumpMeshSpecificData(_mesh, grid, points);

            for (auto it = MeshNodeIterator<MeshType, snapshotterId>(_mesh); it.hasNext(); it++)
            {
                auto& node = *it;

                border->InsertNextValue(node.isBorder() ? 1 : 0);
                used->InsertNextValue(node.isUsed() ? 1 : 0);
                contact->InsertNextValue(node.isInContact() ? 1 : 0);

                if (node.isUsed() && node.isBorder())
                    _mesh->findBorderNodeNormal(node, _norm, _norm+1, _norm+2, false);
                else
                    _norm[0] = _norm[1] = _norm[2] = 0.0;
                norm->InsertNextTuple(_norm);

                vel->InsertNextTuple(node.velocity);
                crack->InsertNextTuple(node.getCrackDirection().coords);
                sxx->InsertNextValue(node.sxx);
                sxy->InsertNextValue(node.sxy);
                sxz->InsertNextValue(node.sxz);
                syy->InsertNextValue(node.syy);
                syz->InsertNextValue(node.syz);
                szz->InsertNextValue(node.szz);
                compression->InsertNextValue(node.getCompression());
                tension->InsertNextValue(node.getTension());
                shear->InsertNextValue(node.getShear());
                deviator->InsertNextValue(node.getDeviator());
                matId->InsertNextValue(node.getMaterialId());
                rho->InsertNextValue(node.getRho());
                mpiState->InsertNextValue(node.isRemote() ? 1 : 0);
                nodePrivateFlags->InsertNextValue (node.getPrivateFlags());
                nodePublicFlags->InsertNextValue (node.getPublicFlags());
                nodeErrorFlags->InsertNextValue (node.getErrorFlags());
                nodeBorderConditionId->InsertNextValue (node.getBorderConditionId());
				nodeContactConditionId->InsertNextValue(node.getContactConditionId());
                nodeNumber->InsertNextValue(node.number);
                contactDestroyed->InsertNextValue(node.isContactDestroyed() ? 1 : 0);
                nodeDestroyed->InsertNextValue(node.isDestroyed() ? 1 : 0);
                nodeFailureMeasure->InsertNextValue(node.getDamageMeasure());
            }

           vtkFieldData* fd;

           if (useCells)
               fd = grid->GetCellData();
           else
               fd = grid->GetPointData();

           grid->SetPoints(points);

           fd->AddArray(contact);
           fd->AddArray(border);
           fd->AddArray(used);
           fd->AddArray(norm);
           fd->AddArray(crack);
           fd->AddArray(sxx);
           fd->AddArray(sxy);
           fd->AddArray(sxz);
           fd->AddArray(syy);
           fd->AddArray(syz);
           fd->AddArray(szz);
           fd->AddArray(compression);
           fd->AddArray(tension);
           fd->AddArray(shear);
           fd->AddArray(deviator);
           fd->AddArray(matId);
           fd->AddArray(rho);
           fd->AddArray(mpiState);
           fd->AddArray (nodePrivateFlags);
           fd->AddArray (nodePublicFlags);
           fd->AddArray (nodeErrorFlags);
           fd->AddArray (nodeBorderConditionId);
           fd->AddArray (nodeContactConditionId);
           fd->AddArray(vel);
           fd->AddArray(nodeNumber);
           fd->AddArray(contactDestroyed);
           fd->AddArray(nodeDestroyed);
           fd->AddArray(nodeFailureMeasure);

           // Write file
           auto writer = vtkSmartPointer<GridWriterType>::New();
           writer->SetFileName(fileName.c_str());
           #ifdef CONFIG_VTK_5
           writer->SetInput(grid);
           #else
           writer->SetInputData(grid);
           #endif
           writer->Write();

           return fileName;
        }