Esempio n. 1
0
        public void TestNormals()
        {
            var mdlReader         = new MdlFilePolygonDataReader(_inputPath + @"\flowerpetals.mdl");
            var triangles         = Triangle.GetTrianglesFromPts(mdlReader.Points);
            var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles);

            Assert.AreEqual(0, meshGeometryModel.Normals.Count);
            XamlWriter.SaveMeshGeometryModel(_outputPath + @"\ModelWithoutSetNormals.xaml", meshGeometryModel, Color.FromRgb(255, 255, 0));

            NormalCalculator.SetNormalsForModel(meshGeometryModel);

            Assert.AreEqual(meshGeometryModel.Positions.Count, meshGeometryModel.Normals.Count);

            XamlWriter.SaveMeshGeometryModel(_outputPath + @"\ModelWithSetNormals.xaml", meshGeometryModel, Color.FromRgb(255, 255, 0));

            var normalModelPts = new List <Point3D>();

            for (var index = 0; index < meshGeometryModel.Normals.Count; index++)
            {
                var normal   = meshGeometryModel.Normals[index];
                var position = meshGeometryModel.Positions[index];

                var p2 = new Point3D(position.X + normal.X, position.Y + normal.Y, position.Z + normal.Z);

                var lineModel = LineDisplayModel.GetLineModel(position, p2, .03);
                normalModelPts.AddRange(lineModel);
            }
            XamlWriter.WritePolygonsToXamlFile("", _outputPath + @"\NormalsAsLines.xaml", normalModelPts, false);
        }
        public void TestRotationAlongTheXAxis()
        {
            var inputPts      = new MdlFilePolygonDataReader(ExecutionDirInfoHelper.GetInputDirPath() + @"\1.mdl").Points;
            var outputDirPath = ExecutionDirInfoHelper.GetOutputDirPath() + @"\TestRotationAlongTheXAxis";

            if (!Directory.Exists(outputDirPath))
            {
                Directory.CreateDirectory(outputDirPath);
            }
            XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\Input.xaml", outputDirPath), inputPts, false);
            for (var angleInRadian = 0.0; angleInRadian <= Math.PI * 2; angleInRadian += Math.PI * 2.0 / 18.0)//every 20 degrees
            {
                var outputPts = RotateAlongXYOrZAxis.GetRotatedPtList(Axis.X, angleInRadian, inputPts.ToArray());
                XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\Output_X_{1}.xaml", outputDirPath, CommonFunctions.RadianToDegrees(angleInRadian, 0)), outputPts, false);
            }
        }
Esempio n. 3
0
        public void TestMediumSizedModel()
        {
            var mdlFileReader = new MdlFilePolygonDataReader(_inputPath + @"\v.mdl");
            var triangles     = Triangle.GetTrianglesFromPts(mdlFileReader.Points);

            XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\InputModel.xaml", _outputPath), mdlFileReader.Points, false);

            var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles);

            XamlWriter.SaveMeshGeometryModel(string.Format(@"{0}\InputModelMeshGeometry.xaml", _outputPath), meshGeometryModel, Color.FromRgb(100, 100, 100));

            var smoothPositions = PaulBourkeSmoother.GetSmoothenedPositions(meshGeometryModel.Positions, meshGeometryModel.TriangleIndices, 6);

            XamlWriter.SavePositionsAndTriangleIndicesAsModel(string.Format(@"{0}\Smoothened_{1}_times.xaml", _outputPath, 6),
                                                              smoothPositions, meshGeometryModel.TriangleIndices, Color.FromRgb(100, 100, 100));
        }
Esempio n. 4
0
        public void Create_Some_Rotated_Pts_Along_Z_Axis()
        {
            //translate to +y
            for (var ctr = 0; ctr < _ptsForACube.Count(); ctr++)
            {
                _ptsForACube[ctr].Y += 5.0;
            }
            var ptList = new List <Point3D>();

            for (var angle = 0.0; angle <= Math.PI; angle += Math.PI / 10)
            {
                Point3D[] rotatedPts = RotateAlongXYOrZAxis.GetRotatedPts(Axis.Z, angle, _ptsForACube);
                ptList.AddRange(rotatedPts);
            }
            XamlWriter.WritePolygonsToXamlFile(
                GetTemplatePath(),
                ExecutionDirInfoHelper.GetOutputDirPath() + @"\testRotationAlongZAxis.xaml",
                ptList,
                false);
        }
Esempio n. 5
0
        public void TestGetSmoothenedPositions()
        {
            var mdlFileReader = new MdlFilePolygonDataReader(_inputPath + @"\flowerpetals.mdl");
            var triangles     = Triangle.GetTrianglesFromPts(mdlFileReader.Points);

            XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\InputModel.xaml", _outputPath), mdlFileReader.Points, false);

            var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles);

            XamlWriter.SaveMeshGeometryModel(string.Format(@"{0}\InputModelMeshGeometry.xaml", _outputPath), meshGeometryModel, Color.FromRgb(100, 100, 100));

            var currentPositions  = meshGeometryModel.Positions;
            var positionNeighbors = PaulBourkeSmoother.GetPositionNeighbors(currentPositions.Count, meshGeometryModel.TriangleIndices);

            for (var ctr = 1; ctr <= 10; ctr++)
            {
                var newPositions = PaulBourkeSmoother.GetSmoothenedPositions(currentPositions, meshGeometryModel.TriangleIndices, positionNeighbors);
                XamlWriter.SavePositionsAndTriangleIndicesAsModel(string.Format(@"{0}\Smoothing_Iteration_{1}.xaml", _outputPath, ctr),
                                                                  newPositions, meshGeometryModel.TriangleIndices, Color.FromRgb(100, 100, 100));
                currentPositions = newPositions;
            }
        }