mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 22:00:33 +05:00
Merge branch 'write_chart_to_file' into 'master'
Button to write selected chart (closed with extra point) to separate .stlb file See merge request jschoeberl/netgen!245
This commit is contained in:
commit
b4751c2ba8
@ -3521,6 +3521,75 @@ void STLGeometry :: SmoothGeometry ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void STLGeometry :: WriteChartToFile( ChartId chartnumber, string filename )
|
||||||
|
{
|
||||||
|
PrintMessage(1,"write chart ", int(chartnumber), " to ", filename);
|
||||||
|
Array<int> trignums;
|
||||||
|
|
||||||
|
if (chartnumber >= 1 && chartnumber <= GetNOCharts())
|
||||||
|
{
|
||||||
|
const STLChart& chart = GetChart(chartnumber);
|
||||||
|
|
||||||
|
for (int j = 1; j <= chart.GetNChartT(); j++)
|
||||||
|
trignums.Append(chart.GetChartTrig1(j));
|
||||||
|
|
||||||
|
for (int j = 1; j <= chart.GetNOuterT(); j++)
|
||||||
|
trignums.Append(chart.GetOuterTrig1(j));
|
||||||
|
|
||||||
|
QuickSort(trignums);
|
||||||
|
STLGeometry geo;
|
||||||
|
NgArray<STLReadTriangle> readtrigs;
|
||||||
|
const auto & first_trig = GetTriangle(chart.GetChartTrig1(1));
|
||||||
|
auto normal = first_trig.Normal();
|
||||||
|
Box<3> box{Box<3>::EMPTY_BOX};
|
||||||
|
|
||||||
|
for(auto j : trignums)
|
||||||
|
{
|
||||||
|
const auto& trig = GetTriangle(j);
|
||||||
|
Point<3> pts[3];
|
||||||
|
for(auto k : Range(3))
|
||||||
|
{
|
||||||
|
pts[k] = GetPoint(trig[k]);
|
||||||
|
box.Add(pts[k]);
|
||||||
|
}
|
||||||
|
Vec3d normal = Cross( pts[1]-pts[0], pts[2]-pts[0] );
|
||||||
|
readtrigs.Append(STLReadTriangle(pts, trig.Normal()));
|
||||||
|
}
|
||||||
|
auto dist = box.PMax() - box.PMin();
|
||||||
|
auto extra_point = GetPoint(first_trig[0]) - dist.Length()*normal;
|
||||||
|
|
||||||
|
NgArray<int> acttrigs(GetNT());
|
||||||
|
acttrigs = -1;
|
||||||
|
for (int j = 1; j <= chart.GetNT(); j++)
|
||||||
|
acttrigs.Elem(chart.GetTrig1(j)) = chartnumber;
|
||||||
|
|
||||||
|
for (int j = 1; j <= chart.GetNT(); j++)
|
||||||
|
{
|
||||||
|
auto t = chart.GetTrig1(j);
|
||||||
|
const auto & tt = GetTriangle(t);
|
||||||
|
for (int k = 1; k <= 3; k++)
|
||||||
|
{
|
||||||
|
int nt = NeighbourTrig(t,k);
|
||||||
|
if (acttrigs.Get(nt) != chartnumber)
|
||||||
|
{
|
||||||
|
STLPointId np1, np2;
|
||||||
|
tt.GetNeighbourPoints(GetTriangle(nt),np1,np2);
|
||||||
|
|
||||||
|
Point<3> pts[3];
|
||||||
|
pts[0] = GetPoint(np2);
|
||||||
|
pts[1] = GetPoint(np1);
|
||||||
|
pts[2] = extra_point;
|
||||||
|
Vec3d normal = -Cross( pts[2]-pts[0], pts[1]-pts[0] );
|
||||||
|
readtrigs.Append(STLReadTriangle(pts, normal));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
geo.InitSTLGeometry(readtrigs);
|
||||||
|
geo.Save(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class STLGeometryRegister : public GeometryRegister
|
class STLGeometryRegister : public GeometryRegister
|
||||||
|
@ -394,14 +394,14 @@ namespace netgen
|
|||||||
int TrigIsInOC(int tn, int ocn) const;
|
int TrigIsInOC(int tn, int ocn) const;
|
||||||
|
|
||||||
//get chart number of a trig or 0 if unmarked
|
//get chart number of a trig or 0 if unmarked
|
||||||
ChartId GetChartNr(STLTrigId i) const;
|
DLL_HEADER ChartId GetChartNr(STLTrigId i) const;
|
||||||
ChartId GetMarker(STLTrigId i) const { return chartmark[i]; }
|
ChartId GetMarker(STLTrigId i) const { return chartmark[i]; }
|
||||||
void SetMarker(STLTrigId nr, ChartId m);
|
void SetMarker(STLTrigId nr, ChartId m);
|
||||||
size_t GetNOCharts() const { return atlas.Size(); }
|
size_t GetNOCharts() const { return atlas.Size(); }
|
||||||
//get a chart from atlas
|
//get a chart from atlas
|
||||||
const STLChart& GetChart(ChartId nr) const { return *atlas[nr];};
|
const STLChart& GetChart(ChartId nr) const { return *atlas[nr];};
|
||||||
STLChart & GetChart(ChartId nr) { return *atlas[nr];};
|
STLChart & GetChart(ChartId nr) { return *atlas[nr];};
|
||||||
int AtlasMade() const;
|
DLL_HEADER int AtlasMade() const;
|
||||||
|
|
||||||
void GetInnerChartLimes(NgArray<twoint>& limes, ChartId chartnum);
|
void GetInnerChartLimes(NgArray<twoint>& limes, ChartId chartnum);
|
||||||
|
|
||||||
@ -460,6 +460,9 @@ namespace netgen
|
|||||||
int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam) override;
|
int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam) override;
|
||||||
|
|
||||||
virtual const Refinement & GetRefinement () const override;
|
virtual const Refinement & GetRefinement () const override;
|
||||||
|
|
||||||
|
// Add additional Point to chart to close the surface and write the resulting stl to a file
|
||||||
|
DLL_HEADER void WriteChartToFile( ChartId chartnumber, string filename="chart.slb" );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -395,6 +395,16 @@ namespace netgen
|
|||||||
{
|
{
|
||||||
stlgeometry->STLDoctorConfirmedToCandidateEdges();
|
stlgeometry->STLDoctorConfirmedToCandidateEdges();
|
||||||
}
|
}
|
||||||
|
else if (strcmp (argv[1], "writechart") == 0)
|
||||||
|
{
|
||||||
|
int st = stlgeometry->GetSelectTrig();
|
||||||
|
|
||||||
|
if (st >= 1 && st <= stlgeometry->GetNT() && stlgeometry->AtlasMade())
|
||||||
|
{
|
||||||
|
auto chartnumber = stlgeometry->GetChartNr(st);
|
||||||
|
stlgeometry->WriteChartToFile(chartnumber, "chart.stlb");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
|
@ -944,8 +944,14 @@ proc viewingoptionsdialog { } {
|
|||||||
-textvariable stloptions.chartnumberoffset -validate focus -takefocus 0 \
|
-textvariable stloptions.chartnumberoffset -validate focus -takefocus 0 \
|
||||||
-validatecommand "my_validate %W 0 1e9 %P 0" \
|
-validatecommand "my_validate %W 0 1e9 %P 0" \
|
||||||
-invalidcommand "my_invalid %W"
|
-invalidcommand "my_invalid %W"
|
||||||
|
|
||||||
|
ttk::button $f.fn.btn_write_chart -text "Write selected chart to chart.stlb" -command {
|
||||||
|
Ng_STLDoctor writechart
|
||||||
|
}
|
||||||
|
|
||||||
grid $f.fn.lab -sticky ne -padx 4
|
grid $f.fn.lab -sticky ne -padx 4
|
||||||
grid $f.fn.ent -sticky nw -padx 4 -row 1 -column 1
|
grid $f.fn.ent -sticky nw -padx 4 -row 1 -column 1
|
||||||
|
grid $f.fn.btn_write_chart -padx 4 -row 2 -column 1
|
||||||
grid anchor $f.fn center
|
grid anchor $f.fn center
|
||||||
|
|
||||||
ttk::labelframe $f.advstl -text "Advanced STL options" -relief groove -borderwidth 3
|
ttk::labelframe $f.advstl -text "Advanced STL options" -relief groove -borderwidth 3
|
||||||
|
@ -1996,8 +1996,12 @@ const char * ngscript[] = {""
|
|||||||
,"-textvariable stloptions.chartnumberoffset -validate focus -takefocus 0 \\\n"
|
,"-textvariable stloptions.chartnumberoffset -validate focus -takefocus 0 \\\n"
|
||||||
,"-validatecommand \"my_validate %W 0 1e9 %P 0\" \\\n"
|
,"-validatecommand \"my_validate %W 0 1e9 %P 0\" \\\n"
|
||||||
,"-invalidcommand \"my_invalid %W\"\n"
|
,"-invalidcommand \"my_invalid %W\"\n"
|
||||||
|
,"ttk::button $f.fn.btn_write_chart -text \"Write selected chart to chart.stlb\" -command {\n"
|
||||||
|
,"Ng_STLDoctor writechart\n"
|
||||||
|
,"}\n"
|
||||||
,"grid $f.fn.lab -sticky ne -padx 4\n"
|
,"grid $f.fn.lab -sticky ne -padx 4\n"
|
||||||
,"grid $f.fn.ent -sticky nw -padx 4 -row 1 -column 1\n"
|
,"grid $f.fn.ent -sticky nw -padx 4 -row 1 -column 1\n"
|
||||||
|
,"grid $f.fn.btn_write_chart -padx 4 -row 2 -column 1\n"
|
||||||
,"grid anchor $f.fn center\n"
|
,"grid anchor $f.fn center\n"
|
||||||
,"ttk::labelframe $f.advstl -text \"Advanced STL options\" -relief groove -borderwidth 3\n"
|
,"ttk::labelframe $f.advstl -text \"Advanced STL options\" -relief groove -borderwidth 3\n"
|
||||||
,"pack $f.advstl -fill x -pady 15\n"
|
,"pack $f.advstl -fill x -pady 15\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user