Fractrace.SceneGraph.MeshTool.Update C# (CSharp) Метод

Update() публичный Метод

public Update ( Iterate iter, Fractrace.DataTypes.PictureData pictureData ) : Fractrace.SceneGraph.Mesh
iter Iterate
pictureData Fractrace.DataTypes.PictureData
Результат Fractrace.SceneGraph.Mesh
        public Mesh Update(Iterate iter, PictureData pictureData)
        {
            _iterate = iter;
            _pictureData = pictureData;
            // TODO: Update _mesh data

            List<Coord2D> pointList = new List<Coord2D>();

            int[,] pointIndex = new int[_pictureData.Width + 1, _pictureData.Height + 1];

            int currentIndex = _mesh._coordinates.Count/3; // lenght of pointindex in _mesh??
            for (int i = 0; i < _pictureData.Width; i++)
            {
                for (int j = 0; j < _pictureData.Height; j++)
                {
                    if (_pictureData.Points[i, j] != null)
                    {
                        Coord2D coord = new Coord2D(i, j);
                        pointIndex[i, j] = currentIndex;
                        pointList.Add(coord);
                        currentIndex++;
                    }
                    else
                    {
                        pointIndex[i, j] = -1;
                    }
                }
            }

            // to test for invalid pdata
            double maxcol = 0;

            foreach (Coord2D coord in pointList)
            {
                PixelInfo pInfo = Transform(_pictureData.Points[coord.X, coord.Y]);
                if (pInfo != null && pInfo.Coord != null && pInfo.AdditionalInfo != null)
                {

                    double x, y, z;

                    if (_needScaling || AlwaysScale)
                    {
                        x = (pInfo.Coord.X - _centerx) / _radius;
                        y = (pInfo.Coord.Y - _centery) / _radius;
                        z = (pInfo.Coord.Z - _centerz) / _radius;
                    }
                    else
                    {
                        // Scale by 1000
                        x = 1000.0 * pInfo.Coord.X;
                        y = 1000.0 * pInfo.Coord.Y;
                        z = 1000.0 * pInfo.Coord.Z;
                    }

                    _mesh._coordinates.Add((float)x);
                    _mesh._coordinates.Add((float)y);
                    _mesh._coordinates.Add((float)z);

                    double red = pInfo.AdditionalInfo.red2;
                    double green = pInfo.AdditionalInfo.green2;
                    double blue = pInfo.AdditionalInfo.blue2;

                    _mesh._colors.Add((float)red);
                    _mesh._colors.Add((float)green);
                    _mesh._colors.Add((float)blue);

                    // test for invalid data only
                    if (maxcol < red)
                        maxcol = red;
                    if (maxcol < green)
                        maxcol = green;
                    if (maxcol < blue)
                        maxcol = blue;

                }
            }

            for (int i = 0; i < _pictureData.Width; i++)
            {
                for (int j = 0; j < _pictureData.Height; j++)
                {
                    if (_pictureData.Points[i, j] != null)
                    {
                        PixelInfo point1 = _pictureData.Points[i, j];
                        if (point1.Coord.X > 1000 && point1.Coord.X < -1000 && point1.Coord.Y > 1000 && point1.Coord.Y < -1000 && point1.Coord.Z > 1000 && point1.Coord.Z < -1000)
                        {
                            System.Diagnostics.Debug.WriteLine("Error");
                        }
                        if (i > 0 && j > 0 && _pictureData.Points[i - 1, j - 1] != null)
                        {

                            if (_pictureData.Points[i - 1, j] != null)
                            {
                                // triangle 1
                                bool useTriangle = true;
                                if (_useDistance)
                                {
                                    PixelInfo point2 = _pictureData.Points[i - 1, j];
                                    PixelInfo point3 = _pictureData.Points[i - 1, j - 1];
                                    if (Dist(point1, point2) > _maxDist || Dist(point1, point3) > _maxDist)
                                        useTriangle = false;
                                }
                                if (useTriangle)
                                {
                                    _mesh._faces.Add(pointIndex[i, j]);
                                    _mesh._faces.Add(pointIndex[i - 1, j]);
                                    _mesh._faces.Add(pointIndex[i - 1, j - 1]);

                                    _mesh._normales.Add((float)point1.Normal.X);
                                    _mesh._normales.Add((float)point1.Normal.Y);
                                    _mesh._normales.Add((float)point1.Normal.Z);

                                }
                            }
                            if (_pictureData.Points[i, j - 1] != null)
                            {
                                // triangle 2
                                bool useTriangle = true;
                                if (_useDistance)
                                {
                                    PixelInfo point2 = _pictureData.Points[i - 1, j - 1];
                                    PixelInfo point3 = _pictureData.Points[i, j - 1];
                                    if (Dist(point1, point2) > _maxDist || Dist(point1, point3) > _maxDist)
                                        useTriangle = false;
                                }
                                if (useTriangle)
                                {
                                    _mesh._faces.Add(pointIndex[i, j]);
                                    _mesh._faces.Add(pointIndex[i - 1, j - 1]);
                                    _mesh._faces.Add(pointIndex[i, j - 1]);

                                    _mesh._normales.Add((float)point1.Normal.X);
                                    _mesh._normales.Add((float)point1.Normal.Y);
                                    _mesh._normales.Add((float)point1.Normal.Z);

                                }
                            }
                        }
                    }
                }
            }
            if (maxcol < 0.0001)
            {
                _valid = false;
            }
            return _mesh;
        }

Usage Example

Пример #1
0
 public void Update(Iterate iter, PictureData pictureData)
 {
     _mesh = _meshTool.Update(iter, pictureData);
 }