コード例 #1
0
void CLODMeshGenerator::setMeshData(WEMTrianglePatch* wemPatch)
{
    _wem->removeAll();
    WEMTrianglePatch* newTrianglePatch = _wem->addWEMPatchCopy(wemPatch);
    newTrianglePatch->computeBoundingBox();
    newTrianglePatch->setId(0);
}
コード例 #2
0
void DicomSurfaceSegmentationLoad::_addMeshToOutput(const int meshNumber)
{
	if(meshNumber >= _dicomMeshesVector.size())
  {
		return;
  }

  int meshesIDStartValue = (int)_meshesIDStartValueFld->getIntValue();

	const Element3D meshElement     = _dicomMeshesVector[meshNumber];

	const std::string segmentLabel  = meshElement.getSegmentLabel();	 
  const Coordinates3D meshSurface = meshElement.getReferencedSurface();

  const std::vector<Vector3> wemPositions              = meshSurface.getCoordinates();
	const std::vector<unsigned long> meshPositionIndices = meshSurface.getCoordinateIndices();
	const std::vector<Vector3> meshNormals               = meshSurface.getNormals();

	WEMTrianglePatch* newPatch = NULL;
	ML_CHECK_NEW(newPatch, WEMTrianglePatch());

  // Add WEM nodes
	for (unsigned long p = 0; p < wemPositions.size(); p++) 
  {
		WEMNode* newNode = newPatch->addNode();

		newNode->setPosition(wemPositions[p]);

		if(!meshNormals.empty())
    {
			newNode->setNormal(meshNormals[p]);
    }
		else
    {
			newNode->computeNormal();
    }
	}

  // Add WEM faces
	for (size_t f = 0; f < meshPositionIndices.size(); f += 3) 
  {
		WEMTriangle* newFace = newPatch->addTriangle();

		for (unsigned int i = 0; i < 3; i++) 
    {
			WEMNode* node = newPatch->getNodeAt(meshPositionIndices[f+i]);
			newFace->setNode(i, node);
			node->addFace(newFace);
		}

		newFace->computeNormal();
	}
	
	newPatch->setLabel(segmentLabel);
	//newPatch->setId(_outWEM->getCurrentWEMPatchId());
	newPatch->setId(meshesIDStartValue + meshNumber);
	newPatch->setType(_type);

	ML_NAMESPACE::WEMPrimitiveValueList* primitiveValueList = newPatch->createOrGetPrimitiveValueList("LUT");
	primitiveValueList->setValue(0, static_cast<double>(meshNumber));

	newPatch->buildEdgeConnectivity();
	_outWEM->addWEMPatch(newPatch);
	_finish(newPatch);
}
コード例 #3
0
ML_START_NAMESPACE


//***********************************************************************************


void SavePRC::PreProcessMeshData(WEMPtr saveWEM, 
							                   PRCMeshInfoVector &meshInfoVector,
                                 ModelBoundingBoxStruct& boundingBox)
{
  if (!_inWEM) 
  { 
    return; 
  }

  MLuint32 meshNumber = 0;

  bool simpleMode = _simpleModeMeshFld->getBoolValue();

  StringVector meshSpecificationsVector;

  if (simpleMode)
  {
    //meshSpecificationsVector.push_back("<U3DMesh>");
  }
  else
  {
    meshSpecificationsVector = getObjectSpecificationsStringFromUI(_meshSpecificationFld, "<Mesh>");
  }

  // Scan all WEM patches, triangulate them if necessary and collect base info.
  WEMPatch*           wemPatch = NULL;
  WEMTrianglePatch*   addedTrianglePatch = NULL;

  _statusFld->setStringValue("Analyzing mesh specification and input WEM.");

  const MLuint32 numberOfWEMPatches = _inWEM->getNumWEMPatches();

  for (MLuint32 i = 0; i < numberOfWEMPatches; i++)
  {
    PRCMeshInfoStruct   thisWEMMeshInfo;

    wemPatch = _inWEM->getWEMPatchAt(i); 
    addedTrianglePatch = NULL;
    const unsigned int newId = saveWEM->getCurrentWEMPatchId();

    if (wemPatch->getNumFaces() > 0)
    {

      if (wemPatch->getPatchType() != WEM_PATCH_TRIANGLES)
      {
        WEMTrianglePatch* triangulatedPatch = NULL;

        ML_CHECK_NEW(triangulatedPatch,WEMTrianglePatch());
        wemPatch->triangulate(triangulatedPatch, WEM_TRIANGULATION_STRIP);
        addedTrianglePatch = saveWEM->addWEMPatchCopy(triangulatedPatch);
        addedTrianglePatch->computeBoundingBox();
        ML_DELETE(triangulatedPatch);
      }
      else
      {
        addedTrianglePatch = saveWEM->addWEMPatchCopy(reinterpret_cast<WEMTrianglePatch*>(wemPatch));
      }

      if (addedTrianglePatch != NULL) 
      {
        addedTrianglePatch->setId(newId);

        // Adjust properties of main WEM bounding box
        WEMBoundingBox* thisWEMPatchBoundingBox = addedTrianglePatch->getBoundingBox();
        ModelBoundingBoxStruct newboundingBox;
        newboundingBox.start = thisWEMPatchBoundingBox->getMin();
        newboundingBox.end   = thisWEMPatchBoundingBox->getMax();
        UpdateBoundingBox(boundingBox, newboundingBox);

	      std::string wemDescription = addedTrianglePatch->getDescription();
        std::string wemLabel = addedTrianglePatch->getLabel();

        SpecificationParametersStruct thisSpecificationParameters;

        // Create an artificial meshSpecificationVector if only WEM label & description shall be used 
        if (simpleMode)
        {
          meshSpecificationsVector.clear();

          // Parse WEM label & description...
          std::string u3dModelName       = getSpecificParameterFromWEMDescription(wemDescription, "ModelName");
          std::string u3dGroupName       = getSpecificParameterFromWEMDescription(wemDescription, "GroupName");
          std::string u3dGroupPath       = "";
          if ("" != u3dModelName)
          {
            u3dGroupPath = "/" + u3dModelName + "/";
          }
          if ("" != u3dGroupName)
          {
            if ("" == u3dGroupPath)
            {
              u3dGroupPath += "/";
            }
            u3dGroupPath += u3dGroupName + "/";
          }

          std::string displayName = wemLabel;
          if (displayName == "") {
            displayName = "Mesh " + intToString(i+1);
          }

          // ...and write data into meshSpecification string
          std::string meshSpecificationsString = "<U3DMesh>";
          meshSpecificationsString += "<WEMLabel>" + wemLabel + "</WEMLabel>";
          meshSpecificationsString += "<ObjectName>" + displayName + "</ObjectName>";
          meshSpecificationsString += "<GroupPath>" + u3dGroupPath + "</GroupPath>";
          meshSpecificationsString += "<Color>" + getSpecificParameterFromWEMDescription(wemDescription, "Color") + "</Color>";
          meshSpecificationsString += "<SpecularColor>" + getSpecificParameterFromWEMDescription(wemDescription, "SpecularColor") + "</SpecularColor>";
          meshSpecificationsString += "<ModelVisibility>3</ModelVisibility>";

          // Add meshSpecification string to meshSpecificationVector
          meshSpecificationsVector.push_back(meshSpecificationsString);
        }

        for (int thisSpecificationIndex = 0; thisSpecificationIndex < meshSpecificationsVector.size(); thisSpecificationIndex++)
        {
          thisSpecificationParameters = getAllSpecificationParametersFromString(meshSpecificationsVector[thisSpecificationIndex]);
          if (thisSpecificationParameters.WEMLabel == wemLabel)
          {
            PRCObjectInfoStruct thisPRCObjectInfo = CreateNewPRCObjectInfo(i,PRCOBJECTTYPE_MESH, thisSpecificationParameters.ObjectName, defaultValues);
            thisPRCObjectInfo.GroupPath        = thisSpecificationParameters.GroupPath;
            thisPRCObjectInfo.ParentTreeNodeID = -1;
            thisPRCObjectInfo.RGBAColor        = getColorVec4(thisSpecificationParameters.Color, Vector4(0));  // If alpha = 0 -> Adobe doesn't render;
            _prcObjectInfoVector.push_back(thisPRCObjectInfo);



            // Collect mesh info
            thisWEMMeshInfo.DiffuseColorCount    = 0;    // This is not really needed in this version
            thisWEMMeshInfo.SpecularColorCount   = 0;    // This is not really needed in this version
            thisWEMMeshInfo.TextureCoordCount    = 0;    // This is not really needed in this version
            thisWEMMeshInfo.DefaultAmbientColor  = defaultValues.defaultMaterialAmbientColor;
            thisWEMMeshInfo.DefaultSpecularColor = defaultValues.defaultMaterialSpecularColor;
            thisWEMMeshInfo.DefaultDiffuseColor  = defaultValues.defaultMaterialDiffuseColorWithTransparency;
            thisWEMMeshInfo.DefaultEmissiveColor = defaultValues.defaultMaterialEmissiveColor;            
            thisWEMMeshInfo.FaceCount = addedTrianglePatch->getNumFaces();
            thisWEMMeshInfo.NormalCount = addedTrianglePatch->getNumFaces();
            thisWEMMeshInfo.VertexCount = addedTrianglePatch->getNumNodes();            
            thisWEMMeshInfo.PatchID = addedTrianglePatch->getId();
  //          thisWEMMeshInfo.MeshAttributes = U3D_MESH_ATTRIBUTES_DEFAULT;
  //          thisWEMMeshInfo.MeshAttributes |= ( (thisWEMMeshInfo.NormalCount == 0) ? U3D_MESH_ATTRIBUTES_EXCLUDENORMALS : 0 );
  //          thisWEMMeshInfo.ShadingAttributes = U3D_SHADINGATTRIBUTES_NONE;  
  //          thisWEMMeshInfo.ShadingAttributes |= ( (thisWEMMeshInfo.DiffuseColorCount > 0) ? U3D_SHADINGATTRIBUTES_DIFFUSECOLORS : 0 );   // Should not happen in this version
  //          thisWEMMeshInfo.ShadingAttributes |= ( (thisWEMMeshInfo.SpecularColorCount > 0) ? U3D_SHADINGATTRIBUTES_SPECULARCOLORS : 0 ); // Should not happen in this version
  //          thisWEMMeshInfo.ResourceName = thisPRCObjectInfo.ResourceName;
            thisWEMMeshInfo.MeshNumber = meshNumber++;

	          meshInfoVector.push_back(thisWEMMeshInfo);           
          }
        }

      }  // if (addedTrianglePatch != NULL)

    }  // if (wemPatch->getNumFaces() > 0)

    wemPatch = NULL;
  }

}