Exemplo n.º 1
0
void writePointCloud(const char *filename, short *edges, unsigned char *edge_colors)
{
	console_printf("exporter: exporting point cloud...\n");
	// copy borders
	memcpy(edges, edges + scan_camera->height * STEPS, scan_camera->height * sizeof(short));
	memcpy(edges + scan_camera->height * (STEPS + 1), edges + scan_camera->height, scan_camera->height * sizeof(short));

	FILE *file = fopen(filename, "wt");
	long vcp = writeHeader(file);
	int vertexCount = writeEdges(file, edges, edge_colors);
	fclose(file);

	file = fopen(filename, "r+");
	writeVertexCount(file, vcp, vertexCount);
	fclose(file);
	console_printf("exporter: wrote %d points\n", vertexCount);
}
Exemplo n.º 2
0
void Foam::fileFormats::VTKedgeFormat::write
(
    const fileName& filename,
    const edgeMesh& eMesh
)
{
    OFstream os(filename);
    if (!os.good())
    {
        FatalErrorIn
        (
            "fileFormats::VTKedgeFormat::write"
            "(const fileName&, const edgeMesh&)"
        )
            << "Cannot open file for writing " << filename
            << exit(FatalError);
    }

    writeHeader(os, eMesh.points());
    writeEdges(os, eMesh.edges());
}
Exemplo n.º 3
0
static void writeGraph(
	std::ostream &os,
	const Graph &G, const GraphAttributes *GA)
{
	const long long n = G.numberOfNodes(), m = G.numberOfEdges();

	os << "DL N = " << n << "\n";

	// We pick output format basing on edge density.
	enum { matrix, edges } format = (m > (n * n / 2)) ? matrix : edges;

	// Specify output format.
	os << "FORMAT = ";
	if(format == matrix) {
		os << "fullmatrix\n";
		writeMatrix(os, G, GA);
	} else if(format == edges) {
		os << "edgelist1\n";
		writeEdges(os, G, GA);
	}
}
Exemplo n.º 4
0
static void writeCluster(
	std::ostream &out, int depth,
	const ClusterGraph &C, const ClusterGraphAttributes *CA, cluster c)
{
	if(C.rootCluster() != c) {
		GraphIO::indent(out, depth) << "<node "
		                            << "id=\"cluster" << c->index() << "\""
		                            << ">\n";
	} else {
		const std::string dir =
			(CA && !CA->directed()) ? "undirected" : "directed";
		GraphIO::indent(out, depth) << "<graph "
		                            << "mode=\"static\""
		                            << "defaultedgetype=\"" << dir << "\""
		                            << ">\n";

		if(CA) {
			defineAttributes(out, depth + 1, *CA);
		}
	}

	GraphIO::indent(out, depth + 1) << "<nodes>\n";

	for(ListConstIterator<cluster> cit = c->cBegin(); cit.valid(); ++cit) {
		writeCluster(out, depth + 2, C, CA, *cit);
	}

	for(ListConstIterator<node> nit = c->nBegin(); nit.valid(); ++nit) {
		writeNode(out, depth + 2, CA, *nit);
	}

	GraphIO::indent(out, depth + 1) << "</nodes>\n";

	if(C.rootCluster() != c) {
		GraphIO::indent(out, depth) << "</node>\n";
	} else {
		writeEdges(out, C.constGraph(), CA);
		GraphIO::indent(out, depth) << "</graph>\n";
	}
}
Exemplo n.º 5
0
void GLC_WorldTo3dxml::writeGeometry(const GLC_Mesh* pMesh)
{
	// Get the list of material id
	QList<GLC_uint> materialList= pMesh->materialIds();
	const int materialCount= materialList.size();

	m_pOutStream->writeStartElement("Rep");
	m_pOutStream->writeAttribute("xsi:type", "PolygonalRepType");
	m_pOutStream->writeAttribute("id", QString::number(++m_CurrentId));
	const double masterAccuracy= pMesh->getLodAccuracy(0);
	m_pOutStream->writeAttribute("accuracy", QString::number(masterAccuracy));
	m_pOutStream->writeAttribute("solid", "1");
	const int lodCount= pMesh->lodCount();
	if (lodCount > 1)
	{
		// The mesh contains LOD
		for (int i= 1; i < lodCount; ++i)
		{
			const double lodAccuracy= pMesh->getLodAccuracy(i);
			m_pOutStream->writeStartElement("PolygonalLOD");
			m_pOutStream->writeAttribute("accuracy", QString::number(lodAccuracy));
			m_pOutStream->writeStartElement("Faces");
			for (int matIndex= 0; matIndex < materialCount; ++matIndex)
			{
				const GLC_uint materialId= materialList.at(matIndex);
				if (pMesh->lodContainsMaterial(i, materialId))
				{
					writeGeometryFace(pMesh, i, materialId);
				}
			}
			m_pOutStream->writeEndElement(); // Faces
			m_pOutStream->writeEndElement(); // PolygonalLOD
		}
	}

	// Master LOD
	m_pOutStream->writeStartElement("Faces");
	for (int matIndex= 0; matIndex < materialCount; ++matIndex)
	{
		const GLC_uint materialId= materialList.at(matIndex);
		if (pMesh->lodContainsMaterial(0, materialId))
		{
			writeGeometryFace(pMesh, 0, materialId);
		}
	}
	m_pOutStream->writeEndElement(); // Faces
	if (!pMesh->wireDataIsEmpty())
	{
		writeEdges(pMesh);
	}

	// Save Bulk data
	m_pOutStream->writeStartElement("VertexBuffer");
	{
		// Get positions
		GLfloatVector positionVector= pMesh->positionVector();
		QString positions;
		const int size= positionVector.size();
		for (int i= 0; i < size; i+=3)
		{
			positions.append(QString::number(positionVector.at(i)));
			positions.append(' ');
			positions.append(QString::number(positionVector.at(i + 1)));
			positions.append(' ');
			positions.append(QString::number(positionVector.at(i + 2)));
			positions.append(", ");
		}
		positions.remove(positions.size() - 2, 2);
		m_pOutStream->writeTextElement("Positions", positions);
	}
	{
		// Get normals
		GLfloatVector normalVector= pMesh->normalVector();
		QString normals;
		const int size= normalVector.size();
		for (int i= 0; i < size; i+=3)
		{
			normals.append(QString::number(normalVector.at(i)));
			normals.append(' ');
			normals.append(QString::number(normalVector.at(i + 1)));
			normals.append(' ');
			normals.append(QString::number(normalVector.at(i + 2)));
			normals.append(", ");
		}
		normals.remove(normals.size() - 2, 2);
		m_pOutStream->writeTextElement("Normals", normals);
	}
	{
		// Get texture coordinates
		GLfloatVector texelVector= pMesh->texelVector();
		if (!texelVector.isEmpty())
		{
			QString texels;
			const int size= texelVector.size();
			for (int i= 0; i < size; i+=2)
			{
				texels.append(QString::number(texelVector.at(i)));
				texels.append(' ');
				texels.append(QString::number(texelVector.at(i + 1)));
				texels.append(", ");
			}
			texels.remove(texels.size() - 2, 2);

			m_pOutStream->writeStartElement("TextureCoordinates");
			m_pOutStream->writeAttribute("dimension", "2D");
			m_pOutStream->writeAttribute("channel", "0");
			m_pOutStream->writeCharacters(texels);
			m_pOutStream->writeEndElement(); // TexturesCoordinates
		}
	}


	m_pOutStream->writeEndElement(); // VertexBuffer
	m_pOutStream->writeEndElement(); // Rep

}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void SurfaceMeshDataContainerWriter::execute()
{
  int err = 0;
  std::stringstream ss;
  setErrorCondition(err);
  SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer();
  if(NULL == sm)
  {
    setErrorCondition(-999);
    notifyErrorMessage("The Surfacemesh DataContainer Object was NULL", -999);
    return;
  }
  setErrorCondition(0);

  // Create the HDF5 Group for the Data Container
  err = H5Utilities::createGroupsFromPath(DREAM3D::HDF5::SurfaceMeshDataContainerName.c_str(), m_HdfFileId);
  if (err < 0)
  {
    ss.str("");
    ss << "Error creating HDF Group " << DREAM3D::HDF5::SurfaceMeshDataContainerName << std::endl;
    setErrorCondition(-60);
    addErrorMessage(getHumanLabel(), ss.str(), err);
    return;
  }
  hid_t dcGid = H5Gopen(m_HdfFileId, DREAM3D::HDF5::SurfaceMeshDataContainerName.c_str(), H5P_DEFAULT );
  if (dcGid < 0)
  {
    ss.str("");
    ss << "Error opening Group " << DREAM3D::HDF5::SurfaceMeshDataContainerName << std::endl;
    setErrorCondition(-61);
    addErrorMessage(getHumanLabel(), ss.str(), err);
    return;
  }

  // Add some VTK hints into the group
  err = createVtkObjectGroup(DREAM3D::HDF5::SurfaceMeshDataContainerName, H5_VTK_POLYDATA);
  if (err < 0)  {
    return;
  }

  writeXdmfGridHeader();


  H5GroupAutoCloser dcGidAutoCloser(&dcGid);

  err = writeVertices(dcGid);
  if (err < 0)
  {
    return;
  }

  err = writeMeshVertLinks(dcGid);
  if (err < 0)
  {
    return;
  }

  err = writeVertexAttributeData(dcGid);
  if (err < 0)
  {
    return;
  }


  err = writeFaces(dcGid);
  if (err < 0)
  {
    return;
  }

  err = writeMeshFaceNeighborLists(dcGid);
  if (err < 0)
  {
    return;
  }

  err = writeFaceAttributeData(dcGid);
  if (err < 0)
  {
    return;
  }

  err = writeEdges(dcGid);
  if (err < 0)
  {
    return;
  }

  err = writeEdgeAttributeData(dcGid);
  if (err < 0)
  {
    return;
  }


  err = writeFieldData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }

  err = writeEnsembleData(dcGid);
  if (err < 0)
  {
    H5Gclose(dcGid); // Close the Data Container Group
    return;
  }


  // Now finally close the group and the HDf5 File
  H5Gclose(dcGid); // Close the Data Container Group
  dcGid = -1;

  writeXdmfGridFooter();


  notifyStatusMessage("Complete");
}