Adds command line configuration
This commit is contained in:
parent
4b2a90321a
commit
c5b061d3bd
|
@ -1,21 +1,63 @@
|
|||
with Ada.Containers; use Ada.Containers;
|
||||
with Ada.Text_IO;
|
||||
with Ada.Float_Text_IO;
|
||||
with Ada.Integer_Text_IO;
|
||||
with GNAT.Command_Line; use GNAT.Command_Line;
|
||||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
|
||||
|
||||
with Dtm; use Dtm;
|
||||
with Dtm.Katie;
|
||||
with Dtm.Surface;
|
||||
with Stl;
|
||||
|
||||
|
||||
procedure Tesselada is
|
||||
|
||||
use Ada.Text_IO;
|
||||
Info : Dtm_Info;
|
||||
Input : File_Type;
|
||||
Minimum_Thickness : constant := 1.0;
|
||||
Z_Scaling_Value : constant := 10.0;
|
||||
Max_X_Y_Dimension : constant := 244.0;
|
||||
Minimum_Thickness : Dtm_Value := 1.0;
|
||||
Z_Scaling_Value : Dtm_Value := 10.0;
|
||||
Max_X_Y_Dimension : Dtm_Value := 150.0;
|
||||
Output_Mode_Binary : Boolean := True;
|
||||
Config : Command_Line_Configuration;
|
||||
Input_File : Unbounded_String := To_Unbounded_String("sample-data/katie.dat");
|
||||
|
||||
begin
|
||||
Ada.Text_IO.Put_Line("Tess started.");
|
||||
Open(Input, In_File, "sample-data/katie.dat");
|
||||
declare
|
||||
procedure Config_Callback(Switch, Param, Section : String) is
|
||||
begin
|
||||
if Switch = "-a" or Switch = "--ascii" then
|
||||
Output_Mode_Binary := False;
|
||||
elsif Switch = "-m" or Switch = "--min-thickness" then
|
||||
Minimum_Thickness := Dtm_Value'Value(Param);
|
||||
elsif Switch = "-z" or Switch = "--z-exagerate" then
|
||||
Z_Scaling_Value := Dtm_Value'Value(Param);
|
||||
elsif Switch = "-c"or Switch = "--constrain-xy" then
|
||||
Max_X_Y_Dimension := Dtm_Value'Value(Param);
|
||||
else
|
||||
Display_Help(Config);
|
||||
end if;
|
||||
end Config_Callback;
|
||||
begin
|
||||
Define_Switch (Config, "-a", Long_Switch => "--ascii",
|
||||
Help => "Output ASCII STL (Default is binary STL)");
|
||||
Define_Switch (Config, "-m:", Long_Switch => "--min-thickness=",
|
||||
Help => "Set Minimum Thickness (Default is " &Minimum_Thickness'Image & "mm)");
|
||||
Define_Switch (Config, "-z:",
|
||||
Long_Switch => "--z-exagerate=",
|
||||
Help => "Exagerate height data (Default is Z * " & Z_Scaling_Value'Image & ")");
|
||||
Define_Switch (Config, "-c:",
|
||||
Long_Switch => "--constrain-xy=",
|
||||
Help => "Constrain maximum X or Y dimension (Default is X or Y <= " & Max_X_Y_Dimension'Image & "mm)");
|
||||
Getopt(Config, Config_Callback'Unrestricted_Access);
|
||||
Input_File := To_Unbounded_String(Get_Argument);
|
||||
if Input_File = "" then
|
||||
Put_Line("Missing input file");
|
||||
return;
|
||||
end if;
|
||||
end;
|
||||
|
||||
Open(Input, In_File, To_String(Input_File));
|
||||
Info := Dtm.Katie.Get_Info(Input);
|
||||
|
||||
declare
|
||||
|
@ -25,21 +67,41 @@ begin
|
|||
Triangles : Dtm.Surface.Surface_Vector;
|
||||
Normalize_and_Scale_Factor : Dtm_Value;
|
||||
Constraint_Factor : Dtm_Value;
|
||||
|
||||
package Dtm_IO is new Ada.Text_IO.Float_IO(Dtm_Value); use Dtm_IO;
|
||||
use Ada.Integer_Text_IO;
|
||||
begin
|
||||
Put_Line("Processing " & To_String(Input_File));
|
||||
Put("Grid is "); Put(Info.Get_X, Width => 0); Put(" * "); Put(Info.Get_Y, Width => 0);
|
||||
New_Line;
|
||||
Put("Constraining maximum X or Y size to "); Put(Max_X_Y_Dimension, Exp => 0); Put_Line("mm");
|
||||
Put("Z Exaggeration is "); Put(Z_Scaling_Value, Exp => 0); Put_Line("x");
|
||||
Put("Minimum model thickness is"); Put(Minimum_Thickness, Exp => 0); Put_Line("mm");
|
||||
|
||||
Dtm.Katie.Get_Data(Data, Input);
|
||||
Normalize_and_Scale_Factor := Z_Scaling_Value / Max(Data);
|
||||
Data := Data * Normalize_and_Scale_Factor;
|
||||
Data := Data + Minimum_Thickness;
|
||||
Triangles.Reserve_Capacity(Count_Type(Info.Triangle_Count));
|
||||
Triangles.Reserve_Capacity(Count_Type(Info.Triangle_Count + Info.Get_X * 2 + Info.Get_Y * 2 + 2));
|
||||
Dtm.Surface.Surface_From_Grid(Triangles, Data);
|
||||
|
||||
if Info.Get_X > Info.Get_Y then
|
||||
Constraint_Factor := Max_X_Y_Dimension / Dtm_Value(Info.Get_X);
|
||||
else
|
||||
Constraint_Factor := Max_X_Y_Dimension / Dtm_Value(Info.Get_Y);
|
||||
end if;
|
||||
Dtm.Surface.Constrain(Triangles, Constraint_Factor);
|
||||
Stl.Write(Triangles, "Farts.stl");
|
||||
Stl.Write_Binary(Triangles, "Binary_Farts.stl");
|
||||
|
||||
declare
|
||||
Output_File_Name : String := To_String(Input_File & ".stl");
|
||||
begin
|
||||
if Output_Mode_Binary = True then
|
||||
Put_Line("Outputting Binary STL: " & Output_File_Name);
|
||||
Stl.Write_Binary(Triangles, Output_File_Name);
|
||||
else
|
||||
Put_Line("Outputting ASCII STL: " & Output_File_Name);
|
||||
Stl.Write(Triangles, Output_File_Name);
|
||||
end if;
|
||||
end;
|
||||
|
||||
end;
|
||||
end Tesselada;
|
||||
|
|
Loading…
Reference in New Issue