示例#1
0
 public CS_ParamValueTable(Panel paramValuePanel, Panel paramExplanationPanel, CS_Params csparams)
 {
     _paramValuePanel       = paramValuePanel;
     _paramExplanationPanel = paramExplanationPanel;
     _paramValuePanel.Controls.Clear();
     _csparams = csparams;
 }
示例#2
0
 /**
  * Creates a new tree object
  */
 public CS_TreeImpl(int seed, CS_Params csparams)
 {
     this.csparams = csparams;
     this.seed     = seed;
     trunks        = new List <CS_StemImpl>();
     //newProgress();
 }
示例#3
0
        public override Vector3[] getSectionPoints(bool start = true)
        {
            CS_Params      par  = segment.par;
            CS_LevelParams lpar = segment.lpar;

            int pt_cnt = lpar.mesh_points;

            Vector3[]         points;
            DX_Transformation trf = getTransformation(); //segment.getTransformation().translate(pos.sub(segment.getLowerPosition()));

            // if radius = 0 create only one point -> that's a problem for me
            if (false /*rad < -0.000001*/)
            {
                points    = new Vector3[1];
                points[0] = trf.apply(new Vector3(0, 0, 0));
            }
            else
            { //create pt_cnt points
                points = new Vector3[pt_cnt];
                //stem.DBG("MESH+LOBES: lobes: %d, depth: %f\n"%(self.tree.Lobes, self.tree.LobeDepth))

                for (int i = 0; i < pt_cnt; i++)
                {
                    float angle = i * 360.0f / pt_cnt;
                    // for Lobes ensure that points are near lobes extrema, but not exactly there
                    // otherwise there are to sharp corners at the extrema
                    if (lpar.level == 0 && par.Lobes != 0)
                    {
                        angle -= 10.0f / par.Lobes;
                    }

                    // create some point on the unit circle
                    Vector3 pt = new Vector3((float)Math.Cos(angle * Math.PI / 180), (float)Math.Sin(angle * Math.PI / 180), 0);
                    // scale it to stem radius
                    if (lpar.level == 0 && (par.Lobes != 0 || par._0ScaleV != 0))
                    {
                        float rad1 = rad * (1 +
                                            par.random.uniform(-par._0ScaleV, par._0ScaleV) /
                                            segment.getSubsegmentCount());
                        pt = pt * (rad1 * (1.0f + par.LobeDepth * (float)Math.Cos(par.Lobes * angle * Math.PI / 180.0)));
                    }
                    else
                    {
                        pt = pt * rad; // faster - no radius calculations
                    }
                    // apply transformation to it
                    // (for the first trunk segment transformation shouldn't be applied to
                    // the lower meshpoints, otherwise there would be a gap between
                    // ground and trunk)
                    // FIXME: for helical stems may be/may be not a random rotation
                    // should applied additionally?

                    pt        = trf.apply(pt);
                    points[i] = pt;
                }
            }

            return(points);
        }
示例#4
0
        /**
         * Creates a new stem
         *
         * @param tr the tree object
         * @param params the general tree parameters
         * @param lparams the parameters for the stem level
         * @param parnt the parent stem, from wich the stems grows out
         * @param stlev the stem level
         * @param trf the base transformation of the stem
         * @param offs the offset of ste stem within the parent stem (0..1)
         */
        public CS_StemImpl(CS_TreeImpl tr, CS_StemImpl growsOutOf, int stlev,
                           DX_Transformation trf, float offs) /* offs=0 */
        {
            tree      = tr;
            stemlevel = stlev;
            transf    = trf;
            offset    = offs;

            if (growsOutOf != null)
            {
                if (growsOutOf.stemlevel < stemlevel)
                {
                    parent = growsOutOf;
                }
                else
                {
                    clonedFrom = growsOutOf;
                    parent     = growsOutOf.parent;
                }
            }

            par  = tree.csparams;
            lpar = par.getLevelParams(stemlevel);

            // initialize lists
            segments = new List <CS_SegmentImpl>(lpar.nCurveRes);

            if (lpar.nSegSplits > 0 || par._0BaseSplits > 0)
            {
                clones = new List <CS_StemImpl>();        // lpar.nSegSplits*lpar.nCurveRes+1);
            }

            if (stemlevel < par.Levels - 1)
            {
                CS_LevelParams lpar_1 = par.getLevelParams(lpar.level + 1);
                substems = new List <CS_StemImpl>(lpar_1.nBranches);
            }

            if (stemlevel == par.Levels - 1 && par.Leaves != 0)
            {
                leaves = new List <CS_LeafImpl>(Math.Abs(par.Leaves));
            }

            // inialize other variables
            leavesPerSegment = 0;
            splitCorrection  = 0;

            index = 0;         // substem number

            cloneIndex = new List <int>();
            pruneTest  = false;        // flag used for pruning

            //...
            maxPoint = new Vector3(-float.MaxValue, -float.MaxValue, -float.MaxValue);
            minPoint = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        }
示例#5
0
        public DXTreeSkeleton(CS_Tree tree, CS_Params csParams)
        {
            InitShaders();

            DXTreeSkeleton_TreeTraversal traversal = new DXTreeSkeleton_TreeTraversal(csParams);

            tree.traverseTree(traversal);
            BBox = traversal.BBox;

            for (int i = 0; i < 5; i++)
            {
                if (traversal.Vertices2[i].Count != 0)
                {
                    var stream = new DataStream(traversal.Vertices2[i].Count * Marshal.SizeOf(typeof(DXSKV)), true, true);

                    stream.WriteRange(traversal.Vertices2[i].ToArray());
                    stream.Position   = 0;
                    _vertexBuffer2[i] = new Buffer(DXDevice, stream, new BufferDescription()
                    {
                        BindFlags      = BindFlags.VertexBuffer,
                        CpuAccessFlags = CpuAccessFlags.None,
                        OptionFlags    = ResourceOptionFlags.None,
                        SizeInBytes    = traversal.Vertices2[i].Count * Marshal.SizeOf(typeof(DXSKV)),
                        Usage          = ResourceUsage.Default
                    });
                    stream.Dispose();

                    List <UInt32> indices = new List <UInt32>();
                    for (int k = 0; k < traversal.Vertices2[i].Count; k++)
                    {
                        indices.Add((UInt32)k);
                    }

                    stream = new DataStream(indices.Count * sizeof(UInt32), true, true);
                    stream.WriteRange(indices.ToArray());

                    stream.Position = 0;

                    _indexBuffer2[i] = new Buffer(DXDevice, stream, new BufferDescription()
                    {
                        BindFlags      = BindFlags.IndexBuffer,
                        CpuAccessFlags = CpuAccessFlags.None,
                        OptionFlags    = ResourceOptionFlags.None,
                        SizeInBytes    = indices.Count * sizeof(UInt32),
                        Usage          = ResourceUsage.Default
                    });
                    stream.Dispose();

                    IndexCount2[i] = indices.Count;
                }
            }
        }
示例#6
0
        /**
         *	Leaf rotation toward light
         */
        private void setLeafOrientation(CS_Params par)
        {
            if (par.LeafBend == 0)
            {
                return;
            }

            // FIXME: make this function as fast as possible - a tree has a lot of leafs

            // rotation outside
            Vector3 pos = transf.getT();
            // the z-vector of transf is parallel to the
            // axis of the leaf, the y-vector is the normal
            // (of the upper side) of the leaf
            Vector3 norm = transf.getY3();

            float tpos  = (float)(Math.Atan2(pos.Y, pos.X) * 180 / Math.PI);
            float tbend = tpos - (float)(Math.Atan2(norm.Y, norm.X) * 180 / Math.PI);;
            // if (tbend>180) tbend = 360-tbend;

            float bend_angle = par.LeafBend * tbend;

            // transf = transf.rotz(bend_angle);
            // rotate about global z-axis
            transf = transf.rotaxis(bend_angle, DX_Transformation.Z_AXIS);

            // rotation up
            norm = transf.getY3();
            float fbend = (float)(Math.Atan2((float)Math.Sqrt(norm.X * norm.X + norm.Y * norm.Y), norm.Z) * 180 / Math.PI);

            bend_angle = par.LeafBend * fbend;

            transf = transf.rotx(bend_angle);

            //		this is from the paper, but is equivalent with
            //      local x-rotation (upper code line)
            //
            //		double orientation = Vector.atan2(norm.getY(),norm.getX());
            //		transf = transf
            //			.rotaxis(-orientation,Vector.Z_AXIS)
            //			.rotx(bend_angle)
            //			.rotaxis(orientation,Vector.Z_AXIS);
        }
示例#7
0
        public CS_SegmentImpl(/*Params params, LevelParams lparams,*/
            CS_StemImpl stm, int inx, DX_Transformation trf,
            float r1, float r2)
        {
            index  = inx;
            transf = trf;
            rad1   = r1;
            rad2   = r2;
            stem   = stm;

            par    = stem.par;
            lpar   = stem.lpar;
            length = stem.segmentLength;

            // FIXME: rad1 and rad2 could be calculated only when output occurs (?)
            // or here in the constructor ?
            // FIXME: inialize subsegs with a better estimation of size
            subsegments = new List <CS_SubsegmentImpl>(10);
        }
示例#8
0
        private void MakeTreeFromParams(string filename, bool paramExists = false)
        {
            if (!paramExists)
            {
                csParams = new CS_Params();
                csParams.prepare(13);

                ResetMenuItems();

                if (filename != "")
                {
                    Text = "Arbaro C# V0.1 - " + Path.GetFileName(mainOpenFileDialog.FileName);
                    csParams.readFromXML(mainOpenFileDialog.FileName);
                }
                else
                {
                    Text = "Arbaro C# V0.1";
                }

                // refresh params GUI
                pgv = new CS_ParamGroupsView(treeView1);
                pvt = new CS_ParamValueTable(paramTablePanel, paramExplanationPanel, csParams);
                pev = new CS_ParamExplanationView(paramExplanationPanel, paramTablePanel, csParams);

                csParams.enableDisable();
                csParams.OnParamChanged += csParams_OnParamChanged;
            }

            CS_PreciseTimer  t0            = new CS_PreciseTimer(10);
            DateTime         tStart        = t0.Now;
            CS_TreeGenerator treeGenerator = CS_TreeGeneratorFactory.createShieldedTreeGenerator(csParams);

            tree = treeGenerator.makeTree(new Object());
            DateTime tEnd = t0.Now;


            // make 3D Tree
            if (Program.Renderer.RenderableList.ContainsKey("Skeleton"))
            {
                DXRenderable s = Program.Renderer.RenderableList["Skeleton"];
                Program.Renderer.RenderableList.Remove("Skeleton");
                s.Dispose();
            }
            DXTreeSkeleton sk = new DXTreeSkeleton(tree, csParams);

            sk.Visible = false;
            Program.Renderer.RenderableList.Add("Skeleton", sk);
            if (skeletonToolStripMenuItem.Checked)
            {
                sk.Visible = true;
            }
            else
            {
                sk.Visible = false;
            }

            if (Program.Renderer.RenderableList.ContainsKey("TreeMesh"))
            {
                DXRenderable s = Program.Renderer.RenderableList["TreeMesh"];
                Program.Renderer.RenderableList.Remove("TreeMesh");
                s.Dispose();
            }

            //DXTreeMesh me = new DXTreeMesh(tree, csParams);
            //Program.Renderer.RenderableList.Add("TreeMesh", me);
            DXArbaroTreeMesh me = new DXArbaroTreeMesh(tree, csParams);

            Program.Renderer.RenderableList.Add("TreeMesh", me);

            if (solidWireframeToolStripMenuItem.Checked)
            {
                me.Visible = true;
            }
            else
            {
                me.Visible = false;
            }

            // only reset the view when a new tree is loaded
            if (!paramExists)
            {
                Program.Renderer.CameraControler.LookAt(me.BBox);
            }

            float elapsed = (float)(tEnd.Subtract(tStart)).TotalMilliseconds;

            Console.WriteLine(elapsed);
        }
示例#9
0
 public DXTreeSkeleton_TreeTraversal(CS_Params csParams)
 {
     _csParams = csParams;
 }
 static public CS_TreeGenerator createShieldedTreeGenerator(CS_Params csparams)
 {
     return(new CS_ShieldedTreeGenerator(new CS_TreeGeneratorImpl(csparams)));
 }
 public CS_ParamExplanationView(Panel paramExplanationPanel, Panel paramValuePanel, CS_Params csparams)
 {
     _paramExplanationPanel    = paramExplanationPanel;
     paramExplanationPanel.Tag = this;
     _csparams = csparams;
 }
 public CS_TreeGeneratorImpl(CS_Params csparams)
 {
     this.csparams = csparams;
 }
示例#13
0
 public DXTreeMesh_TreeTraversal(DXBaseArbaroTreeMesh[] me, CS_Params csParams)
 {
     _csParams = csParams;
     _meshes   = me;
     _lmh      = new DXArbaroLeafMeshHelper(csParams.LeafScale, csParams.LeafScale * _csParams.LeafScaleX, _csParams.LeafScale * _csParams.LeafStemLen, csParams.LeafShape, _meshes[LEAFLEVEL]);
 }
示例#14
0
 /**
  * Creates a new tree object copying the parameters
  * from an other tree
  *
  * @param other the other tree, from wich parameters are taken
  */
 public CS_TreeImpl(CS_TreeImpl other)
 {
     csparams = new CS_Params(other.csparams);
     trunks   = new List <CS_StemImpl>();
 }
示例#15
0
 /**
  * Makes the leave. Does nothing at the moment, because
  * all the values can be calculated in the constructor
  */
 public void make(CS_Params par)
 {
     setLeafOrientation(par);
 }
示例#16
0
 public DXTreeMesh_TreeTraversal(CS_Params csParams)
 {
     _csParams = csParams;
     DXLeafMeshHelper leaves = new DXLeafMeshHelper(csParams.LeafScale, csParams.LeafScale * _csParams.LeafScaleX,
                                                    _csParams.LeafScale * _csParams.LeafStemLen, csParams.LeafShape, V, I);
 }
示例#17
0
        public DXArbaroTreeMesh(CS_Tree tree, CS_Params csParams)
            : base()
        {
            _csParams = csParams;
            DXTreeMesh_TreeTraversal traversal = new DXTreeMesh_TreeTraversal(meshes, csParams);

            tree.traverseTree(traversal);

            InitShaders();

            BBox         = new BoundingBox();
            BBox.Minimum = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            BBox.Maximum = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            for (int i = 0; i < 5; i++)
            {
                // Build vertex buffer
                if (meshes[i].Faces.Count != 0)
                {
                    var streamV = new DataStream(meshes[i].Vertices.Count * Marshal.SizeOf(typeof(DXMEV)), true, true);

                    DataStream streamI = new DataStream(meshes[i].Faces.Count * 3 * sizeof(UInt32), true, true);

                    // Let's make it simple for now
                    // We now we are dealing with a quad mesh
                    // and we hope everything wii be OK
                    foreach (DXBaseArbaroTreeMesh.DXVertex dxv in meshes[i].Vertices)
                    {
                        Vector3 pos   = dxv.Traits.Position;
                        DXMEV   dxmev = new DXMEV(); dxmev.P = new Vector4(pos.X, pos.Y, pos.Z, 1);
                        streamV.Write(dxmev);

                        BBox.Minimum = Vector3.Min(BBox.Minimum, pos);
                        BBox.Maximum = Vector3.Max(BBox.Maximum, pos);
                    }
                    streamV.Position  = 0;
                    _vertexBuffer2[i] = new Buffer(DXDevice, streamV, new BufferDescription()
                    {
                        BindFlags      = BindFlags.VertexBuffer,
                        CpuAccessFlags = CpuAccessFlags.None,
                        OptionFlags    = ResourceOptionFlags.None,
                        SizeInBytes    = meshes[i].Vertices.Count * Marshal.SizeOf(typeof(DXMEV)),
                        Usage          = ResourceUsage.Default
                    });
                    streamV.Dispose();


                    foreach (DXBaseArbaroTreeMesh.DXFace dxf in meshes[i].Faces)
                    {
                        List <int> indices = new List <int>();
                        foreach (DXBaseArbaroTreeMesh.DXVertex dxv in dxf.Vertices)
                        {
                            indices.Add(dxv.Index);
                        }
                        streamI.Write(indices[0]); streamI.Write(indices[1]); streamI.Write(indices[2]);
                    }

                    streamI.Position = 0;

                    _indexBuffer2[i] = new Buffer(DXDevice, streamI, new BufferDescription()
                    {
                        BindFlags      = BindFlags.IndexBuffer,
                        CpuAccessFlags = CpuAccessFlags.None,
                        OptionFlags    = ResourceOptionFlags.None,
                        SizeInBytes    = meshes[i].Faces.Count * 3 * sizeof(UInt32),
                        Usage          = ResourceUsage.Default
                    });
                    streamI.Dispose();

                    IndexCount2[i] = meshes[i].Faces.Count * 3;
                }
            }
        }
 public CS_TreeGeneratorImpl()
 {
     csparams = new CS_Params();
 }