コード例 #1
0
void CModelWriterNode100_Model::writeBaseMaterials()
{
    nfUint32 nMaterialCount = m_pModel->getBaseMaterialCount();
    nfUint32 nMaterialIndex;
    nfUint32 j;

    for (nMaterialIndex = 0; nMaterialIndex < nMaterialCount; nMaterialIndex++) {
        CModelBaseMaterialResource * pBaseMaterial = m_pModel->getBaseMaterial(nMaterialIndex);

        writeStartElement(XML_3MF_ELEMENT_BASEMATERIALS);
        // Write Object ID (mandatory)
        writeIntAttribute(XML_3MF_ATTRIBUTE_BASEMATERIALS_ID, pBaseMaterial->getResourceID());

        nfUint32 nElementCount = pBaseMaterial->getCount();

        for (j = 0; j < nElementCount; j++) {
            PModelBaseMaterial pElement = pBaseMaterial->getBaseMaterial(j);
            writeStartElement(XML_3MF_ELEMENT_BASE);
            writeStringAttribute(XML_3MF_ATTRIBUTE_BASEMATERIAL_NAME, pElement->getName());
            writeStringAttribute(XML_3MF_ATTRIBUTE_BASEMATERIAL_DISPLAYCOLOR, pElement->getDisplayColorString());
            writeEndElement();

        }

        writeFullEndElement();
    }

}
コード例 #2
0
void CModelWriterNode100_Model::writeTextures2D()
{
    nfUint32 nTextureCount = m_pModel->getTexture2DCount();
    nfUint32 nTextureIndex;

    for (nTextureIndex = 0; nTextureIndex < nTextureCount; nTextureIndex++) {
        CModelTexture2DResource * pTexture2D = m_pModel->getTexture2D(nTextureIndex);

        writeStartElementWithPrefix(XML_3MF_ELEMENT_TEXTURE2D, XML_3MF_NAMESPACEPREFIX_MATERIAL);
        writeIntAttribute(XML_3MF_ATTRIBUTE_TEXTURE2D_ID, pTexture2D->getResourceID());
        writeStringAttribute(XML_3MF_ATTRIBUTE_TEXTURE2D_PATH, pTexture2D->getPath());
        writeStringAttribute(XML_3MF_ATTRIBUTE_TEXTURE2D_CONTENTTYPE, pTexture2D->getContentTypeString());

        std::wstring sTileStyle;
        sTileStyle = pTexture2D->getTileStyleU();
        if (sTileStyle.size() > 0)
            writeStringAttribute(XML_3MF_ATTRIBUTE_TEXTURE2D_TILESTYLEU, sTileStyle);

        sTileStyle = pTexture2D->getTileStyleV();
        if (sTileStyle.size() > 0)
            writeStringAttribute(XML_3MF_ATTRIBUTE_TEXTURE2D_TILESTYLEV, sTileStyle);

        writeEndElement();

    }

}
コード例 #3
0
void CModelWriterNode100_Model::writeToXML()
{
    std::wstring sLanguage = m_pModel->getLanguage();

    writeStartElementWithNamespace(XML_3MF_ELEMENT_MODEL, PACKAGE_XMLNS_100);

    writeStringAttribute(XML_3MF_ATTRIBUTE_MODEL_UNIT, m_pModel->getUnitString());
    writeConstPrefixedStringAttribute(XML_3MF_ATTRIBUTE_PREFIX_XML, XML_3MF_ATTRIBUTE_MODEL_LANG, sLanguage.c_str());
    writeConstPrefixedStringAttribute(XML_3MF_ATTRIBUTE_XMLNS, XML_3MF_NAMESPACEPREFIX_MATERIAL, XML_3MF_NAMESPACE_MATERIALSPEC);

    writeMetaData();
    writeResources();
    writeBuild();

    writeFullEndElement();
}
コード例 #4
0
void CModelWriterNode100_Model::writeColors()
{
    nfUint32 nCount = m_pColorMapping->getCount();
    nfUint32 nIndex;
    if (nCount > 0) {
        writeStartElementWithPrefix(XML_3MF_ELEMENT_COLORGROUP, XML_3MF_NAMESPACEPREFIX_MATERIAL);
        writeIntAttribute(XML_3MF_ATTRIBUTE_COLORS_ID, m_pColorMapping->getResourceID());
        for (nIndex = 0; nIndex < nCount; nIndex++) {
            nfColor cColor = m_pColorMapping->getColor(nIndex);
            writeStartElementWithPrefix(XML_3MF_ELEMENT_COLOR, XML_3MF_NAMESPACEPREFIX_MATERIAL);
            writeStringAttribute(XML_3MF_ATTRIBUTE_COLORS_COLOR, fnColorToWString(cColor));
            writeEndElement();
        }

        writeFullEndElement();
    }
}
コード例 #5
0
void CModelWriterNode100_Model::writeMetaData()
{
    nfUint32 nMetaDataCount = m_pModel->getMetaDataCount();
    nfUint32 nMetaDataIndex;

    for (nMetaDataIndex = 0; nMetaDataIndex < nMetaDataCount; nMetaDataIndex++) {
        std::wstring sKey;
        std::wstring sValue;
        m_pModel->getMetaData(nMetaDataIndex, sKey, sValue);

        writeStartElement(XML_3MF_ELEMENT_METADATA);
        writeStringAttribute(XML_3MF_ATTRIBUTE_METADATA_NAME, sKey);
        writeText(sValue.c_str(), (nfUint32)sValue.length());
        writeEndElement();
    }

}
コード例 #6
0
void CModelWriterNode100_Model::writeBuild()
{
    writeStartElement(XML_3MF_ELEMENT_BUILD);
    nfUint32 nCount = m_pModel->getBuildItemCount();
    nfUint32 nIndex;

    for (nIndex = 0; nIndex < nCount; nIndex++) {
        PModelBuildItem pBuildItem = m_pModel->getBuildItem(nIndex);

        writeStartElement(XML_3MF_ELEMENT_ITEM);
        writeIntAttribute(XML_3MF_ATTRIBUTE_ITEM_OBJECTID, pBuildItem->getObjectID());
        if (pBuildItem->hasTransform())
            writeStringAttribute(XML_3MF_ATTRIBUTE_ITEM_TRANSFORM, pBuildItem->getTransformString());
        writeEndElement();
    }

    writeFullEndElement();
}
コード例 #7
0
void CModelWriterNode100_Model::writeComponentsObject(_In_ CModelComponentsObject * pComponentsObject)
{
    __NMRASSERT(pComponentsObject);

    nfUint32 nIndex;
    nfUint32 nCount = pComponentsObject->getComponentCount();

    writeStartElement(XML_3MF_ELEMENT_COMPONENTS);
    for (nIndex = 0; nIndex < nCount; nIndex++) {
        PModelComponent pComponent = pComponentsObject->getComponent(nIndex);
        writeStartElement(XML_3MF_ELEMENT_COMPONENT);
        writeIntAttribute(XML_3MF_ATTRIBUTE_COMPONENT_OBJECTID, pComponent->getObjectID());
        if (pComponent->hasTransform())
            writeStringAttribute(XML_3MF_ATTRIBUTE_COMPONENT_TRANSFORM, pComponent->getTransformString());
        writeEndElement();
    }

    writeFullEndElement();
}
コード例 #8
0
ファイル: test_SWMR_fail.c プロジェクト: areaDetector/ADCore
int main(int argc, char *argv[])
{
  hid_t fid           = -1;
  hid_t access_plist  = -1;
  hid_t create_plist  = -1;
  hid_t cparm         = -1;
  hid_t datatype      = -1;
  hid_t dataspace     = -1;
  hid_t dataset       = -1;
  hid_t memspace      = -1;
  hid_t groupDetector = -1;
  int rank = 1;
  hsize_t chunk[2] = {10,10};
  hsize_t dims[2] = {1,1};
  hsize_t elementSize[2] = {1,1};
  hsize_t maxdims[2] = {H5S_UNLIMITED,H5S_UNLIMITED};
  int ivalue[2];
  int fillValue = 0;
  
  /* Open the source file and dataset */
  /* All SWMR files need to use the latest file format */
  access_plist = H5Pcreate(H5P_FILE_ACCESS);
  H5Pset_fclose_degree(access_plist, H5F_CLOSE_STRONG);
#if H5_VERSION_GE(1,9,178)
  H5Pset_object_flush_cb(access_plist, cFlushCallback, NULL);
#endif
  H5Pset_libver_bounds(access_plist, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
  create_plist = H5Pcreate(H5P_FILE_CREATE);
  fid = H5Fcreate("test_string_swmr.h5", H5F_ACC_TRUNC, create_plist, access_plist);

  /* Data */
  rank = 2;
  dims[0] = 10;
  dims[1] = 10;
  dataspace = H5Screate_simple(rank, dims, dims);
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(cparm, rank, chunk);
  datatype = H5Tcopy(H5T_NATIVE_INT8);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  groupDetector = H5Gcreate(fid, "detector", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

  access_plist = H5Pcreate(H5P_DATASET_ACCESS);
  H5Pset_chunk_cache(access_plist, 503, 100, 1.0);
  dataset = H5Dcreate2(groupDetector, "data1",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, access_plist);
  ivalue[0] = 1;
  ivalue[1] = 1;
  writeInt32Attribute(dataset, "NDArrayDimBinning", 2, ivalue);
  ivalue[0] = 0;
  ivalue[1] = 0;
  writeInt32Attribute(dataset, "NDArrayDimOffset", 2, ivalue);
  writeInt32Attribute(dataset, "NDArrayDimReverse", 2, ivalue);
  ivalue[0] = 2;
  writeInt32Attribute(dataset, "NDArrayNumDims", 1, ivalue);
  H5Gclose(groupDetector);

  dims[0] = 1;
  dims[1] = 1;
  chunk[0] = 1;
  rank = 1;

  /* Unique ID */
  datatype = H5T_NATIVE_INT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayUniqueId",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayUniqueId");
  writeStringAttribute(dataset, "NDAttrDescription", "The unique ID of the NDArray");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS Timestemp */
  datatype = H5T_NATIVE_DOUBLE;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayTimeStamp",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayTimeStamp");
  writeStringAttribute(dataset, "NDAttrDescription", "The timestamp of the NDArray as float64");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS TS sec */
  datatype = H5T_NATIVE_UINT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayEpicsTSSec",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayEpicsTSSec");
  writeStringAttribute(dataset, "NDAttrDescription", "The NDArray EPICS timestamp seconds past epoch");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* EPICS TS nsec */
  datatype = H5T_NATIVE_UINT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "NDArrayEpicsTSnSec",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "NDArrayEpicsTSnSec");
  writeStringAttribute(dataset, "NDAttrDescription", "The NDArray EPICS timestamp nanoseconds");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");
 
  /* Color mode */
  datatype = H5T_NATIVE_INT32;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "ColorMode",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "ColorMode");
  writeStringAttribute(dataset, "NDAttrDescription", "Color mode");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceDriver");
  writeStringAttribute(dataset, "NDAttrSource",      "Driver");

  /* Camera manufacturer */
  datatype = H5Tcopy(H5T_C_S1);
  H5Tset_size(datatype, 256);
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_fill_value(cparm, datatype, &fillValue);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "CameraManufacturer",
                       datatype, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  memspace = H5Screate_simple(rank, elementSize, NULL);
  writeStringAttribute(dataset, "NDAttrName",        "CameraManufacturer");
  writeStringAttribute(dataset, "NDAttrDescription", "Camera manufacturer");
  writeStringAttribute(dataset, "NDAttrSourceType",  "NDAttrSourceParam");
  writeStringAttribute(dataset, "NDAttrSource",      "MANUFACTURER");

  /* Performance data */
  rank = 2;
  dims[0] = 1;
  dims[1] = 5;
  chunk[1] = 5;
  cparm = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(cparm, rank, chunk);
  dataspace = H5Screate_simple(rank, dims, maxdims);
  dataset = H5Dcreate2(fid, "timestamp",
                       H5T_NATIVE_DOUBLE, dataspace,
                       H5P_DEFAULT, cparm, H5P_DEFAULT);
  if (!H5Iis_valid(dataset)) {
    printf("Error writing performance dataset");
  }
  H5Sclose(dataspace);

#if H5_VERSION_GE(1,9,178)
  H5Fstart_swmr_write(fid);
#endif
  
  H5Fclose(fid);

  return 0;

} /* end main */
コード例 #9
0
void CModelWriterNode100_Model::writeObjects()
{
    nfUint32 nObjectCount = m_pModel->getObjectCount();
    nfUint32 nObjectIndex;

    for (nObjectIndex = 0; nObjectIndex < nObjectCount; nObjectIndex++) {
        CModelObject * pObject = m_pModel->getObject(nObjectIndex);

        writeStartElement(XML_3MF_ELEMENT_OBJECT);
        // Write Object ID (mandatory)
        writeIntAttribute(XML_3MF_ATTRIBUTE_OBJECT_ID, pObject->getResourceID());

        // Write Object Name (optional)
        std::wstring sObjectName = pObject->getName();
        if (sObjectName.length() > 0)
            writeStringAttribute(XML_3MF_ATTRIBUTE_OBJECT_NAME, sObjectName);

        // Write Object Partnumber (optional)
        std::wstring sObjectPartNumber = pObject->getPartNumber();
        if (sObjectPartNumber.length() > 0)
            writeStringAttribute(XML_3MF_ATTRIBUTE_OBJECT_PARTNUMBER, sObjectPartNumber);

        // Write Object Type (optional)
        writeStringAttribute(XML_3MF_ATTRIBUTE_OBJECT_TYPE, pObject->getObjectTypeString());

        // Write Default Property Indices
        ModelResourceID nPropertyID = 0;
        ModelResourceIndex nPropertyIndex = 0;

        PModelDefaultProperty pProperty = pObject->getDefaultProperty();
        // Color Properties
        CModelDefaultProperty_Color * pColorProperty = dynamic_cast<CModelDefaultProperty_Color *> (pProperty.get());
        if (pColorProperty != nullptr) {
            if (m_pColorMapping->findColor(pColorProperty->getColor(), nPropertyIndex)) {
                nPropertyID = m_pColorMapping->getResourceID();
            }
        }

        // TexCoord2D Properties
        CModelDefaultProperty_TexCoord2D * pTexCoord2DProperty = dynamic_cast<CModelDefaultProperty_TexCoord2D *> (pProperty.get());
        if (pTexCoord2DProperty != nullptr) {
            PModelWriter_TexCoordMapping pTexCoordMapping = m_pTexCoordMappingContainer->findTexture(pTexCoord2DProperty->getTextureID());
            if (pTexCoordMapping.get() != nullptr) {
                if (pTexCoordMapping->findTexCoords(pTexCoord2DProperty->getU(), pTexCoord2DProperty->getV(), nPropertyIndex)) {
                    nPropertyID = pTexCoordMapping->getResourceID();
                }
            }
        }

        // Base Material Properties
        CModelDefaultProperty_BaseMaterial * pBaseMaterialProperty = dynamic_cast<CModelDefaultProperty_BaseMaterial *> (pProperty.get());
        if (pBaseMaterialProperty != nullptr) {
            nPropertyID = pBaseMaterialProperty->getResourceID();
            nPropertyIndex = pBaseMaterialProperty->getResourceIndex();
        }

        // Write Attributes
        if (nPropertyID != 0) {
            writeIntAttribute(XML_3MF_ATTRIBUTE_OBJECT_PID, nPropertyID);
            writeIntAttribute(XML_3MF_ATTRIBUTE_OBJECT_PINDEX, nPropertyIndex);
        }


        // Check if object is a mesh Object
        CModelMeshObject * pMeshObject = dynamic_cast<CModelMeshObject *> (pObject);
        if (pMeshObject) {
            CModelWriterNode100_Mesh ModelWriter_Mesh(pMeshObject, m_pXMLWriter, m_pColorMapping, m_pTexCoordMappingContainer);
            ModelWriter_Mesh.writeToXML();
        }

        // Check if object is a component Object
        CModelComponentsObject * pComponentObject = dynamic_cast<CModelComponentsObject *> (pObject);
        if (pComponentObject) {
            writeComponentsObject(pComponentObject);
        }

        writeFullEndElement();
    }

}