Exemple #1
0
 public AssetLoadResultByLoader Load(AssetLoadInfo loadInfo)
 {
     try
     {
         var asset = BuildAsset(loadInfo);
         return(AssetLoadResultByLoader.Success(asset));
     }
     catch (Exception ex)
     {
         return(AssetLoadResultByLoader.Failure("EXCEPTION", ex));
     }
 }
 public AssetLoadResultByLoader Load(AssetLoadInfo loadInfo)
 {
     try
     {
         var asset = BuildAsset(loadInfo);
         return(AssetLoadResultByLoader.Success(asset));
     }
     catch (Exception ex)
     {
         return(AssetLoadResultByLoader.Failure(ex.GetType().Name, ex));
     }
 }
Exemple #3
0
 public AssetLoadResultByLoader Load(AssetLoadInfo loadInfo)
 {
     try
     {
         initializer.EnsureInitialized();
         var asset = CreateAsset(loadInfo);
         return(AssetLoadResultByLoader.Success(asset));
     }
     catch (Exception ex)
     {
         return(AssetLoadResultByLoader.Failure(ex.GetType().Name, ex));
     }
 }
Exemple #4
0
 public AssetLoadResultByLoader Load(AssetLoadInfo loadInfo)
 {
     // todo: use file system
     try
     {
         if (Path.GetExtension(loadInfo.LoadPath) == ".dcm")
         {
             return(LoadSingle(loadInfo));
         }
         if (Path.GetExtension(loadInfo.LoadPath) == ".dcmf")
         {
             return(LoadFolder(loadInfo));
         }
         return(AssetLoadResultByLoader.Failure("Neither .dcm nor .dcmf", null));
     }
     catch (Exception ex)
     {
         return(AssetLoadResultByLoader.Failure(ex.GetType().Name, ex));
     }
 }
Exemple #5
0
 public AssetLoadResultByLoader Load(AssetLoadInfo loadInfo)
 {
     try
     {
         var points   = new List <Vector3>();
         var loadPath = loadInfo.LoadPath;
         var fileData = loadInfo.FileSystem.ReadAllBytes(loadPath);
         using (var reader = new StreamReader(new MemoryStream(fileData)))
             while (true)
             {
                 var line = reader.ReadLine();
                 if (line == null)
                 {
                     break;
                 }
                 var match = PointRegex.Match(line);
                 if (!match.Success)
                 {
                     continue;
                 }
                 points.Add(new Vector3(
                                float.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture),
                                float.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture),
                                float.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture)
                                ));
             }
         var resource = new SpherePackingResult(points);
         var hash     = AssetHashMd5.FromSingleFile(fileData);
         var asset    = new Asset(loadInfo.AssetName, resource, loadInfo.StorageType, hash, loadInfo.ReferencePath, Path.GetFileName(loadInfo.ReferencePath));
         return(AssetLoadResultByLoader.Success(asset));
     }
     catch (Exception ex)
     {
         return(AssetLoadResultByLoader.Failure("EXCEPTION", ex));
     }
 }
Exemple #6
0
        private static AssetLoadResultByLoader Load(AssetLoadInfo loadInfo, void *dicomManager)
        {
            int width, height, depth;

            CheckSuccess(DicomProject.AnalyzerGetDimensions(dicomManager, 1, &width, &height, &depth));

            var lowerBuffer  = new byte[width * height];
            var higherBuffer = new byte[width * height];
            var vertexList   = new List <VertexPosNormTex>();

            fixed(byte *pBuffer = higherBuffer)
            {
                int bufferSize = higherBuffer.Length;
                int bytesWritten;

                CheckSuccess(DicomProject.AnalyzerGetMonochromePixelDataBufferOfSlice(dicomManager, 1, pBuffer, &bufferSize, &bytesWritten));
            }

            for (int z = 1; z < depth; z++)
            {
                CodingHelper.Swap(ref lowerBuffer, ref higherBuffer);

                fixed(byte *pBuffer = higherBuffer)
                {
                    int bufferSize = higherBuffer.Length;
                    int bytesWritten;

                    CheckSuccess(DicomProject.AnalyzerGetMonochromePixelDataBufferOfSlice(dicomManager, z + 1, pBuffer, &bufferSize, &bytesWritten));
                }

                for (int y = 0; y < height - 1; y++)
                {
                    for (int x = 0; x < width - 1; x++)
                    {
                        var vx = (100f / width) * x - 50f;
                        var vy = (100f / height) * y - 50f;
                        var vz = (100f / depth) * z - 50f;

                        var yStride = width;

                        var mcCube = new MCCubeCornerScalarStruct
                        {
                            CubeDim   = new IrtPtType(100.0 / width, 100.0 / height, 100.0 / depth),
                            Vrtx0Lctn = new IrtPtType(vx, vy, vz)
                        };
                        mcCube.Corners[0] = UNormToDouble(lowerBuffer[yStride * y + x]);
                        mcCube.Corners[1] = UNormToDouble(lowerBuffer[yStride * y + (x + 1)]);
                        mcCube.Corners[2] = UNormToDouble(lowerBuffer[yStride * (y + 1) + (x + 1)]);
                        mcCube.Corners[3] = UNormToDouble(lowerBuffer[yStride * (y + 1) + x]);
                        mcCube.Corners[4] = UNormToDouble(higherBuffer[yStride * y + x]);
                        mcCube.Corners[5] = UNormToDouble(higherBuffer[yStride * y + (x + 1)]);
                        mcCube.Corners[6] = UNormToDouble(higherBuffer[yStride * (y + 1) + (x + 1)]);
                        mcCube.Corners[7] = UNormToDouble(higherBuffer[yStride * (y + 1) + x]);
                        // todo: use ref instead
                        EstimateGradient(&mcCube);
                        var MCPolys = Irit.MCThresholdCube(&mcCube, 0.5);

                        while (MCPolys != null)
                        {
                            var texCoord = new Vector2((float)x / width, (float)z / depth);

                            var vertex0    = MCPolys->GetClarityVertex(0, texCoord);
                            var vertexCurr = MCPolys->GetClarityVertex(1, texCoord);

                            for (var i = 2; i < MCPolys->NumOfVertices; i++)
                            {
                                var vertexPrev = vertexCurr;

                                vertexCurr = MCPolys->GetClarityVertex(i, texCoord);
                                vertexList.Add(vertex0);
                                vertexList.Add(vertexPrev);
                                vertexList.Add(vertexCurr);
                            }

                            //Irit.IritFree(MCPolys);

                            MCPolys = MCPolys->Pnext;
                        }
                    }
                }
            }

            var pack = new ResourcePack(ResourceVolatility.Immutable);

            var rawVerticesData = new RawDataResource(ResourceVolatility.Immutable, vertexList.Count * sizeof(VertexPosNormTex));

            pack.AddSubresource("VertexData", rawVerticesData);
            var pRawData = (VertexPosNormTex *)rawVerticesData.Map();

            for (int i = 0; i < vertexList.Count; i++)
            {
                pRawData[i] = vertexList[i];
            }
            rawVerticesData.Unmap(true);

            var vertexSet = new FlexibleModelVertexSet(ResourceVolatility.Immutable, new[] { new RawDataResSubrange(rawVerticesData, 0) }, VertexPosNormTex.GetElementsInfos(0), null);

            pack.AddSubresource("ModelVertexSet", vertexSet);
            var modelPart = new FlexibleModelPart
            {
                IndexCount        = vertexList.Count,
                PrimitiveTopology = FlexibleModelPrimitiveTopology.TriangleList,
                VertexSetIndex    = 0
            };
            var model = new FlexibleModel(ResourceVolatility.Immutable, new[] { vertexSet }, new[] { modelPart }, new Sphere(Vector3.Zero, 50));

            pack.AddSubresource("Model", model);
            pack.MainSubresource = model;

            CheckSuccess(DicomProject.AnalyzerKillDicomAnalyzer(&dicomManager));

            // todo: calculate hash honestly
            var hash     = AssetHashMd5.Random(new Random());
            var fileName = Path.GetFileName(loadInfo.LoadPath);
            var asset    = new Asset(loadInfo.AssetName, pack, AssetStorageType.ReferenceOriginal, hash, loadInfo.ReferencePath, fileName);

            return(AssetLoadResultByLoader.Success(asset));
        }