/** * 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(); }
public CS_ParamValueTable(Panel paramValuePanel, Panel paramExplanationPanel, CS_Params csparams) { _paramValuePanel = paramValuePanel; _paramExplanationPanel = paramExplanationPanel; _paramValuePanel.Controls.Clear(); _csparams = csparams; }
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; } } }
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); }
/** * 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); }
/** * 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>(); }
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 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]); }
public CS_TreeGeneratorImpl(CS_Params csparams) { this.csparams = csparams; }
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); }
/** * 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); }
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); }
public static CS_TreeGenerator createTreeGenerator(CS_Params csparams) { return new CS_TreeGeneratorImpl(csparams); }
public static CS_TreeGenerator createShieldedTreeGenerator(CS_Params csparams) { return new CS_ShieldedTreeGenerator(new CS_TreeGeneratorImpl(csparams)); }
/* offs=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) { 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); }
public DXTreeSkeleton_TreeTraversal(CS_Params csParams) { _csParams = csParams; }
public CS_TreeGeneratorImpl() { csparams = new CS_Params(); }
public CS_Params(CS_Params other) { // copy values from other //debug = other.debug; //verbose = other.verbose; ignoreVParams = other.ignoreVParams; stopLevel = other.stopLevel; Species = other.Species; // Seed = other.Seed; Smooth = other.Smooth; // create paramDB paramDB = new Hashtable(); levelParams = new CS_LevelParams[4]; for (int l = 0; l < 4; l++) { levelParams[l] = new CS_LevelParams(l, paramDB); } registerParams(); // copy param values foreach (CS_AbstractParam p in paramDB.Values) { try { CS_AbstractParam otherParam = other.getParam(p.name); if (!otherParam.empty()) { p.setValue(otherParam.getValue()); } // else use default value } catch (Exception err) { Console.WriteLine("Error copying params: " + err.Message); } } }
public CS_ParamExplanationView(Panel paramExplanationPanel, Panel paramValuePanel, CS_Params csparams) { _paramExplanationPanel = paramExplanationPanel; paramExplanationPanel.Tag = this; _csparams = csparams; }