Ejemplo n.º 1
0
        internal static void RunGeometricReasoning(Dictionary <string, List <TessellatedSolid> > solids)
        {
            // Generate a good number of directions on the surface of a sphere
            //------------------------------------------------------------------------------------------
            //SimplifySolids(solids);
            Directions = IcosahedronPro.DirectionGeneration(1);
            DisassemblyDirections.Directions = new List <double[]>(Directions);
            FindingOppositeDirections();
            // Creating Bounding Geometries for every solid
            //------------------------------------------------------------------------------------------
            //Bridge.StatusReporter.ReportStatusMessage("Creating Bounding Geometries ... ", 1);
            BoundingGeometry.OrientedBoundingBoxDic = new Dictionary <TessellatedSolid, BoundingBox>();
            BoundingGeometry.BoundingCylinderDic    = new Dictionary <TessellatedSolid, BoundingCylinder>();
            BoundingGeometry.CreateOBB2(solids);
            BoundingGeometry.CreateBoundingCylinder(solids);
            //Bridge.StatusReporter.PrintMessage("BOUNDING GEOMETRIES ARE SUCCESSFULLY CREATED.", 0.5f);

            // Detecting Springs
            //SpringDetector.DetectSprings(solids);

            // Primitive Classification
            //------------------------------------------------------------------------------------------
            // what parts to be classified?
            var partsForPC = BlockingDetermination.PartsTobeClassifiedIntoPrimitives(solids);

            SolidPrimitive = BlockingDetermination.PrimitiveMaker(partsForPC);
        }
        internal static Dictionary <int, List <Component[]> > NonAdjacentBlocking = new Dictionary <int, List <Component[]> >(); //Component[0] is blocked by Component[1]
        internal static List <int> Run(designGraph assemblyGraph, List <TessellatedSolid> solids)
        {
            Solids     = new List <TessellatedSolid>(solids);
            Directions = IcosahedronPro.DirectionGeneration();
            var globalDirPool  = new List <int>();
            var solidPrimitive = BlockingDetermination.PrimitiveMaker(solids);

            //var gears = BoltAndGearDetection.GearDetector(solidPrimitive);

            AddingNodesToGraph(assemblyGraph, solids);//, gears, screwsAndBolts);

            /*for (var i = 0; i < solids.Count - 1; i++)
             * {
             *  var solid1 = solids[i];
             *  var solid1Primitives = solidPrimitive[solid1];
             *  for (var j = i + 1; j < solids.Count; j++)
             *  {
             *      var solid2 = solids[j];
             *      var solid2Primitives = solidPrimitive[solid2];
             *      List<int> localDirInd;
             *      double cert;
             *      if (BlockingDetermination.DefineBlocking(assemblyGraph, solid1, solid2, solid1Primitives, solid2Primitives,
             *          globalDirPool, out localDirInd, out cert))
             *      {
             *          // I wrote the code in a way that "solid1" is always "Reference" and "solid2" is always "Moving".
             *          //List<int> finDirs, infDirs;
             *          //UnconnectedBlockingDetermination.FiniteDirectionsBetweenConnectedParts(solid1, solid2, localDirInd, out finDirs, out infDirs);
             *          var from = assemblyGraph[solid2.Name]; // Moving
             *          var to = assemblyGraph[solid1.Name];   // Reference
             *          assemblyGraph.addArc((Component)from, (Component)to);
             *          var a = (Connection)assemblyGraph.arcs.Last();
             *          a.Certainty = cert;
             *          AddInformationToArc(a, localDirInd);
             *      }
             *  }
             * }*/
            return(globalDirPool);
        }
Ejemplo n.º 3
0
        internal static void RunPerecptronLearner(bool regenerateTrainingData)
        {
            // this functions, finds the training stls, opens them,
            // read them and creates the csv file of the training data
            // which includes the features of each solid.

            // Here is what I need to pay attention:
            //    1. if the csv file exists and the user doesnt want to improve(!) the results
            //       do nothing
            //    2. if the csv doesnt exist or the user has new training stls, we can run it and
            //       improve the classifier.

            var path =

                                #if NOSRC
                Program.state.inputDir + "src/Assembly Planner/InitialGraphMaker/BoltAndGearDetector";
                                #else
                "bin/training";
                                #endif

            //Path to write the csv to:
                        #if NOSRC
            var trainingDataPath    = path + "/TrainingData.csv";
            var weightsAndVotesPath = path + "/WeightsAndVotes.csv";
                        #else
            var trainingDataPath    = path + "/ClassifierFiles/TrainingData.csv";
            var weightsAndVotesPath = path + "/ClassifierFiles/WeightsAndVotes.csv";
                        #endif

            if (!regenerateTrainingData && File.Exists(weightsAndVotesPath))
            {
                return;
            }
            if (!regenerateTrainingData && !File.Exists(weightsAndVotesPath) && File.Exists(trainingDataPath))
            {
                // CSV of the training data exists, but weights and votes, dont exist, therefore: run the Learner
                Learner(); // this will automatically create the csv containing weights and votes
                return;
            }
            if (!regenerateTrainingData && !File.Exists(weightsAndVotesPath) && !File.Exists(trainingDataPath))
            {
                Console.WriteLine("Sorry!! csv files don't exist. We need to generate the training data");
            }
            //statusReporter.PrintMessage("BOUNDING GEOMETRIES ARE SUCCESSFULLY CREATED.", 1f);
            //Path to read STLs from:

                        #if NOSRC
            var stlFastenerPath    = path + "/Fastener";
            var stlNotFastenerPath = path + "/notFastener";
                        #else
            var stlFastenerPath    = path + "/TrainingSTLs/Fastener";
            var stlNotFastenerPath = path + "/TrainingSTLs/notFastener";
                        #endif

            var fastenersTraining = StlToSolid(stlFastenerPath);
            var fastenerPrimitive = BlockingDetermination.PrimitiveMaker(fastenersTraining);

            var ntFastenersTraining  = StlToSolid(stlNotFastenerPath);
            var notFastenerPrimitive = BlockingDetermination.PrimitiveMaker(ntFastenersTraining);

            if (!File.Exists(trainingDataPath))
            {
                File.Create(trainingDataPath).Close();
            }

            // now fill the csv:
            TrainingDataCsvFiller(trainingDataPath, fastenerPrimitive, notFastenerPrimitive);
            Learner();
        }