### Install PicoGK Development Environment Source: https://context7.com/leap71/leap71.github.io/llms.txt Guides users through installing the necessary tools and dependencies for developing with PicoGK. This includes installing the .NET SDK, Visual Studio Code with C# extensions, and downloading the example projects. It targets Windows 64-bit and macOS on Apple Silicon. ```bash # 1. Install .NET SDK 9.0 from Microsoft # Download from: https://dotnet.microsoft.com/en-us/download/dotnet/sdk-for-vs-code # 2. Install Visual Studio Code # Download from: https://code.visualstudio.com # 3. Install C# Dev Kit extension in VS Code # Search for "C#" in extensions and install "C# Dev Kit" # 4. Download PicoGK_Examples from GitHub # Visit: https://github.com/leap71/PicoGK_Examples # Click "Code" → "Download ZIP" # 5. Extract to your Documents folder and open in VS Code # File → Open Folder → Select PicoGK_Examples-main # 6. Run the project # Click "Run and Debug" button (left sidebar) # Press "Run and Debug" button # Select "C#" when prompted for debugger # Select first option for Launch Configuration # Select first option for C# Startup Project # The viewer window will launch and showcase PicoGK operations # Check PicoGK.log in your Documents folder for diagnostic messages ``` -------------------------------- ### C# App.Run() Method: Fixture Creation Example Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/9-computational-fixture-maker.md Provides an example of the App.Run() method in C# that sets up a 3D printing scenario. It involves instantiating a BasePlate, loading and scaling a mesh (Utah Teapot), creating a FixtureObject with specific dimensions, and then initializing and running a FixtureMaker to process the object. ```csharp public class App { public static void Run() { BasePlate oBase = new(); Mesh mshSmall = Mesh.mshFromStlFile( Path.Combine( Utils.strPicoGKSourceCodeFolder(), "Examples/Testfiles/Teapot.stl")); Mesh mshObject = mshSmall.mshCreateTransformed(new(6,6,6), Vector3.Zero); FixtureObject oObject = new( mshObject, 10, 15, 3, 20); FixtureMaker oMaker = new(oBase, oObject); oMaker.Run(); } } ``` -------------------------------- ### C# Voxel Offsetting and Projection Example Source: https://context7.com/leap71/leap71.github.io/llms.txt Demonstrates voxel offsetting (expansion, contraction, shell creation) and Z-axis projection for extrusion and creating tapered structures. Includes practical examples like creating a mounting flange with holes. ```csharp using PicoGK; using System.Numerics; // Create base geometry Lattice lat = new(); lat.AddSphere(Vector3.Zero, 30); Voxels voxOriginal = new(lat); // Positive offset: expand outward by 5mm Voxels voxExpanded = voxOriginal.voxOffset(5); // Negative offset: contract inward by 5mm Voxels voxContracted = voxOriginal.voxOffset(-5); // Create hollow shell: offset inward and subtract Voxels voxShell = voxOriginal.voxOffset(3) - voxOriginal.voxOffset(-3); Library.oViewer().Add(voxExpanded, 0); Library.oViewer().Add(voxContracted, 1); Library.oViewer().Add(voxShell, 2); // Z-axis projection: create extruded profile // ProjectZSlice(topZ, bottomZ) - projects geometry between Z heights Voxels voxTower = new Voxels(voxOriginal); meningkatkan.ProjectZSlice(100, 0); // Project from Z=0 to Z=100 // Create tapered structure using projection Lattice latComplex = new(); latComplex.AddBeam(new Vector3(0, 0, 0), new Vector3(50, 0, 0), 10, 5); latComplex.AddBeam(new Vector3(50, 0, 0), new Vector3(50, 50, 0), 5, 15); Voxels voxComplex = new(latComplex); // Offset then project to create thick-walled extrusion voxComplex.Offset(2); // Add 2mm wall voxComplex.ProjectZSlice(50, 0); // Extrude to 50mm height // Trim projected geometry with bounding box BBox3 trimBox = new(new(-20, -20, 0), new(70, 70, 30)); Mesh mshTrim = Utils.mshCreateCube(trimBox); voxComplex.BoolIntersect(new Voxels(mshTrim)); Library.oViewer().Add(voxTower, 3); Library.oViewer().Add(voxComplex, 4); // Practical example: Create mounting flange Lattice latPipe = new(); latPipe.AddBeam(Vector3.Zero, new Vector3(0, 0, 100), 20, 20, true); Voxels voxPipe = new(latPipe); // Create flange at bottom by offsetting and projecting Voxels voxFlange = new Voxels(voxPipe); voxFlange.Offset(30); // Make flange 30mm wider than pipe voxFlange.ProjectZSlice(10, 0); // Flange is 10mm tall // Combine pipe and flange Voxels voxPipeWithFlange = voxPipe + voxFlange; // Create mounting holes in flange float fHoleRadius = 5; float fBoltCircle = 40; for (int i = 0; i < 4; i++) { float fAngle = (float)(i * Math.PI / 2); Vector3 vecHolePos = new Vector3( fBoltCircle * (float)Math.Cos(fAngle), fBoltCircle * (float)Math.Sin(fAngle), 5); Lattice latHole = new(); latHole.AddSphere(vecHolePos, fHoleRadius); Voxels voxHole = new(latHole); voxHole.ProjectZSlice(10, 0); // Through-hole voxPipeWithFlange.BoolSubtract(voxHole); } Library.oViewer().SetGroupMaterial(5, "c0c0c0", 0.8f, 0.2f); Library.oViewer().Add(voxPipeWithFlange, 5); ``` -------------------------------- ### Example Usage of Surface Modulation Implementations in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/17-computational-geometry-part5.md Illustrates how to instantiate and combine different IModulation implementations, including ModulationImage, ModulationTrans, ModulationGauss, ModulationRandom, and ModulationNoop, to create various surface effects for a BaseBox object. This example showcases a practical application of the defined interfaces and classes. ```csharp IModulation xImg = new ModulationImage(img); IModulation xTop = new ModulationTrans(xImg, 0.02f); IModulation xBottom = new ModulationGauss(); IModulation xLeft = new ModulationRandom(0.001f); IModulation xRight = new ModulationNoop(); IModulation xBack = xBottom; IModulation xFront = xBottom; BaseBox oBox = new(); ``` -------------------------------- ### Using Properties as Variables in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/21-properties.md Demonstrates how properties can be accessed and modified using a variable-like syntax in C#. This example shows setting a property and retrieving its value. ```csharp public static void DoSomething() { SomeClass oClass = new(); oClass.vecOrigin = Vector3.UnitX; Vector3 vecValue = oClass.vecOrigin; Console.WriteLine($"Value= {vecValue}"); } ``` -------------------------------- ### Basic C# 'Hello World' Output Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/3-running-code.md This snippet demonstrates a basic C# program to print 'Hello World' to the console. It initializes a string variable and then uses the Console.WriteLine method to display its content. This is a foundational example for understanding C# application execution and output. ```csharp string str; str = "Hello World"; Console.WriteLine(str); ``` -------------------------------- ### Application Setup Instantiating FixtureMaker in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/9-computational-fixture-maker.md Demonstrates how to instantiate and use the `FixtureMaker` class within an application's run function. It shows the creation of `BasePlate` and `FixtureObject` instances, passing them to the `FixtureMaker` constructor, and then calling the `Run` method. ```csharp BasePlate oBase = new(); FixtureObject oObject = new(); FixtureMaker oMaker = new(oBase, oObject); oMaker.Run(); ``` -------------------------------- ### ProgressReporter Usage Examples Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/10-computational-fixture-maker-2.md Illustrates how to use the methods defined in the ProgressReporter interface to manage visual elements and their properties. These calls would replace direct calls to viewer functions. ```csharp oProgress.SetGroupMaterial(0, "da9c6b", 0.3f, 0.7f); oProgress.SetGroupMaterial(1, "FF0000BB", 0.5f, 0.5f); oProgress.AddObject(oObject.voxObject(), 1); oProgress.AddObject(m_voxFixture, 0); ``` -------------------------------- ### BaseBox Initialization and Transformation Matrix Access Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/15-computational-geometry-part3.md Shows how to initialize the BaseBox with an identity transformation matrix and provides methods to get and set the transformation matrix. ```csharp public BaseBox() { m_matTransform = Matrix4x4.Identity; } public Matrix4x4 matTransform() {return m_matTransform} public void SetTransform(Matrix4x4 matNew) {m_matTransform = matNew} public mshConstruct() { ... } ``` -------------------------------- ### C# Property Implementation for Transformation Matrix Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/15-computational-geometry-part3.md Demonstrates how to use C# properties with 'get' and 'set' accessors to provide convenient access to the transformation matrix member variable. ```csharp public get { return m_matTransform; } public set { m_matTransform = value; } ``` ```csharp public Matrix4x4 matTransform {get;set;} ``` -------------------------------- ### C# Orienting Boxes Towards a Different Point Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/15-computational-geometry-part3.md Demonstrates orienting boxes towards a specified look-at point (0,0,100) using the CreateWorld function. This example showcases flexibility in defining the forward direction for the boxes. ```csharp Vector3 vecLookAtPoint = new Vector3(0,0,100); Vector3 vecDir = Vector3.Normalize(vecLookAtPoint - vecP); Matrix4x4 matWorld = Matrix4x4.CreateWorld( position: vecP, forward: vecDir, up: Vector3.UnitZ); ``` -------------------------------- ### Initialize PicoGK and Run Tasks in C# Source: https://context7.com/leap71/leap71.github.io/llms.txt This snippet demonstrates how to initialize the PicoGK library and execute computational geometry tasks within a C# console application. It covers creating a basic voxel sphere and a cube, applying materials, adding them to viewer groups, and saving geometry to an STL file. Ensure the PicoGK NuGet package is installed. ```csharp using PicoGK; // In Program.cs - entry point for console application namespace MyPicoGKApp { class Program { static void Main(string[] args) { // Initialize PicoGK library and launch viewer // Pass a delegate to your main task function Library.Go(MyGeometryTask); } static void MyGeometryTask() { // All PicoGK operations happen here // Create a simple voxel sphere Lattice lat = new(); lat.AddSphere(new System.Numerics.Vector3(0, 0, 0), 25); Voxels voxSphere = new(lat); // Set material: hex color, metallic (0-1), roughness (0-1) Library.oViewer().SetGroupMaterial(0, "4287f5", 0.8f, 0.2f); // Add to viewer group 0 Library.oViewer().Add(voxSphere, 0); // Create and add multiple objects to different groups Voxels voxBox = new(Utils.mshCreateCube( new BBox3(new(-10, -10, -10), new(10, 10, 10)))); Library.oViewer().SetGroupMaterial(1, "ff6b35", 0.2f, 0.8f); Library.oViewer().Add(voxBox, 1); // Save geometry to disk try { voxSphere.SaveToStlFile("output_sphere.stl"); Console.WriteLine("Saved sphere to output_sphere.stl"); } catch (Exception ex) { Console.WriteLine($"Error saving file: {ex.Message}"); } } } } // Alternative: Using the example project structure // In PicoGK_Examples, tasks are organized in separate files namespace PicoGK_Examples { class MyTask { public static void Task() { // Your geometry code here Lattice lat = new(); lat.AddBeam(Vector3.Zero, new(100, 0, 0), 10, 10, true); Voxels vox = new(lat); Library.oViewer().Add(vox); } } } // In Program.cs, call the task: // Library.Go(MyTask.Task); ``` -------------------------------- ### FixtureMaker Class Constructor with Initial Parameters in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/9-computational-fixture-maker.md Illustrates an early implementation of the FixtureMaker class constructor. It accepts base plate dimensions and hole properties as parameters to initialize the fixture generation process. This approach is presented as a starting point before adopting a more object-oriented design. ```csharp public class FixtureMaker { public FixtureMaker( Vector3 vecBasePlateMM, float fBorderMM, float fHoleSpacingMM, float fHoleDiameterMM, ... More stuff) { m_vecBasePlate = vecBasePlateMM; m_fBorder = fBorderMM; m_fHoleSpacing = fHoleSpacingMM; m_fHoleRadius = fHoleDiameterMM / 2; .... More stuff } ... } ``` -------------------------------- ### Create Voxel Geometry with Lattice Beams in C# Source: https://context7.com/leap71/leap71.github.io/llms.txt Demonstrates how to construct 3D geometry using PicoGK's lattice system in C#. It covers creating beams with specified start/end points, radii, and caps, converting lattices to voxels for boolean operations, and displaying the results in a viewer. The example also shows creating connected pipe segments. ```csharp using PicoGK; using System.Numerics; // Create a rounded cone from a single lattice beam Lattice lat = new(); // Add beam: start point, end point, start radius (5mm), end radius (20mm), rounded caps lat.AddBeam(new Vector3(0, 0, 0), // Start at origin new Vector3(50, 0, 0), // End 50mm along X axis 5, // 5mm radius at start 20, // 20mm radius at end true); // Rounded caps enabled // Convert lattice to voxels (materializes the mathematical formula) Voxels vox = new(lat); // Display in viewer Library.oViewer().Add(vox); // Create connected pipe segments with multiple beams Lattice latPipe = new(); latPipe.AddBeam(new Vector3(0, 0, 0), new Vector3(50, 0, 0), 5, 5, true); latPipe.AddBeam(new Vector3(50, 0, 0), new Vector3(50, 50, 0), 5, 5, true); latPipe.AddBeam(new Vector3(50, 50, 0), new Vector3(0, 0, 0), 5, 5, true); Voxels voxTriangle = new(latPipe); Library.oViewer().Add(voxTriangle); ``` -------------------------------- ### Auto-Implemented Property Shortcut in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/21-properties.md Shows the syntax for auto-implemented properties in C#, which provide a concise way to declare properties with automatically generated getter and setter methods. The example highlights its potential use in simple container objects. ```csharp public Vector3 vecOrigin {get;set;} = Vector3.Zero; ``` -------------------------------- ### Generate Custom Fixture from STL Mesh in C# Source: https://context7.com/leap71/leap71.github.io/llms.txt This C# code demonstrates the core functionality of the Computational Fixture Maker. It loads an STL mesh, scales it, and then uses the FixtureMaker class to generate a holding fixture around the object. The fixture includes a conformal sleeve and a base flange, with specified clearances and dimensions. This example requires the PicoGK library. ```csharp using PicoGK; using System.Numerics; namespace Coding4Engineers.FixtureFun { public class App { public static void Go() { BasePlate oBase = new(); // Load and scale mesh (scale by 6x from original) Mesh mshSmall = Mesh.mshFromStlFile( Path.Combine(Utils.strPicoGKSourceCodeFolder(), "Examples/Testfiles/Teapot.stl")); Mesh mshObject = mshSmall.mshCreateTransformed(new(6, 6, 6), Vector3.Zero); // Create fixture with parameters: 10mm bottom clearance, 15mm sleeve, // 3mm wall thickness, 20mm flange width FixtureObject oObject = new(mshObject, 10, 15, 3, 20); FixtureMaker oMaker = new(oBase, oObject); oMaker.Run(); } } public class FixtureObject { public FixtureObject(Mesh msh, float fObjectBottomMM, float fSleeveMM, float fWallMM, float fFlangeMM) { if (fObjectBottomMM <= 0) throw new Exception("Object cannot be placed below build plate"); // Center object horizontally, position above build plate BBox3 oObjectBounds = msh.oBoundingBox(); Vector3 vecOffset = new Vector3( -oObjectBounds.vecCenter().X, -oObjectBounds.vecCenter().Y, -oObjectBounds.vecMin.Z + fObjectBottomMM); m_voxObject = new Voxels(msh.mshCreateTransformed(Vector3.One, vecOffset)); m_fObjectBottom = fObjectBottomMM; m_fSleeve = fSleeveMM; m_fWall = fWallMM; m_fFlange = fFlangeMM; } public Voxels voxObject() => m_voxObject; public float fWallMM() => m_fWall; public float fSleeveMM() => m_fSleeve; public float fFlangeHeightMM() => m_fObjectBottom; public float fFlangeWidthMM() => m_fFlange; Voxels m_voxObject; float m_fWall, m_fSleeve, m_fObjectBottom, m_fFlange; } public class FixtureMaker { public FixtureMaker(BasePlate oPlate, FixtureObject oObject) { m_oPlate = oPlate; m_oObject = oObject; } public void Run() { // Create conformal sleeve around object Voxels voxFixture = new(m_oObject.voxObject()); voxFixture.Offset(m_oObject.fWallMM()); // Project to create vertical sleeve walls voxFixture.ProjectZSlice( m_oObject.fFlangeHeightMM() + m_oObject.fSleeveMM(), 0); // Trim sleeve to correct height BBox3 oFixtureBounds = voxFixture.mshAsMesh().oBoundingBox(); oFixtureBounds.vecMin.Z = 0; oFixtureBounds.vecMax.Z = m_oObject.fFlangeHeightMM() + m_oObject.fSleeveMM(); voxFixture.BoolIntersect( new Voxels(Utils.mshCreateCube(oFixtureBounds))); // Create wider flange at bottom Voxels voxFlange = new(voxFixture); voxFlange.Offset(m_oObject.fFlangeWidthMM()); BBox3 oFlangeBounds = voxFlange.mshAsMesh().oBoundingBox(); oFlangeBounds.vecMin.Z = 0; oFlangeBounds.vecMax.Z = m_oObject.fFlangeHeightMM(); voxFlange.BoolIntersect( new Voxels(Utils.mshCreateCube(oFlangeBounds))); // Combine flange and sleeve, subtract object cavity voxFixture.BoolAdd(voxFlange); voxFixture.BoolSubtract(m_oObject.voxObject()); // Display with materials: gold fixture, red transparent object Library.oViewer().SetGroupMaterial(0, "da9c6b", 0.3f, 0.7f); Library.oViewer().SetGroupMaterial(1, "FF0000BB", 0.5f, 0.5f); Library.oViewer().Add(m_oObject.voxObject(), 1); Library.oViewer().Add(voxFixture, 0); } BasePlate m_oPlate; FixtureObject m_oObject; } public class BasePlate { } } ``` -------------------------------- ### C# Public Accessor Methods Example Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/2-fundamentals.md Shows how to expose class data through public accessor methods in C#. These methods provide controlled read access to private member variables, adhering to encapsulation principles. This example includes methods to get the car's name, battery level, and health. ```csharp public class TeslaRoadster { public TeslaRoadster( string strName = "Poor anonymous car", uint nPercentFull = 0) { m_fBatteryLevel = nPercentFull / 100.0f; m_strName = strName; } public void Charge() { m_fBatteryLevel = 1; m_nChargingCycles = m_nChargingCycles + 1; } public string strName() { return m_strName; } public uint nBatteryLevelPercent() { return Convert.ToUInt32(m_fBatteryLevel * 100.0f); } public uint nBatteryHealthPercent() { // Calculate an abstract "health percentage" float fHealth = 1.0f - (float) m_nChargingCycles / 10000.0f; return Convert.ToUInt32(fHealth * 100.0f); } float m_fBatteryLevel; uint m_nChargingCycles = 0; string m_strName; } ``` -------------------------------- ### Add multiple lattice beams to form a triangle in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/8-first-steps-in-picogk.md This C# code snippet shows how to construct a more complex lattice by adding multiple beams. Each beam is defined with start and end points, equal radii, and rounded caps. The example creates three beams that connect to form a triangular shape, which is then voxelized. ```csharp Lattice lat = new(); lat.AddBeam( new Vector3(0,0,0), new Vector3(50,0,0), 5, 5, true); lat.AddBeam( new Vector3(50,0,0), new Vector3(50,50,0), 5, 5, true); lat.AddBeam( new Vector3(50,50,0), new Vector3(0,0,0), 5, 5, true); Voxels vox = new(lat); ``` -------------------------------- ### C# PicoGK Application Entry Point Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/8-first-steps-in-picogk.md Shows the basic structure for running a PicoGK application. The `PicoGK.Library.Go` function initializes the voxel resolution and specifies the task function to execute. ```csharp PicoGK.Library.Go(0.5f, Coding4Engineers.LatticeExample.Task); ``` -------------------------------- ### Expensive Property Calculation Example in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/21-properties.md Illustrates a potential pitfall of using properties for operations that are computationally expensive. This example defines a property whose getter involves a long-running calculation. ```csharp public class Universe { public State oQuantumStateOfTheUniverse { // Calculation takes roughly 13.8 billion years, give or take get => oCalculateTheQuantumStateOfTheUniverse(); } } ``` -------------------------------- ### C# Private Class Members Example Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/2-fundamentals.md Demonstrates a C# class with private member variables and methods. Private members are not accessible from outside the class, enforcing encapsulation. This example shows the default visibility of members in C#. ```csharp class TeslaRoadster { TeslaRoadster( string strName = "Poor anonymous car", uint nPercentFull = 0) { m_fBatteryLevel = nPercentFull / 100.0f; m_strName = strName; } void Charge() { m_fBatteryLevel = 1; m_nChargingCycles = m_nChargingCycles + 1; } float m_fBatteryLevel; uint m_nChargingCycles = 0; string m_strName; } ``` -------------------------------- ### C# FixtureMaker.Run() Method: Applying Offset and ProjectZSlice Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/9-computational-fixture-maker.md Demonstrates the FixtureMaker.Run() method in C#, which first creates a copy of the object's voxels and applies an offset based on the wall thickness. It then uses ProjectZSlice to project voxels downwards to a specified height, preparing the object for 3D printing by creating a solid base and handling potential undercuts. ```csharp public void Run() { Voxels voxFixture = new(m_oObject.voxObject()); voxFixture.Offset(m_oObject.fWallMM()); voxFixture.ProjectZSlice(m_oObject.fFlangeHeightMM() + m_oObject.fSleeveMM(), 0); Library.oViewer().Add(voxFixture); } ``` -------------------------------- ### Create Lattice Beams and Voxels for Pipe Geometry (C#) Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/13-computational-geometry-part1.md This snippet demonstrates the initial steps of creating pipe geometry using the Leap71 library. It involves initializing a Lattice, adding beam segments with specified dimensions and wall thickness, and then converting this lattice into voxel representations for both the internal fluid volume and an offsetted outer volume. A bounding box is defined to later trim the pipe ends. ```csharp Lattice lat = new(); lat.AddBeam(Vector3.Zero, new(100,0,0), 10, 10); lat.AddBeam(new(100,0,0), new(100,100,0), 10, 10); lat.AddBeam(new(100,100,0), new(100,100,100), 10, 10); BBox3 oBox = new(new(0,-12,-12), new(112,112,100)); Voxels voxInside = new(lat); Voxels voxOutside = voxInside.voxOffset(2); Voxels voxPipe = (voxOutside - voxInside) & new Voxels(Utils.mshCreateCube(oBox)); Library.oViewer().Add(voxPipe, 1); ``` -------------------------------- ### C# Property with Getter Only (Full Syntax) Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/21-properties.md Presents the full syntax for a C# property with only a getter. It explicitly defines the 'get' accessor, which returns the value of the private backing field. ```csharp public Vector3 vecOrigin { get { return m_vecOrigin; } } ``` -------------------------------- ### Fixture Instantiation with ProgressReporterActive Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/10-computational-fixture-maker-2.md Demonstrates how to instantiate the Fixture class, passing an instance of ProgressReporterActive to enable viewer output. This ensures the Fixture continues to report progress visually as before. ```csharp Fixture oFixture = new( oBase, oObject, new ProgressReporterActive()); ``` -------------------------------- ### C# Public Class Members Example Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/2-fundamentals.md Illustrates a C# class with public visibility for the class itself, its constructor, and methods. Public members are accessible from outside the class. This allows for instantiation and interaction with the object. ```csharp public class TeslaRoadster { public TeslaRoadster( string strName = "Poor anonymous car", uint nPercentFull = 0) { m_fBatteryLevel = nPercentFull / 100.0f; m_strName = strName; } public void Charge() { m_fBatteryLevel = 1; m_nChargingCycles = m_nChargingCycles + 1; } float m_fBatteryLevel; uint m_nChargingCycles = 0; string m_strName; } ``` -------------------------------- ### C# Grid anLeftEdge Method to Get Left Edge Vertices Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/17-computational-geometry-part5.md Retrieves an array of vertex indices that form the left edge of the grid. This is used to share edge data with adjacent grids. ```csharp public int [] anLeftEdge() { // U direction int [] anEdge = new int [m_anGrid.GetLength(1)]; for (int v=0;v ai = new(); ai.AddLast(10); Console.WriteLine(ai.Count()); ``` -------------------------------- ### Creating a Lattice and Voxelizing it in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/19-computational-geometry-part7.md Demonstrates the creation of a `Lattice` object and its subsequent voxelization into a `Voxels` object using C#. This is a foundational step before applying implicit structures for infill. ```csharp Lattice lat = new(); lat.AddBeam( Vector3.Zero, new(6,0,8), 2, 3); Voxels vox = new(lat); ``` -------------------------------- ### C# Property with Getter and Setter Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/21-properties.md Demonstrates a C# property with both 'get' and 'set' accessors. The setter includes logic to check if the new value differs from the current one before updating the backing field and setting a recomputation flag. ```csharp public Vector3 vecOrigin { get { return m_vecOrigin; } set { if (value != m_vecOrigin) { m_vecOrigin = value; m_bRecomputeRequired = true; } } } ``` -------------------------------- ### C# Hollow Pipe Creation with Boolean Subtract Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/8-first-steps-in-picogk.md Demonstrates creating a hollow pipe by subtracting an inner voxel shape from an outer one using PicoGK's boolean operations. This method is reliable and efficient for constructing complex geometries. ```csharp Lattice latOutside = new(); latOutside.AddBeam( new Vector3(0,0,0), new Vector3(50,0,0), 10, 10, false); Lattice latInside = new(); latInside.AddBeam( new Vector3(0,0,0), new Vector3(50,0,0), 8, 8, false); Voxels voxOutside = new(latOutside); Voxels voxInside = new(latInside); voxOutside.BoolSubtract(voxInside); ``` -------------------------------- ### C# Pass-by-Value Function Example Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/22-values-references.md Demonstrates how modifying a parameter of a value type (float) inside a function does not affect the original variable outside the function because it's passed by value (a copy is made). ```csharp static void DontChangeVariable(float f) { f = 5; } float fValue = 10; DontChangeVariable(fValue); Console.WriteLine(fValue); ``` -------------------------------- ### Integrate FixtureMaker App with PicoGK in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/9-computational-fixture-maker.md Demonstrates how to call the 'App.Run' method from the 'Fixtures' namespace within the main PicoGK execution flow. It includes error handling using a try-catch block to display any exceptions that occur during execution. This snippet is intended to be added to the 'Program.cs' file. ```csharp try { PicoGK.Library.Go(.5f, Coding4Engineers.Fixtures.App.Run); } catch (Exception e) { Console.WriteLine(e.ToString()); } ``` -------------------------------- ### C# Pass-by-Reference Function Example (using 'ref') Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/22-values-references.md Illustrates how to pass a value type by reference using the 'ref' keyword in C#. When passed by reference, modifications inside the function directly alter the original variable. ```csharp void ChangeVariable(ref float f) { f = 5; } float fValue = 10; ChangeVariable(ref fValue); Console.WriteLine(fValue); ``` -------------------------------- ### C# App.Run Method Integration with Fixture Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/10-computational-fixture-maker-2.md Demonstrates how to integrate the new `Fixture` class into an existing `App.Run` method in C#. This involves creating an instance of `Fixture` with the necessary parameters. ```csharp public static void Run() { // previous stuff unchanged Fixture oFixture = new(oBase, oObject); } ``` -------------------------------- ### C# Constructor for Box Initialization Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/15-computational-geometry-part3.md Initializes a BaseBox object with a specified size. It creates a scaling matrix by dividing the input Vector3 size by 2, ensuring proper scaling of the object. ```csharp public BaseBox(Vector3 vecSize) { matTransform = Matrix4x4.CreateScale(vecSize / 2); } ``` -------------------------------- ### Empty FixtureObject Class Definition in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/9-computational-fixture-maker.md Defines a minimal `FixtureObject` class with no members. This class acts as a placeholder for the object that will be held by the fixture. Similar to `BasePlate`, this definition allows for initial setup and deferral of specific attribute definitions. ```csharp public class FixtureObject { // nothing here yet } ``` -------------------------------- ### Implement Image-Based Surface Modulation in C# Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/17-computational-geometry-part5.md Implements the IModulation interface using an image. The fHeight method reads the grayscale value from the provided image at the given UV coordinates to determine the surface height. It requires an Image object during instantiation. ```csharp public class ModulationImage : IModulation { public ModulationImage(Image img) { m_img = img; } public float fHeight(Vector2 vecUV) { int nX = (int) float.Round(vecUV.X * m_img.nWidth); int nY = (int) float.Round(vecUV.Y * m_img.nHeight); return m_img.fValue(nX, nY); } Image m_img; } ``` -------------------------------- ### Implement C# Class Method with No Return Value Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/2-fundamentals.md This snippet illustrates how to define a method within a C# class that performs an action but does not return any value. The 'void' keyword signifies that the function has no return type. This example includes a 'Charge' method that sets the battery level. ```csharp class TeslaRoadster { void Charge() { m_fBatteryLevel = 1; } float m_fBatteryLevel; string m_strName; } ``` -------------------------------- ### Declare C# Class Member Variables Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/2-fundamentals.md This example demonstrates how to declare member variables within a C# class to store data associated with an object. It includes a 'float' for battery level and a 'string' for the car's name, using a common naming convention with prefixes. ```csharp class TeslaRoadster { float m_fBatteryLevel; string m_strName; } ``` -------------------------------- ### C# Rendering an Implicit Sphere with Bounding Box Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/19-computational-geometry-part7.md This C# code snippet demonstrates how to render an `ImplicitSphere` using PicoGK's `Voxels` object. It requires creating an `ImplicitSphere` instance and a `BBox3` to define the sampling region for the rendering process. ```csharp ImplicitSphere oSphere = new(3); Voxels vox = new(); vox.RenderImplicit(oSphere, new BBox3( new Vector3(-3,-3,-3), new Vector3(3,3,3))); ``` -------------------------------- ### Alternative Voxels Creation and Manipulation for Pipe (C#) Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/13-computational-geometry-part1.md This snippet provides a more explicit, step-by-step version of the voxel operations shown previously. It details the process of creating the inside voxel volume, then creating an offsetted outside volume by copying and applying an offset. It further explains the subtraction of inside from outside to form the pipe shell and the intersection with a bounding box mesh to trim the ends. ```csharp Voxels voxInside = new Voxels(lat); Voxels voxOutside = voxInside; voxOutside.Offset(2); Voxels voxPipe = (voxOutside - voxInside); Mesh mshBounds = Utils.mshCreateCube(oBox); Voxels voxBounds = new Voxels(mshBounds); voxPipe.Intersect(voxBounds); ``` -------------------------------- ### C# Complex Voxel Operations with Operator Overloading Source: https://github.com/leap71/leap71.github.io/blob/main/coding-for-engineers/12-computational-fixture-maker-4.md Shows an example of combining multiple voxel operations (addition, subtraction, intersection) using overloaded operators in a single expression. This highlights the enhanced readability and conciseness achieved with operator overloading for complex voxel manipulations. ```csharp Voxels voxResult = (voxUpper + voxBottom).voxOffset(fWallThickness) + (voxPort - voxHole) + voxInlet + voxOutlet + voxSupports; ``` ```csharp return (voxEngine + voxBasePlate) & voxPrinterVolume; ```