add docfx samples.

This commit is contained in:
2025-04-13 00:19:09 +08:00
parent d63cb0e141
commit 9246bd6c41
13 changed files with 652 additions and 11 deletions
+48
View File
@@ -0,0 +1,48 @@
using Hi.Disp;
using Hi.Geom;
using System;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoCylindroid.cs)]
/// </remarks>
public static class DemoCylindroid
{
internal static void BuildCylindorid()
{
Cylindroid cylindroid = new Cylindroid(24,
new PairZr(0, 1),
new PairZr(1, 1),
new PairZr(1, 2),
new PairZr(2, 2),
new PairZr(8, 3));
DispEngine.Init();
DemoUtil.RunApplication("BuildCylindorid", cylindroid.ToFaceDrawing());
}
internal static void TestCylindoridXml()
{
Cylindroid cylindroid = new Cylindroid(24,
new PairZr(0, 1),
new PairZr(1, 1),
new PairZr(1, 2),
new PairZr(2, 2),
new PairZr(4, 3));
var xmlElement = cylindroid.MakeXmlSource(null, null);
Console.WriteLine("XML:" + xmlElement);
cylindroid = new Cylindroid(xmlElement);
DispEngine.Init();
DemoUtil.RunApplication("BuildCylindorid", cylindroid.ToFaceDrawing());
}
static void Main()
{
BuildCylindorid();
//TestCylindoridXml();
}
}
}
+40
View File
@@ -0,0 +1,40 @@
using Hi.Disp;
using Hi.Disp.Flag;
using Hi.Geom;
using Hi.Coloring;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoDiscreteRgb.cs)]
/// </remarks>
public class DemoDiscreteRgb : IDisplayee
{
/// <inheritdoc/>
public void Display(Bind bind)
{
bind.RGB = ColorUtil.GetDiscreteRGB_Env();
new Box3d(0, 0, 0, 1, 1, 1).ToDraw_Face().Display(bind);
bind.RGB = ColorUtil.GetDiscreteRGB_Env();
new Box3d(1, 0, 0, 2, 1, 1).ToDraw_Face().Display(bind);
bind.RGB = ColorUtil.GetDiscreteRGB_Env();
new Box3d(2, 0, 0, 3, 1, 1).ToDraw_Face().Display(bind);
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
dst.Expand(new Vec3d(0, 0, 0));
dst.Expand(new Vec3d(3, 1, 1));
}
static void Main()
{
DemoUtil.RunApplication("Demo Discrete I",
new DispList(new CoordinateDrawing(), new DemoDiscreteRgb()));
}
}
}
+177
View File
@@ -0,0 +1,177 @@
using Hi.Geom;
using Hi.Disp;
using System.Collections.Generic;
using Hi.Disp.Treat;
using Hi.Coloring;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoDrawing.cs)]
/// </remarks>
public static class DemoDrawing
{
public static void FreeDrawing()
{
#region DocSite.FreeDrawing
double[] vs =
{0,0,0
,1,0,0
,0,0,1};
DemoUtil.RunApplication("EasyDraw"
, new Drawing(vs, Stamp.V, GL.GL_LINE_STRIP));
#endregion
}
public static void DrawLines()
{
List<Vec3d> ps;
double[] vs;
int n = 10; //vertex num
////create drawPoints
ps = new List<Vec3d>(n);
for (int i = 0; i < n; i++)
ps.Add(new Vec3d(i, 0, 0));
vs = new double[ps.Count * 3];
for (int i = 0; i < ps.Count; i++)
{
vs[3 * i] = ps[i].x;
vs[3 * i + 1] = ps[i].y;
vs[3 * i + 2] = ps[i].z;
}
//V means Vertex
Drawing drawPoints = new Drawing(vs, Stamp.V, GL.GL_POINTS);
////create drawLineStrip
vs = new double[ps.Count * 3];
for (int i = 0; i < ps.Count; i++)
{
vs[3 * i] = i;
vs[3 * i + 1] = 0;
vs[3 * i + 2] = 1;
}
Drawing drawLineStrip = new Drawing(vs, Stamp.V, GL.GL_LINE_STRIP);
////create drawLineStripWithNormal
//the content of vs is Nx,Ny,Nz,Vx,Vy,Vz, Nx,Ny,Nz,Vx,Vy,Vz, ...
vs = new double[n * 6];
for (int i = 0; i < n; i++)
{
//nx,ny,nz
vs[6 * i] = 1;
vs[6 * i + 1] = 0;
vs[6 * i + 2] = 0;
//x,y,z
vs[6 * i + 3] = i;
vs[6 * i + 4] = 0;
vs[6 * i + 5] = 2;
}
//V means Vertex; N means Normal
Drawing drawLineStripWithNormal =
new Drawing(vs, Stamp.NV, GL.GL_LINE_STRIP);
////create drawColorLines
vs = new double[n * 6];
for (int i = 0; i < n; i++)
{
//the rgb values set casually.
//r,g,b
vs[6 * i] = i % 3 / 2D;
vs[6 * i + 1] = i % 5 / 4D;
vs[6 * i + 2] = i % 7 / 6D;
//x,y,z
vs[6 * i + 3] = i;
vs[6 * i + 4] = 0;
vs[6 * i + 5] = 3;
}
//V means Vertex; C means Color
Drawing drawLineStripWithColor = new Drawing(vs, Stamp.CV, GL.GL_LINE_STRIP);
DemoUtil.RunApplication("DrawLines",
new DispList(drawPoints, drawLineStrip
, drawLineStripWithNormal, drawLineStripWithColor));
}
public static void DrawTrianglesByPrimitives()
{
int n = 10;// triangle num
double[] vs;
////create drawTrisCV
//each triangle has 3 point; each point has r,g,b,x,y,z, totally 6 doubles.
vs = new double[n * 3 * 6];
for (int i = 0, k = 0; i < n; i++)
{
//the rgb values set as casual.
Vec3d rgb = ColorUtil.GetDiscreteRgb(i);
Tri3d tri = new Tri3d(new Vec3d(i, 0, 0), new Vec3d(i + 1, 0, 0), new Vec3d(i + 0.5, 0, 1));
for (int j = 0; j < 3; j++)
{
vs[k++] = rgb.x;
vs[k++] = rgb.y;
vs[k++] = rgb.z;
vs[k++] = tri.ps[j].x;
vs[k++] = tri.ps[j].y;
vs[k++] = tri.ps[j].z;
}
}
//V means Vertex; C means Color
Drawing drawTrisCV = new Drawing(vs, Stamp.CV, GL.GL_TRIANGLES);
////create drawTrisCNV
/////each triangle has 3 point; each point has r,g,b,nx,ny,nz,x,y,z, totally 6 doubles.
vs = new double[n * 3 * 9];
for (int i = 0, k = 0; i < n; i++)
{
//the rgb values set as casual.
Vec3d rgb = ColorUtil.GetDiscreteRgb(i);
Tri3d tri = new Tri3d(new Vec3d(i, 0, 3), new Vec3d(i + 1, 0, 3), new Vec3d(i + 0.5, 0, 4));
Vec3d nn = tri.GetNormal();
for (int j = 0; j < 3; j++)
{
vs[k++] = rgb.x;
vs[k++] = rgb.y;
vs[k++] = rgb.z;
vs[k++] = nn.x;
vs[k++] = nn.y;
vs[k++] = nn.z;
vs[k++] = tri.ps[j].x;
vs[k++] = tri.ps[j].y;
vs[k++] = tri.ps[j].z;
}
}
//V means Vertex; C means Color; N means Normal
Drawing drawTrisCNV = new Drawing(vs, Stamp.CNV, GL.GL_TRIANGLES);
//the color of colorTrisDraw is not influence by outer color setting.
DemoUtil.RunApplication("DrawTrianglesByPrimitives",
new DispList(new RgbTreat(1, 0, 0), drawTrisCV, drawTrisCNV));
}
public static void DrawTri3d()
{
int n = 10;
List<Tri3d> tris = new List<Tri3d>(n);
for (int i = 0; i < n; i++)
tris.Add(new Tri3d(new Vec3d(i, 0, 0), new Vec3d(i + 1, 0, 0), new Vec3d(i + 0.5, 0, 1)));
Drawing faceDraw = tris.GetFaceDrawing();
Drawing linesDraw = tris.GetLineDrawing();
DemoUtil.RunApplication("DrawTri3d",
new DispList(new RgbTreat(0, 0, 1), linesDraw
, new RgbTreat(1, 0, 0), faceDraw));
}
static void Main()
{
//FreeDrawing();
//DrawLines();
//DrawTrianglesByPrimitives();
DrawTri3d();
}
}
}
+43
View File
@@ -0,0 +1,43 @@
using Hi.Geom;
using Hi.Disp;
using Hi.Native;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoPick1.cs)]
/// </remarks>
public class DemoPick1 : Pickable, IDisplayee
{
bool isMouseOver = false;
/// <inheritdoc/>
public void Display(Bind bind)
{
bind.PickID = PickingID;
bind.RGB = new Vec3d(isMouseOver ? 0 : 1, 1, 1);
new Box3d(0, 0, 0, 1, 1, 1).DisplayFace(bind);
bind.PickID = 0;
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
dst.Expand(new Vec3d(0, 0, 0));
dst.Expand(new Vec3d(1, 1, 1));
}
/// <inheritdoc/>
public override void OnMouseEnter(ui_event_type e, panel_state_t state)
{
isMouseOver = true;
}
/// <inheritdoc/>
public override void OnMouseLeave(ui_event_type e, panel_state_t state)
{
isMouseOver = false;
}
public static void Main()
{
DemoUtil.RunApplication("DemoPick1", new DemoPick1());
}
}
}
+67
View File
@@ -0,0 +1,67 @@
using Hi.Geom;
using Hi.Disp;
using System;
using Hi.Coloring;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoPick2.cs)]
/// </remarks>
public class DemoPick2 : IDisplayee, IDisposable
{
readonly Pickable pickableA = new ShowEventPickable { Tag = "A" };
readonly Pickable pickableB = new ShowEventPickable { Tag = "B" };
readonly Pickable pickableC = new ShowEventPickable { Tag = "C" };
/// <inheritdoc/>
public void Display(Bind bind)
{
bind.PickID = pickableA.PickingID;
bind.RGB = ColorUtil.GetDiscreteRgb(1);
new Box3d(0, 0, 0, 1, 1, 1).DisplayFace(bind);
bind.PickID = pickableB.PickingID;
bind.RGB = ColorUtil.GetDiscreteRgb(2);
new Box3d(0, 0, 1, 1, 1, 2).DisplayFace(bind);
bind.PickID = pickableC.PickingID;
bind.RGB = ColorUtil.GetDiscreteRgb(3);
new Box3d(0, 0, 2, 1, 1, 3).DisplayFace(bind);
bind.PickID = 0;
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
dst.Expand(new Vec3d(0, 0, 0));
dst.Expand(new Vec3d(1, 1, 3));
}
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
/// <inheritdoc/>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
pickableA.Dispose();
pickableB.Dispose();
pickableC.Dispose();
}
disposedValue = true;
}
}
/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
}
#endregion
public static void Main()
{
DemoUtil.RunApplication("DemoPick2", new DemoPick2());
}
}
}
+47
View File
@@ -0,0 +1,47 @@
using Hi.Disp;
using Hi.Geom;
using System;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoPickable.cs)]
/// </remarks>
public class DemoPickable : IDisplayee
{
private readonly Drawing draw;
private readonly ShowEventPickable pickable;
public DemoPickable()
{
pickable = new ShowEventPickable();
double pid = pickable.PickingID;
double[] vs = new double[] {
//pickID, x,y,z
pid, 0,0.1,0.1,
pid, 0.1,0,0,
pid, 0.1,0,0.1
};
draw = new Drawing(vs, Stamp.PV, GL.GL_TRIANGLES);
}
/// <inheritdoc/>
public void Display(Bind bind)
{
draw.Display(bind);
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
draw.ExpandToBox3d(dst);
}
[STAThread]
public static void Main()
{
DemoUtil.RunApplication("DemoPickable", new DemoPickable());
}
}
}
+50
View File
@@ -0,0 +1,50 @@
using Hi.Geom;
using Hi.Disp;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoSatellite.cs)]
/// </remarks>
public class DemoSatellite : IDisplayee
{
Drawing sun;
Drawing earth;
Drawing moon;
double angle_earth;
double angle_moon;
DemoSatellite()
{
sun = Box3d.CenterUnitBox.ScaleFromCenter(4).ToDraw_Face();
earth = Box3d.CenterUnitBox.ScaleFromCenter(2).ToDraw_Face();
moon = Box3d.CenterUnitBox.ToDraw_Face();
}
/// <inheritdoc/>
public void Display(Bind bind)
{
sun.Display(bind);
bind.ModelMatStack.Push();
bind.ModelMatStack.Mul(new Mat4d(new AxisAngle4d(new Vec3d(0, 0, 1), angle_earth += 0.03)));
bind.ModelMatStack.Mul(new Mat4d(new Vec3d(12, 0, 0)));
earth.Display(bind);
bind.ModelMatStack.Push();
bind.ModelMatStack.Mul(new Mat4d(new AxisAngle4d(new Vec3d(0, 0, 1), angle_moon += 0.02)));
bind.ModelMatStack.Mul(new Mat4d(new Vec3d(4, 0, 0)));
moon.Display(bind);
bind.ModelMatStack.Pop();
bind.ModelMatStack.Pop();
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
dst.Expand(new Vec3d(-14, -14, -2));
dst.Expand(new Vec3d(14, 14, 2));
}
static void Main()
{
DemoUtil.RunApplication("DemoSatellite", new DemoSatellite());
}
}
}
+49
View File
@@ -0,0 +1,49 @@
using Hi.Geom;
using System;
using Hi.Disp;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoStl.cs)]
/// </remarks>
public static class DemoStl
{
internal static void TransformStl()
{
#region DocSite.TransformStl
Stl stl;
stl = new Stl("Demo/cubic.stl");
//scale the stl to 100x.
stl.Transform(new Mat4d(100));
//create a new stl file.
stl.WriteBin("big_cubic.stl");
stl = new Stl("Demo/cubic.stl");
//move the stl by (100,0,0)
stl.Transform(new Mat4d(new Vec3d(100, 0, 0)));
//create a new stl file.
stl.WriteBin("offset_x100_cubic.stl");
#endregion
}
internal static void DemoCommonUsage()
{
#region DocSite.CommonUsage
Stl stl = new Stl("Disp/cubic.stl");
Box3d bouindingbox = new Box3d(stl);
Console.WriteLine("bouindingbox.Min: " + bouindingbox.Min);
Console.WriteLine("bouindingbox.Max: " + bouindingbox.Max);
Console.WriteLine("bouindingbox.Center: " + bouindingbox.Center);
DispUtil.CallRenderingFrame("DemoForm", stl.ToFaceDrawing());
#endregion
}
static void Main()
{
DemoCommonUsage();
}
}
}
+32
View File
@@ -0,0 +1,32 @@
using Hi.Disp;
using Hi.Licenses;
using Hi.MongoUtils;
using Hi.Wpf.Disp;
using System.Windows;
namespace Sample.Disp
{
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoUtil.cs)]
/// </remarks>
public static class DemoUtil
{
public static void RunApplication(string title, IDisplayee displayee)
{
Application app = new Application();
app.Exit += (o, e) =>
{
if(MongoServer.IsDefaultInit)
MongoServer.Default.Dispose();
DispEngine.FinishDisp();
License.LogOutAll();
};
app.Run(new RenderingWindow()
{
Title = title,
Displayee = displayee
});
}
}
}
Binary file not shown.
+86
View File
@@ -0,0 +1,86 @@
solid cubic.stl
facet normal -1 -1.18178e-014 0
outer loop
vertex 0 0 1
vertex 0 1 1
vertex 0 0 0
endloop
endfacet
facet normal -1 -1.18178e-014 0
outer loop
vertex 0 0 0
vertex 0 1 1
vertex 0 1 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 1 0 1
vertex 0 0 1
vertex 1 0 0
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 1 0 0
vertex 0 0 1
vertex 0 0 0
endloop
endfacet
facet normal 1 1.0842e-016 0
outer loop
vertex 1 1 1
vertex 1 0 1
vertex 1 1 0
endloop
endfacet
facet normal 1 1.0842e-016 0
outer loop
vertex 1 1 0
vertex 1 0 1
vertex 1 0 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 0 1 1
vertex 1 1 1
vertex 0 1 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 0 1 0
vertex 1 1 1
vertex 1 1 0
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 1 0 1
vertex 1 1 1
vertex 0 0 1
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 0 1
vertex 1 1 1
vertex 0 1 1
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 1 1 0
vertex 1 0 0
vertex 0 1 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 0 1 0
vertex 1 0 0
vertex 0 0 0
endloop
endfacet
endsolid