using System;
using System.Collections.Generic;
namespace feature_group
{
class FeatureComparer : IComparer<MTKBase_Feature>
{
{
bool anALessThanB = aComparator.
Apply(theA, theB);
if (anALessThanB)
{
return -1;
}
bool aBLessThanA = aComparator.Apply(theB, theA);
if (aBLessThanA)
{
return 1;
}
return 0;
}
}
public struct Pair
{
public Pair(double theFirst, double theSecond)
{
First = theFirst;
Second = theSecond;
}
public double First { get; }
public double Second { get; }
public override string ToString() => $"{First} x {Second}";
}
public struct Dimension
{
public Dimension(double theL, double theW, double theD)
{
L = theL;
W = theW;
D = theD;
}
public double L { get; }
public double W { get; }
public double D { get; }
public override string ToString() => $"{L} x {W} x {D}";
}
public struct Direction
{
public Direction(double theX, double theY, double theZ)
{
X = theX;
Y = theY;
Z = theZ;
}
public double X { get; }
public double Y { get; }
public double Z { get; }
public override string ToString() => $"({FormattedString(X)}, {FormattedString(Y)}, {FormattedString(Z)})";
private string FormattedString(double theValue)
{
System.Globalization.CultureInfo aCI = new System.Globalization.CultureInfo("en-US");
return string.Format(aCI, "{0:0.00}", theValue);
}
}
class FeatureGroupManager
{
public FeatureGroupManager()
{
myGroups = new List<FeatureGroup>();
}
private class FeatureGroup
{
public FeatureGroup(string theName, string theSubgroupName, bool theHasParameters)
{
myName = theName;
mySubgroupName = theSubgroupName;
myHasParameters = theHasParameters;
myFeatureSubgroups = new FeatureMapType(new FeatureComparer());
}
public uint FeatureCount()
{
uint aCount = 0;
foreach (var i in myFeatureSubgroups)
{
aCount += i.Value;
}
return aCount;
}
public string myName;
public string mySubgroupName;
public bool myHasParameters;
public FeatureMapType myFeatureSubgroups;
}
private class FeatureGroupComparer : IComparer<FeatureGroup>
{
public int Compare(FeatureGroup theA, FeatureGroup theB)
{
string anAName = theA.myName;
string aBName = theB.myName;
if (anAName == aBName)
{
return 0;
}
FeatureMapType anAFeatureSubgroups = theA.myFeatureSubgroups;
FeatureMapType aBFeatureSubgroups = theB.myFeatureSubgroups;
if (anAFeatureSubgroups.Count == 0 || aBFeatureSubgroups.Count == 0)
{
return anAName.CompareTo(aBName);
}
foreach (var i in anAFeatureSubgroups)
{
anAFeature = i.Key;
break;
}
foreach (var i in aBFeatureSubgroups)
{
aBFeature = i.Key;
break;
}
FeatureComparer aFeatureComparator = new FeatureComparer();
return aFeatureComparator.Compare(anAFeature, aBFeature);
}
}
private List<FeatureGroup> myGroups;
public void AddFeature(
string theGroupName,
string theSubgroupName,
bool theHasParameters,
MTKBase_Feature theFeature)
{
int aRes = myGroups.FindIndex(theGroup => theGroup.myName == theGroupName);
if (aRes == -1)
{
myGroups.Add(new FeatureGroup(theGroupName, theSubgroupName, theHasParameters));
aRes = myGroups.Count - 1;
}
FeatureGroup aGroup = myGroups[aRes];
FeatureMapType aSubgroups = aGroup.myFeatureSubgroups;
if (aSubgroups.ContainsKey(theFeature))
{
++aSubgroups[theFeature];
}
else
{
aSubgroups[theFeature] = 1;
}
}
public void Print(string theFeatureType, Action<MTKBase_Feature> thePrintFeatureParameters)
{
myGroups.Sort(new FeatureGroupComparer());
uint aTotalCount = 0;
foreach (var i in myGroups)
{
uint aFeatureCount = i.FeatureCount();
aTotalCount += aFeatureCount;
Console.WriteLine($" {i.myName}: {aFeatureCount}");
if (!i.myHasParameters)
{
continue;
}
string aSubgroupName = i.mySubgroupName;
foreach (var j in i.myFeatureSubgroups)
{
Console.WriteLine($" {j.Value} {aSubgroupName} with");
thePrintFeatureParameters(j.Key);
}
}
Console.WriteLine($"\n Total {theFeatureType}: {aTotalCount}\n");
}
public static void PrintFeatureParameter<T>(string theName, T theValue, string theUnits)
{
Console.WriteLine($" {theName}: {theValue} {theUnits}");
}
}
}
Provides possibility to compare MTK based features depending on their type and parameters.
Definition MTKBase_FeatureComparator.cs:21
Describes a base class of MTK based features.
Definition MTKBase_Feature.cs:21
Definition ArrayDouble2.cs:12
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12
using System;
namespace shape_processor
{
{
public override void Apply(
Part thePart)
{
var aBodyVec = thePart.
Bodies();
if (aBodyVec.Count != 0)
{
for (int i = 0; i < aBodyVec.Count; ++i)
{
Body aBody = aBodyVec[i];
foreach (var aShape in aShapeIt)
{
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - solid #{i} has:\n");
ProcessSolid(
Solid.
Cast(aShape));
}
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - shell #{i} has:\n");
ProcessShell(
Shell.
Cast(aShape));
}
}
++myPartIndex;
}
}
}
public abstract void ProcessSolid(
Solid theSolid);
public abstract void ProcessShell(
Shell theShell);
private uint myPartIndex = 0;
}
{
public override void Apply(
Part thePart)
{
var aBodyVec = thePart.Bodies();
if (aBodyVec.Count != 0)
{
for (int i = 0; i < aBodyVec.Count; ++i)
{
Body aBody = aBodyVec[i];
foreach (var aShape in aShapeIt)
{
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - solid #{i} has:\n");
ProcessSolid(
Solid.Cast(aShape));
}
}
++myPartIndex;
}
}
}
public abstract void ProcessSolid(
Solid theSolid);
private uint myPartIndex = 0;
}
}
Provides a base body class.
Definition Body.cs:19
cadex.UTF16String Name()
Returns a name.
Definition ModelElement.cs:67
Element visitor with empty implementation.
Definition ModelElementVoidVisitor.cs:20
Defines a leaf node in the scene graph hierarchy.
Definition Part.cs:23
Iterates over subshapes in a shape.
Definition ShapeIterator.cs:58
Defines a connected set of faces.
Definition Shell.cs:29
Defines a topological solid.
Definition Solid.cs:25
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.cs:17
bool IsEmpty()
Returns true if the string is empty.
Definition UTF16String.cs:96
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Definition AngleUnit.cs:12
ShapeType
Defines shape type.
Definition ShapeType.cs:17
using feature_group;
using shape_processor;
using System;
using System.Collections.Generic;
namespace feature_recognizer
{
class Program
{
static int Main(string[] args)
{
string aKey = MTKLicenseKey.Value();
{
Console.WriteLine("Failed to activate Manufacturing Toolkit license.");
return 1;
}
if (args.Length != 1)
{
Console.WriteLine("Usage: " +
$"{System.Reflection.Assembly.GetExecutingAssembly().Location} <input_file>, where:");
Console.WriteLine($" <input_file> is a name of the file to be read");
Console.WriteLine($"");
return 1;
}
string aSource = args[0];
var aModel =
new Model();
{
Console.WriteLine($"Failed to read the file {aSource}");
return 1;
}
Console.WriteLine($"Model: {aModel.Name()}\n");
var aPartProcessor = new PartProcessor();
aModel.Accept(aVisitor);
return 0;
}
class PartProcessor : SolidProcessor
{
public PartProcessor()
{ }
public override void ProcessSolid(
Solid theSolid)
{
aRecognizerParameters.SetMaxRibThickness(30.0);
aRecognizerParameters.SetMaxRibDraftAngle(0.2);
aRecognizerParameters.SetMaxRibTaperAngle(0.1);
var aFeatureList = aRecognizer.Perform(theSolid);
PrintFeatures(aFeatureList);
}
}
{
FeatureGroupManager aManager = new FeatureGroupManager();
for (uint i = 0; i < theFeatureList.
Size(); i++)
{
{
aManager.AddFeature("Screw Boss(es)", "Screw Boss(es)", true, aScrewBoss);
}
{
aManager.AddFeature("Boss(es)", "Boss(es)", true, aBoss);
}
{
aManager.AddFeature("Rib(s)", "Rib(s)", true, aRib);
}
}
Action<MTKBase_Feature> PrintFeatureParameters = theFeature =>
{
{
FeatureGroupManager.PrintFeatureParameter(
"outer radius", aScrewBoss.
OuterRadius(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"inner radius", aScrewBoss.
InnerRadius(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"draft angle", ToDegrees(aScrewBoss.
DraftAngle()),
"deg");
}
{
FeatureGroupManager.PrintFeatureParameter(
"length", aBoss.
Length(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"height", aBoss.
Height(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"width", aBoss.
Width(),
"mm");
}
{
FeatureGroupManager.PrintFeatureParameter(
"length", aRib.
Length(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"height", aRib.
Height(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"thickness", aRib.
Thickness(),
"mm");
FeatureGroupManager.PrintFeatureParameter(
"draft angle", ToDegrees(aRib.
DraftAngle()),
"deg");
}
};
aManager.Print("features", PrintFeatureParameters);
}
static double ToDegrees(double theAngleRad)
{
return theAngleRad * 180 / Math.PI;
}
}
}
Activates the license key.
Definition LicenseManager.cs:48
Describes a boss. In CNC Machining a boss is a protrusion or raised area on a workpiece that is creat...
Definition MTKBase_Boss.cs:27
double Height()
Definition MTKBase_Boss.cs:111
double Length()
Definition MTKBase_Boss.cs:94
double Width()
Definition MTKBase_Boss.cs:77
static new bool CompareType(cadex.MTKBase_Feature theFeature)
Returnstrue if theFeature is a Boss.
Definition MTKBase_Boss.cs:125
Defines a list of features.
Definition MTKBase_FeatureList.cs:20
uint Size()
Returns the number of elements in the list.
Definition MTKBase_FeatureList.cs:110
cadex.MTKBase_Feature Feature(uint theIndex)
Access specified element.
Definition MTKBase_FeatureList.cs:99
Defines a visitor that visits each unique element only once.
Definition ModelElementUniqueVisitor.cs:25
Provides MTK data model.
Definition Model.cs:30
Reads supported formats, see Import section.
Definition ModelReader.cs:17
Provides an interface to recognizing molding features.
Definition Molding_FeatureRecognizer.cs:21
Defines parameters used by Molding_FeatureRecognizer.
Definition Molding_FeatureRecognizerParameters.cs:17
Describes a rib.
Definition Molding_Rib.cs:39
double DraftAngle()
Definition Molding_Rib.cs:141
double Height()
Definition Molding_Rib.cs:107
static new bool CompareType(cadex.MTKBase_Feature theFeature)
Returns true if theFeature is a Rib.
Definition Molding_Rib.cs:155
double Length()
Definition Molding_Rib.cs:90
double Thickness()
Definition Molding_Rib.cs:124
Describes a screw boss. In injection molding, the Screw Boss is essentially a cylindrical protrusion ...
Definition Molding_ScrewBoss.cs:41
double OuterRadius()
Definition Molding_ScrewBoss.cs:91
static new bool CompareType(cadex.MTKBase_Feature theFeature)
Returns true if theFeature is a molding Screw Boss.
Definition Molding_ScrewBoss.cs:165
double DraftAngle()
Definition Molding_ScrewBoss.cs:134
double InnerRadius()
Definition Molding_ScrewBoss.cs:108