// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AbaqusSurfaceMeshWriter::execute()
{
  int err = 0;
  std::stringstream ss;

  SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer();
  dataCheck(false, 1, 1, 1);
  if(getErrorCondition() < 0)
  {
    return;
  }

  // Make sure any directory path is also available as the user may have just typed
  // in a path without actually creating the full path
  std::string parentPath = MXAFileInfo::parentPath(getOutputFile());
  if(!MXADir::mkdir(parentPath, true))
  {
    std::stringstream ss;
    ss << "Error creating parent path '" << parentPath << "'";
    notifyErrorMessage(ss.str(), -1);
    setErrorCondition(-1);
    return;
  }

  DREAM3D::SurfaceMesh::VertListPointer_t nodesPtr = sm->getVertices();
  DREAM3D::SurfaceMesh::FaceListPointer_t trianglePtr = sm->getFaces();

  // Get the Labels(GrainIds or Region Ids) for the triangles
  Int32ArrayType::Pointer faceLabelsPtr = boost::dynamic_pointer_cast<Int32ArrayType>(sm->getFaceData(DREAM3D::FaceData::SurfaceMeshFaceLabels));
  int32_t* faceLabels = faceLabelsPtr->GetPointer(0);

  // Store all the unique Spins
  std::set<int> uniqueSpins;
  for (int i = 0; i < trianglePtr->GetNumberOfTuples(); i++)
  {
    uniqueSpins.insert(faceLabels[i*2]);
    uniqueSpins.insert(faceLabels[i*2+1]);
  }

  FILE* f = fopen(m_OutputFile.c_str(), "wb");
  ScopedFileMonitor fileMonitor(f);

  err = writeHeader(f, nodesPtr->GetNumberOfTuples(), trianglePtr->GetNumberOfTuples(), uniqueSpins.size()-1);
  err = writeNodes(f);
  err = writeTriangles(f);
  err = writeGrains(f);

  setErrorCondition(0);
  notifyStatusMessage("Complete");

  return;
}
Example #2
0
void Foam::CV2D::insertGrid()
{
    Info<< "insertInitialGrid: ";

    startOfInternalPoints_ = number_of_vertices();
    label nVert = startOfInternalPoints_;

    scalar x0 = qSurf_.globalBounds().min().x();
    scalar xR = qSurf_.globalBounds().max().x() - x0;
    int ni = int(xR/meshControls().minCellSize()) + 1;
    scalar deltax = xR/ni;

    scalar y0 = qSurf_.globalBounds().min().y();
    scalar yR = qSurf_.globalBounds().max().y() - y0;
    int nj = int(yR/meshControls().minCellSize()) + 1;
    scalar deltay = yR/nj;

    Random rndGen(1321);
    scalar pert = meshControls().randomPerturbation()*min(deltax, deltay);

    for (int i=0; i<ni; i++)
    {
        for (int j=0; j<nj; j++)
        {
            point p(x0 + i*deltax, y0 + j*deltay, 0);

            if (meshControls().randomiseInitialGrid())
            {
                p.x() += pert*(rndGen.scalar01() - 0.5);
                p.y() += pert*(rndGen.scalar01() - 0.5);
            }

            if (qSurf_.wellInside(p, 0.5*meshControls().minCellSize2()))
            {
                insert(Point(p.x(), p.y()))->index() = nVert++;
            }
        }
    }

    Info<< nVert << " vertices inserted" << endl;

    if (meshControls().objOutput())
    {
        // Checking validity of triangulation
        assert(is_valid());

        writeTriangles("initial_triangles.obj", true);
        writeFaces("initial_faces.obj", true);
    }
}
Example #3
0
void Foam::CV2D::insertPoints
(
    const point2DField& points,
    const scalar nearness
)
{
    Info<< "insertInitialPoints(const point2DField& points): ";

    startOfInternalPoints_ = number_of_vertices();
    label nVert = startOfInternalPoints_;

    // Add the points and index them
    forAll(points, i)
    {
        const point2D& p = points[i];

        if (qSurf_.wellInside(toPoint3D(p), nearness))
        {
            insert(toPoint(p))->index() = nVert++;
        }
        else
        {
            Warning
                << "Rejecting point " << p << " outside surface" << endl;
        }
    }

    Info<< nVert << " vertices inserted" << endl;

    if (meshControls().objOutput())
    {
        // Checking validity of triangulation
        assert(is_valid());

        writeTriangles("initial_triangles.obj", true);
        writeFaces("initial_faces.obj", true);
    }
}
Example #4
0
int main(int argc, char** argv) {
	Point bottomPoint = Point(-3.0, -3.0, -3.0);
	Point topPoint = Point(3.0, 3.0, 3.0);
	
	float res = .2;
	Grid g = Grid(topPoint, bottomPoint, res);

	std::vector< std::vector <Point> > trianglesList;
	std::vector< std::vector<int> > rotations = createRotationTable();

	std::cout << "Processing of each cubes ... ";
	
	for (int i = 0; i < g.listOfCubes.size(); i++) {
		int f = (int)(((float) i)*100.0/((float) g.listOfCubes.size()));
		if (i%1000 == 0)
			std::cout << f << "%... ";

		std::vector< std::vector <Point> > newTriangles = cubeProcessing(g.listOfCubes[i], rotations, res);

		if (newTriangles.size() != 0)
			trianglesList.insert(trianglesList.end(), newTriangles.begin(), newTriangles.end());
	}
	std::cout << "done!" << std::endl;	

	int nbVertices = 3 * trianglesList.size();
	int nbTriangles = trianglesList.size();

	std::ofstream plyFile;
  	plyFile.open("mcResult.ply");
  	writeHeader(plyFile, nbVertices, nbTriangles);
  	writeVertices(plyFile, trianglesList);
  	writeTriangles(plyFile, nbTriangles);
  	plyFile.close();
  	

	return 0;
}
Example #5
0
int main (int argc, char **argv)
{
	Options mergetr = readParameters (argc, argv);

	char filename_mesh_node[FILENAME_MAX];
	char filename_mesh_ele[FILENAME_MAX];
	char filename_otoczka[FILENAME_MAX];
	char filename_output_node[FILENAME_MAX];
	char filename_output_ele[FILENAME_MAX];
	int no_of_meshes = argc-mergetr.args_start;

	strcpy (filename_otoczka, mergetr.input);
	if ( strstr (filename_otoczka, ".poly") == NULL) 
		strcat (filename_otoczka,  ".poly");

	strcpy (filename_output_node, mergetr.output);
	strcat (filename_output_node,  ".node");
	strcpy (filename_output_ele, mergetr.output);
	strcat (filename_output_ele,  ".ele");

	fprintf(stdout, "************************************\n");
	fprintf(stdout, "***** M * E * R * G * E * T * R ****\n");
	fprintf(stdout, "************************************\n");
	fprintf(stdout, "* Otoczka filename: %s\n", filename_otoczka);
	fprintf(stdout, "* Output filenames: %s & %s\n", filename_output_node, filename_output_ele);
	fprintf(stdout, "* Triangle options: %s\n", mergetr.tr_opt);
	fprintf(stdout, "************************************\n");

	struct triangulateio *siatka;
	struct triangulateio otoczka;
	struct triangulateio out;	
	EdgeList **v;
	PointList **p;
	int i;

	siatka = malloc ( no_of_meshes * sizeof *siatka);
	v = malloc ( no_of_meshes * sizeof **v );
	p = malloc ( no_of_meshes * sizeof **p );
		
	if (siatka == NULL || v == NULL || p == NULL) {
		fprintf (stderr, "** Error! Not enough memory!");
		return -1;
	}		

	initTriangulation (&otoczka);
	
	/* OTOCZKA */
	FILE *file_otoczka = fopen( filename_otoczka, "r"); 

	if (file_otoczka == NULL) {
		fprintf(stderr, "** Error while opening %s\n", filename_otoczka);
		return -100;
	}

	readPoints (file_otoczka, &otoczka);
	readSegments (file_otoczka, &otoczka);
	readHoles (file_otoczka, &otoczka);
	readRegions (file_otoczka, &otoczka);

	fclose (file_otoczka);

	/* MESHES */
	for (i = 0; i < (argc - mergetr.args_start); i++) {

		strcpy (filename_mesh_node, argv[mergetr.args_start+i]);
		strcat (filename_mesh_node, ".node");
		strcpy (filename_mesh_ele, argv[mergetr.args_start+i]);
		strcat (filename_mesh_ele, ".ele");

		fprintf(stdout, "************************************\n");
		fprintf(stdout, "* Mesh filenames: %s & %s\n", filename_mesh_node, filename_mesh_ele);
		
		fprintf(stdout, "************************************\n");

		FILE *file_mesh_node = fopen( filename_mesh_node, "r"); 
		FILE *file_mesh_ele = fopen( filename_mesh_ele, "r");
		
		if (file_mesh_node == NULL) {
			fprintf(stderr, "** Error while opening %s\n", filename_mesh_node);
			return -101;
		}
		if (file_mesh_node == NULL) {
			fprintf(stderr, "** Error while opening %s\n", filename_mesh_ele);
			return -102;
		}

		initTriangulation (&siatka[i]);
		readPoints (file_mesh_node, &siatka[i]);
		readTriangles (file_mesh_ele, &siatka[i]); 
	
		fclose (file_mesh_node);
		fclose (file_mesh_ele);	
	
		v[i] = createEdgeList(siatka[i]);
		markBndEdges (siatka[i], v[i]);
		p[i] = makePointList (otoczka, siatka[i], v[i]);
		
		updatePoints (&otoczka, siatka[i], v[i], p[i]);
		updateSegments (&otoczka, siatka[i], v[i], p[i]);
		updateHoles (&otoczka, siatka[i]);
	}

	fprintf(stdout, "************************************\n");

	/* TRIANGULAtE */
	initTriangulation (&out);
	strcat (mergetr.tr_opt, "pYYQ");

	triangulate (mergetr.tr_opt, &otoczka, &out, (struct triangulateio *) NULL);
	
	/* GLUE HOLES */
	/* markNotBndEdges (siatka1, v); */
	for (i = 0; i < no_of_meshes; i++) {
		glueNotBndPoints (&out, siatka[i], p[i]); /* DOKLEJANIE DO OUT */
		fixPointListNumbers (&out, &siatka[i], p[i]);
		glueInteriorTriangles (&out, siatka[i], p[i]);
		removeHole (&out);
	}	

	FILE *file_output_node = fopen (filename_output_node, "w");
	FILE *file_output_ele = fopen (filename_output_ele, "w");
	
	writePoints (file_output_node, out);
	writeTriangles (file_output_ele, out);

	fclose (file_output_node);
	fclose (file_output_ele);

	fprintf(stdout, "************************************\n");

	free (p);
	free (v);
	freeTriangulation (&otoczka);
	freeTriangulation (&out);
	for (i = 0; i < no_of_meshes; i++)
		freeTriangulation (&siatka[i]);
		
	return 0;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AbaqusSurfaceMeshWriter::execute()
{
  int32_t err = 0;
  setErrorCondition(err);
  dataCheck();
  if(getErrorCondition() < 0) { return; }

  DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName());

  // Make sure any directory path is also available as the user may have just typed
  // in a path without actually creating the full path
  QFileInfo fi(getOutputFile());
  QDir parentPath = fi.path();
  if(!parentPath.mkpath("."))
  {
    QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath());
    setErrorCondition(-8005);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  TriangleGeom::Pointer triangleGeom = sm->getGeometryAs<TriangleGeom>();

  // Store all the unique Spins
  std::set<int32_t> uniqueSpins;
  for (int64_t i = 0; i < triangleGeom->getNumberOfTris(); i++)
  {
    uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2]);
    uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2 + 1]);
  }

  FILE* f = fopen(m_OutputFile.toLatin1().data(), "wb");
  ScopedFileMonitor fileMonitor(f);

  err = writeHeader(f, triangleGeom->getNumberOfVertices(), triangleGeom->getNumberOfTris(), uniqueSpins.size() - 1);
  if(err < 0)
  {
    QString ss = QObject::tr("Error writing header for file '%1'").arg(m_OutputFile);
    setErrorCondition(-8001);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }
  err = writeNodes(f);
  if(err < 0)
  {
    QString ss = QObject::tr("Error writing nodes for file '%1'").arg(m_OutputFile);
    setErrorCondition(-8002);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }
  err = writeTriangles(f);
  if(err < 0)
  {
    QString ss = QObject::tr("Error writing triangles for file '%1'").arg(m_OutputFile);
    setErrorCondition(-8003);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }
  err = writeFeatures(f);
  if(err < 0)
  {
    QString ss = QObject::tr("Error writing Features for file '%1'").arg(m_OutputFile);
    setErrorCondition(-8004);
    notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
    return;
  }

  notifyStatusMessage(getHumanLabel(), "Complete");
}