public static bool CheckOfCylindersForRotation(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double teta, double[] axisDirection, double[] translationalVector) { var numOfCylinderSurfacesFirst = firstMyRepeatedEntity.listOfCylindricalSurfaces.Count; var numOfCylinderSurfacesSecond = secondMyRepeatedEntity.listOfCylindricalSurfaces.Count; if (numOfCylinderSurfacesFirst == numOfCylinderSurfacesSecond) { if (numOfCylinderSurfacesFirst > 0) { var listOfCylindersToLookIn = new List <MyCylinder>(secondMyRepeatedEntity.listOfCylindricalSurfaces); int i = 0; while (listOfCylindersToLookIn.Count != 0 && i < numOfCylinderSurfacesFirst) { var cylinderOfFirst = firstMyRepeatedEntity.listOfCylindricalSurfaces[i]; if (!CylinderOfFirstAtPosition_i_IsOkRotation(firstMyRepeatedEntity, secondMyRepeatedEntity, teta, axisDirection, translationalVector, cylinderOfFirst, ref i)) { return(false); } } return(true); } return(true); } return(false); }
//(THE FOLLOWING FUNCTION IS CREATED FOR COMPOSED PATTERN SEARCH) //This function is the analogous of IsTranslationTwoRE, but in this situation the candidate //translational vector is given as input. public static bool IsTranslationTwoREGivenCandidateVector(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double[] candidateTranslationArray) { var numberOfVerticesIsOk = true; var checkOfVertices = CheckOfVerticesForTranslation(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateTranslationArray, ref numberOfVerticesIsOk); if (numberOfVerticesIsOk) { if (checkOfVertices == false) { return(false); } } else { return(false); } //Check of correct position of normals of all Planar face: if (!CheckOfPlanesForTranslation(firstMyRepeatedEntity, secondMyRepeatedEntity)) { return(false); } ////Check of correct position of cylinder faces: if (!CheckOfCylindersForTranslation(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateTranslationArray)) { return(false); } //CONTINUARE CON GLI ALTRI TIPI DI SUPERFICI............ return(true); }
public static bool CheckOfCylindersForTranslation(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double[] candidateTranslationArray) { //controllo tutti gli assi per tutti i cilindri //poi per ogni edge di cilindro chiuso controllo i dati della curva var tolerance = Math.Pow(10, -5); var numOfCylinderSurfacesFirst = firstMyRepeatedEntity.listOfCylindricalSurfaces.Count; var numOfCylinderSurfacesSecond = secondMyRepeatedEntity.listOfCylindricalSurfaces.Count; if (numOfCylinderSurfacesFirst == numOfCylinderSurfacesSecond) { if (numOfCylinderSurfacesFirst > 0) { var listOfCylindersToLookIn = new List <MyCylinder>(secondMyRepeatedEntity.listOfCylindricalSurfaces); int i = 0; while (listOfCylindersToLookIn.Count != 0 && i < numOfCylinderSurfacesFirst) { var cylinderOfFirst = firstMyRepeatedEntity.listOfCylindricalSurfaces[i]; if (!CylinderOfFirstAtPosition_i_IsOkTranslation(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateTranslationArray, cylinderOfFirst, tolerance, ref i)) { return(false); } } return(true); } return(true); } return(false); }
public static bool CheckOfCylindersForReflection(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, MyPlane candidateReflMyPlane) { var numOfCylinderSurfacesFirst = firstMyRepeatedEntity.listOfCylindricalSurfaces.Count; var numOfCylinderSurfacesSecond = secondMyRepeatedEntity.listOfCylindricalSurfaces.Count; if (numOfCylinderSurfacesFirst == numOfCylinderSurfacesSecond) { if (numOfCylinderSurfacesFirst > 0) { var listOfCylindersToLookIn = new List <MyCylinder>(secondMyRepeatedEntity.listOfCylindricalSurfaces); int i = 0; while (listOfCylindersToLookIn.Count != 0 && i < numOfCylinderSurfacesFirst) { var cylinderOfFirst = firstMyRepeatedEntity.listOfCylindricalSurfaces[i]; if (!CylinderOfFirstAtPosition_i_IsOkReflection(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateReflMyPlane, cylinderOfFirst, ref i)) { return(false); } } return(true); } return(true); } return(false); }
// SBAGLIATO: VEDI FIGURA TIPO CARAMELLA TIC-TAC CON UNA DELLE DUE SUPERFICI SFERICHE AGLI CONCAVA ANZICHè CONVESSA public static bool CheckOfSpheresForTranslation(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double[] candidateTranslationArray) { var tolerance = Math.Pow(10, -5); var numOfSphereSurfacesFirst = firstMyRepeatedEntity.listOfSphericalSurfaces.Count; var numOfSphereSurfacesSecond = secondMyRepeatedEntity.listOfSphericalSurfaces.Count; if (numOfSphereSurfacesFirst == numOfSphereSurfacesSecond) { if (numOfSphereSurfacesFirst > 0) { var listOfSphereToDelete = new List <MySphere>(secondMyRepeatedEntity.listOfSphericalSurfaces); int i = 0; while (listOfSphereToDelete.Count != 0 && i < numOfSphereSurfacesFirst) // DOVREBBERO ESSERE FALSE O VERE CONTEMPORANEAMENTE!!! { var sphereOfFirst = firstMyRepeatedEntity.listOfSphericalSurfaces[i]; if (sphereOfFirst.centerSphere != null) { double[] expectedPosition = { sphereOfFirst.centerSphere[0] + candidateTranslationArray[0], sphereOfFirst.centerSphere[1] + candidateTranslationArray[1], sphereOfFirst.centerSphere[2] + candidateTranslationArray[2] }; var indexOfFound = listOfSphereToDelete.FindIndex( sphere => FunctionsLC.MyEqualsArray(sphere.centerSphere, expectedPosition)); if (indexOfFound != -1) { if (Math.Abs(listOfSphereToDelete[indexOfFound].radiusSphere - sphereOfFirst.radiusSphere) < tolerance) { listOfSphereToDelete.RemoveAt(indexOfFound); i++; } } else { return(false); } } } return(true); } else { return(true); } } else { return(false); } }
//(THE FOLLOWING FUNCTION IS CREATED FOR COMPOSED PATTERN SEARCH) //This function is the analogous of IsReflectionTwoRE, but in this situation the candidate //reflectional plane is given as input. public static bool IsReflectionTwoREGivenCandidateReflPlane(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, MyPlane candidateReflMyPlane) { //Vertex analysis for Reflection: var firstListOfVertices = firstMyRepeatedEntity.listOfVertices; var firstNumOfVerteces = firstListOfVertices.Count; var secondListOfVertices = secondMyRepeatedEntity.listOfVertices; var secondNumOfVerteces = secondListOfVertices.Count; if (firstNumOfVerteces == secondNumOfVerteces) { int i = 0; while (i < firstNumOfVerteces) { if (secondListOfVertices.FindIndex( vert => vert.IsReflectionOf(firstListOfVertices[i], candidateReflMyPlane)) != -1) { var found = secondListOfVertices.Find( vert => vert.IsReflectionOf(firstListOfVertices[i], candidateReflMyPlane)); var scarto = new MyVertex(Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).x - found.x), Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).y - found.y), Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).z - found.z)); i++; } else { return(false); } } } else { return(false); } //Check of correct position of normals of all Planar face: if (!CheckOfPlanesForReflection(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateReflMyPlane)) { return(false); } ////Check of correct position of cylinder faces: if (!CheckOfCylindersForReflection(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateReflMyPlane)) { return(false); } ////CONTINUARE CON GLI ALTRI TIPI DI SUPERFICI............ //KLdebug.Print(" ====>>> TRASLAZIONE TRA QUESTE DUE re VERIFICATA!", nameFile); return(true); }
//Update list of Pattern geometrically verified of length = 2: delete the ones containing //a RE of the newPatternPoint public static void UpdateListOfPatternTwo(MyRepeatedEntity re, ref List <MyPattern> listOfOutputPatternTwo, int indOfThisCentroid) { var indOfFound = listOfOutputPatternTwo.FindIndex( pattern => pattern.listOfMyREOfMyPattern.FindIndex(reInPattern => reInPattern.idRE == re.idRE) != -1); if (indOfFound != -1) { var found = listOfOutputPatternTwo.Find( pattern => pattern.listOfMyREOfMyPattern.FindIndex(reInPattern => reInPattern.idRE == re.idRE) != -1); listOfOutputPatternTwo.Remove(found); } }
public static MyRepeatedComponent ComputeNewRepeatedComponent(SldWorks swApplication, Component2 component2, int idCorrespondingNode, MyTransformMatrix newRelativeTransformMatrix, int indexRepEntity, bool newIsLeaf) { // Aggiunto calcolo dell'entità ripetuta alla parte. var currentModel = component2.GetModelDoc2(); var entityList = (List <Entity>)AssemblyTraverse.KL_GetPartFaces(currentModel, component2.Name2, swApplication); double[,] compositionMatrixOfComponentPart = new double[4, 4] { { (double)newRelativeTransformMatrix.RotationMatrix[0, 0], (double)newRelativeTransformMatrix.RotationMatrix[0, 1], (double)newRelativeTransformMatrix.RotationMatrix[0, 2], (double)newRelativeTransformMatrix.TranslationVector[0] }, { (double)newRelativeTransformMatrix.RotationMatrix[1, 0], (double)newRelativeTransformMatrix.RotationMatrix[1, 1], (double)newRelativeTransformMatrix.RotationMatrix[1, 2], (double)newRelativeTransformMatrix.TranslationVector[1] }, { (double)newRelativeTransformMatrix.RotationMatrix[2, 0], (double)newRelativeTransformMatrix.RotationMatrix[2, 1], (double)newRelativeTransformMatrix.RotationMatrix[2, 2], (double)newRelativeTransformMatrix.TranslationVector[2] }, { 0.0, 0.0, 0.0, 1 } }; //swApplication.SendMsgToUser("Calcolo repeated entity di " + component2.Name2 + "\nnumero facce " + entityList.Count); MyRepeatedEntity newRepeatedEntity = ExtractInfoFromBRep.KLBuildRepeatedEntity( entityList, indexRepEntity, compositionMatrixOfComponentPart, swApplication); //swApplication.SendMsgToUser("Ha " + newRepeatedEntity.listOfVertices.Count + " vertici\n" + newRepeatedEntity.listOfAddedVertices.Count + " vertici aggiunti"); // Fine calcolo entità rip da aggiungere alla componente. var newMyComponent = new MyRepeatedComponent(component2, idCorrespondingNode, newRelativeTransformMatrix, newIsLeaf, newRepeatedEntity); return(newMyComponent); }
//Update the list of MyGroupingSurface, deleting the MyRepeatedEntity already set in the newPatternPoint public static void UpdateListOfMyGroupingSurface(MyRepeatedEntity re, ref List <MyGroupingSurface> listOfMyGroupingSurface, int indOfThisCentroid) { const string nameFile = "GetTranslationalPatterns.txt"; var indOfFound = listOfMyGroupingSurface.FindIndex( gs => gs.listOfREOfGS.FindIndex(reInGS => reInGS.idRE == re.idRE) != -1); if (indOfFound != -1) { var listOfGroupingSurfaceToUpdate = listOfMyGroupingSurface.FindAll( gs => gs.listOfREOfGS.FindIndex(reInGS => reInGS.idRE == re.idRE) != -1); foreach (var gs in listOfGroupingSurfaceToUpdate) { gs.listOfREOfGS.Remove(re); if (gs.listOfREOfGS.Count < 2) { listOfMyGroupingSurface.Remove(gs); } } } }
public static bool CheckOfVerticesForTranslation(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double[] candidateTranslationArray, ref bool numberOfVerticesIsOk) { const string nameFile = "GetTranslationalPatterns.txt"; var whatToWrite = ""; var firstListOfVertices = firstMyRepeatedEntity.listOfVertices; var firstNumOfVerteces = firstListOfVertices.Count; var secondListOfVertices = secondMyRepeatedEntity.listOfVertices; var secondNumOfVerteces = secondListOfVertices.Count; #region STAMPA DEI VERTICI DELLE DUE RE //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 1^ RE", nameFile); //foreach (var myVert in firstListOfVertices) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", firstListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 2^ RE", nameFile); //foreach (var myVert in secondListOfVertices) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", secondListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); #endregion if (firstNumOfVerteces == secondNumOfVerteces) { //KLdebug.Print(" ", nameFile); //KLdebug.Print("Numero di vertici prima RE: " + firstNumOfVerteces, nameFile); //KLdebug.Print("Numero di vertici seconda RE: " + secondNumOfVerteces, nameFile); //KLdebug.Print("Il numero di vertici corrisponde. Passo alla verifica della corrispondenza per traslazione:", nameFile); //KLdebug.Print(" ", nameFile); int i = 0; var checkIsOk = true; while (i < firstNumOfVerteces && checkIsOk) { var found = secondListOfVertices.Find( vert => vert.IsTranslationOf(firstListOfVertices[i], candidateTranslationArray)); if (found != null) { //whatToWrite = string.Format("Ho trovato che {0}-esimo vertice: ({1}, {2}, {3})", i, firstListOfVertices[i].x, // firstListOfVertices[i].y, firstListOfVertices[i].z); // KLdebug.Print(whatToWrite, nameFile); // whatToWrite = string.Format("ha come suo traslato ({0}, {1}, {2})", found.x, found.y, found.z); // var scarto = // new MyVertex(Math.Abs(firstListOfVertices[i].x + candidateTranslationArray[0] - found.x), // Math.Abs(firstListOfVertices[i].y + candidateTranslationArray[1] - found.y), // Math.Abs(firstListOfVertices[i].z + candidateTranslationArray[2] - found.z)); // whatToWrite = string.Format("scarto: ({0}, {1}, {2})", scarto.x, scarto.y, scarto.z); // KLdebug.Print(whatToWrite, nameFile); // KLdebug.Print(" ", nameFile); i++; } else { //KLdebug.Print("TROVATO VERTICE NON CORRISPONDENTE ALLA CERCATA TRASLAZIONE!", nameFile); //KLdebug.Print(" ", nameFile); checkIsOk = false; } } if (checkIsOk) { return(true); } else { return(false); } } else { //KLdebug.Print("NUMERO DI VERTICI NELLE DUE RE NON CORRISPONDENTE. IMPOSSIBILE EFFETTUARE IL CHECK DEI VERTICI!", nameFile); //KLdebug.Print(" ", nameFile); numberOfVerticesIsOk = false; return(false); } }
public static bool CylinderOfFirstAtPosition_i_IsOkReflection(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, MyPlane candidateReflMyPlane, MyCylinder cylinderOfFirst, ref int i) { const string nameFile = "GetReflectionalPattern.txt"; var tolerance = Math.Pow(10, -5); //I compute the distance vector v between the centroidOfFirst and the Origin of the cylinderOfFirst (which pass through the axis) //The axis of the second MyRepeatedEntity should have the same axis direction and //should pass through the point = centroidOfSecond + v double[] originOfFirst = cylinderOfFirst.originCylinder; var originOfFirstMyVertex = new MyVertex(originOfFirst[0], originOfFirst[1], originOfFirst[2]); var pointOnAxisMyVertex = originOfFirstMyVertex.Reflect(candidateReflMyPlane); double[] pointOnAxis = { pointOnAxisMyVertex.x, pointOnAxisMyVertex.y, pointOnAxisMyVertex.z }; var reflectedDirectionOfAxis = ReflectNormal(cylinderOfFirst.axisDirectionCylinder, candidateReflMyPlane); var axisToFind = FunctionsLC.ConvertPointPlusDirectionInMyLine(pointOnAxis, reflectedDirectionOfAxis); var indOfFound = secondMyRepeatedEntity.listOfCylindricalSurfaces.FindIndex( cyl => cyl.axisCylinder.Equals(axisToFind)); if (indOfFound != -1) { var listOfPossibleCylinders = secondMyRepeatedEntity.listOfCylindricalSurfaces.FindAll( cyl => cyl.axisCylinder.Equals(axisToFind)); var numOfPossibleCylinders = listOfPossibleCylinders.Count; //If I find cylinders with right axis line, I check the radius correspondence, //the center of bases correspondence. //For elliptical bases I make a further control on radius and direction axis. var notFound = true; int j = 0; while (notFound && j < numOfPossibleCylinders) { var possibleCylinder = listOfPossibleCylinders[j]; if (Math.Abs(cylinderOfFirst.radiusCylinder - possibleCylinder.radiusCylinder) < tolerance) { if (CheckOfClosedEdgesCorrespondenceRefl(cylinderOfFirst, possibleCylinder, candidateReflMyPlane)) { notFound = false; } } j++; } if (notFound) { return(false); } //if the previous cylinder is ok, i pass to the next cylinder: i++; } else { return(false); } return(true); }
public static MyRepeatedEntity KLBuildRepeatedEntity(List <Entity> entityList, int idNewRepeatedEntity, double[,] compositionMatrixOfComponentPart, SldWorks swapp) { List <Face2> listOfFacesForRepeatedEntity = new List <Face2>(); List <MyVertex> listOfMyVertexForRepeatedEntity = new List <MyVertex>(); List <MyVertex> listOfMyVertexAddedForRepeatedEntity = new List <MyVertex>(); List <MyVertex> listOfMyVertexOfCurrentFace = new List <MyVertex>(); List <MyVertex> listOfAddedMyVertexOfCurrentFace = new List <MyVertex>(); var listOfMyPlane = new List <MyPlane>(); var listOfMySphere = new List <MySphere>(); var listOfMyCone = new List <MyCone>(); var listOfMyCylinder = new List <MyCylinder>(); var listOfMyTorus = new List <MyTorus>(); //const string fileNameBuildRepeatedEntity = "buildRepeatedEntity.txt"; //string whatToWrite = ""; //whatToWrite = string.Format("Numero di facce : {0}", entityList.Count); // KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); foreach (Entity entity in entityList) { // face storing and classification: var face = (Face2)entity; if (((((Surface)face.GetSurface()).Identity() == (int)swSurfaceTypes_e.PLANE_TYPE)) || ((((Surface)face.GetSurface()).Identity() == (int)swSurfaceTypes_e.CYLINDER_TYPE)) || ((((Surface)face.GetSurface()).Identity() == (int)swSurfaceTypes_e.SPHERE_TYPE))) { listOfFacesForRepeatedEntity.Add(face); KLClassifyFace(entity, ref listOfMyPlane, ref listOfMySphere, ref listOfMyCone, ref listOfMyCylinder, ref listOfMyTorus, compositionMatrixOfComponentPart); // vertex storing and classification (from a current face): listOfMyVertexOfCurrentFace.Clear(); listOfAddedMyVertexOfCurrentFace.Clear(); BRepFunctions.MyGetPointFromFaceEntity(entity, ref listOfMyVertexOfCurrentFace, ref listOfAddedMyVertexOfCurrentFace, swapp); // If in the face itself there are two MyVertex repeated (in listOfMyVertexOfCurrentFace) with // the following foreach instruction they are stored only once. foreach (MyVertex myVert in listOfMyVertexOfCurrentFace) { double[] vertexAffine = { myVert.x, myVert.y, myVert.z, 1 }; var newVertex = Matrix.Multiply(compositionMatrixOfComponentPart, vertexAffine); var vertexToAdd = new MyVertex(newVertex[0], newVertex[1], newVertex[2]); if (!(listOfMyVertexForRepeatedEntity.Contains(vertexToAdd))) { listOfMyVertexForRepeatedEntity.Add(vertexToAdd); //whatToWrite = string.Format("Aggiunto Vertice normale: ({0},{1},{2})", myVert.x, myVert.y, // myVert.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); } } // If in the face itself there are two MyVertex repeated (in listOfAddedMyVertexOfCurrentFace) with //// the following foreach instruction they are stored only once. foreach (MyVertex myVert in listOfAddedMyVertexOfCurrentFace) { double[] vertexAffine = { myVert.x, myVert.y, myVert.z, 1 }; var newVertex = Matrix.Multiply(compositionMatrixOfComponentPart, vertexAffine); var vertexToAdd = new MyVertex(newVertex[0], newVertex[1], newVertex[2]); if (!(listOfMyVertexAddedForRepeatedEntity.Contains(vertexToAdd))) { listOfMyVertexAddedForRepeatedEntity.Add(vertexToAdd); //whatToWrite = string.Format("Aggiunto Vertice su edge curvo chiuso: ({0},{1},{2})", myVert.x, // myVert.y, myVert.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); } } } } // Centroid computation: //KLdebug.Print(" ", fileNameBuildRepeatedEntity); var listOfAllVertices = new List <MyVertex>(); listOfAllVertices.AddRange(listOfMyVertexForRepeatedEntity); listOfAllVertices.AddRange(listOfMyVertexAddedForRepeatedEntity); MyVertex outputCentroid = computeCentroidsOfVertices(listOfAllVertices); // centroid of the vertices //whatToWrite = string.Format("Baricentro ({0},{1},{2})", outputCentroid.x, outputCentroid.y, outputCentroid.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); // Creation of new MyRepeatedEntity: MyRepeatedEntity outputRepeatedEntity = new MyRepeatedEntity(idNewRepeatedEntity, listOfFacesForRepeatedEntity, outputCentroid, listOfMyVertexForRepeatedEntity, listOfMyVertexAddedForRepeatedEntity, listOfMyPlane, listOfMySphere, listOfMyCone, listOfMyCylinder, listOfMyTorus, compositionMatrixOfComponentPart); return(outputRepeatedEntity); }
static void Main(string[] args) { //Console.WriteLine("Starting.."); //var swApp = new SldWorks(); //var swAPIWarnings = 0; //var swAPIErrors = 0; //var importData = (ImportStepData)swApp.GetImportFileData(args[0]); //var swActiveDoc = (ModelDoc2)swApp.LoadFile4(args[0], "r", importData, swAPIErrors); //if (swActiveDoc == null) //{ // Console.WriteLine("swActiveDoc nullo " + swAPIWarnings + " " + swAPIErrors); // return; //} //var swAssemblyDoc = (AssemblyDoc)swActiveDoc; //var SwConfiguration = swActiveDoc.GetActiveConfiguration(); //var rootComponent = (Component2)SwConfiguration.GetRootComponent(); //var fileName = rootComponent.Name2; //Console.WriteLine("Modello attivato " + fileName); //var transforation = // (Array)AssemblyTraverse.KL_GetTransformsOfAssemblyComponents(rootComponent, swApp); //const string fatherName = KLgraph.RootLabel; //var pathComponent = rootComponent.Name2; //var componentName = pathComponent.Split('/').Last(); //var componentPath = rootComponent.GetPathName(); //var id = rootComponent.GetHashCode(); //var childrenNumber = rootComponent.IGetChildrenCount(); //var shape = AssemblyTraverse.KL_GetShapeAssembly(rootComponent, swApp); //var statistic = AssemblyTraverse.KL_GetStatisticAssembly(rootComponent, swApp); //var nodeAssembly = new KLgraph.KLnodeAssembly(id, transforation, fatherName, -1, rootComponent, pathComponent, componentName, componentPath, -1, // childrenNumber, statistic, shape); //Console.WriteLine("Creato il nodo assemblato"); //var vertexList = new List<KLgraph.KLnode>(); //var edgeList = new List<KLgraph.KLedge>(); //vertexList.Add(nodeAssembly); //var listOfMyListOfInstances = new List<MyListOfInstances>(); //AssemblyTraverse.KL_GetGraphOfAssemblyComponents(rootComponent, nodeAssembly, // ref vertexList, edgeList, ref listOfMyListOfInstances, swApp); //var partList = new List<KLgraph.KLnode>(vertexList); //partList.RemoveAll(v => v.GetType() != typeof(KLgraph.KLnodePart)); //nodeAssembly.KLstatistic.PrincipalPartNumber = partList.Count(); //nodeAssembly.Instances.AddRange(listOfMyListOfInstances); List <MyPatternOfComponents> listPattern = new List <MyPatternOfComponents>(); List <MyPatternOfComponents> listPattern2 = new List <MyPatternOfComponents>(); StringBuilder fileOutput = new StringBuilder(); fileOutput.AppendLine("RICERCA PATH"); var compName = "DIN"; var listCentroidWordRF = new List <MyVertex>(); var v1 = new MyVertex(-0.00302203528372547, -0.0657609306477435, 0.0657609306501929); var v2 = new MyVertex(-0.00302203528372547, 0.0930000000026054, 0.0); var v3 = new MyVertex(-0.00302203528372547, 0.0, -0.093000000000156); var v4 = new MyVertex(-0.00302203528372547, -0.0657609306477435, -0.0657609306505048); var v5 = new MyVertex(-0.00302203528372547, -0.0929999999973946, -0.0); var v6 = new MyVertex(-0.00302203528372547, 0.0657609306529544, 0.0657609306501929); var v7 = new MyVertex(-0.00302203528372547, 0.0657609306529543, -0.0657609306505049); var v8 = new MyVertex(-0.00302203528372547, 0.0, 0.0929999999998441); listCentroidWordRF.Add(v1); listCentroidWordRF.Add(v2); listCentroidWordRF.Add(v3); listCentroidWordRF.Add(v4); listCentroidWordRF.Add(v5); listCentroidWordRF.Add(v6); listCentroidWordRF.Add(v7); listCentroidWordRF.Add(v8); var newListOfComponetsNoInfo = new List <MyRepeatedComponent>(); foreach (var comp in listCentroidWordRF) { var newComp = new MyRepeatedComponent(); var newRE = new MyRepeatedEntity(); newRE.centroid = comp; newComp.Origin = comp; newComp.Name = compName; newComp.IdCorrespondingNode = 0; newComp.RepeatedEntity = newRE; newListOfComponetsNoInfo.Add(newComp); } AssemblyPatterns.KLFindPatternsOfComponents(newListOfComponetsNoInfo, listCentroidWordRF, ref listPattern, ref listPattern2, ref fileOutput); //PatternComputationFunctions.GetAssemblyPatternsOfRepeatedElements(listOfMyListOfInstances, nodeAssembly, // out listPattern, out listPattern2); //Console.WriteLine("Istanze trovate " + listOfMyListOfInstances.Count); //foreach (var inst in listOfMyListOfInstances) //{ // Console.WriteLine("Istanza di " + inst.Name + " trovata " + inst.ListOfMyComponent.Count + " volte"); //} Console.WriteLine("Pattern trovati " + listPattern.Count); foreach (var patt in listPattern) { Console.WriteLine("Pattern di tipo " + patt.typeOfMyPattern + " formato da " + patt.listOfMyRCOfMyPattern.First().Name); } //Console.WriteLine("Ending.. nodi " + graph.VertexCount + " e archi " + graph.EdgeCount); /* * var fileName = Path.GetFileNameWithoutExtension(args[0]); * var storageGraph = new KLgraph.Graph(graph.Vertices.ToList(), graph.Edges.ToList()); * * JsonSerializerSettings setting = new JsonSerializerSettings * { * TypeNameHandling = TypeNameHandling.All, * TypeNameAssemblyFormat = FormatterAssemblyStyle.Full * }; * * var directoryOutput = Path.GetDirectoryName(args[1]); * var fileNameOutput = Path.GetFileNameWithoutExtension(args[1]); * //Console.WriteLine(directoryOutput); * //Console.WriteLine(fileNameOutput); * * SaveModel(JsonConvert.SerializeObject(storageGraph, setting), directoryOutput, fileNameOutput + ".json"); * Console.WriteLine("JSON saved!"); */ //swApp.ExitApp(); }
public static bool CylinderOfFirstAtPosition_i_IsOkRotation(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double teta, double[] axisDirection, double[] translationalVector, MyCylinder cylinderOfFirst, ref int i) { const string nameFile = "GetRotationalPatterns.txt"; var tolerance = Math.Pow(10, -5); //The axis of the second MyRepeatedEntity should have the same axis direction and //should pass through the rotated Origin of the cylinderOfFirst double[] originOfFirst = cylinderOfFirst.originCylinder; //var whatToWrite = string.Format("Centroid of first: ({0},{1},{2})", firstMyRepeatedEntity.centroid.x, firstMyRepeatedEntity.centroid.y, firstMyRepeatedEntity.centroid.z); //KLdebug.Print(whatToWrite, nameFile); //whatToWrite = string.Format("Centroid of first: ({0},{1},{2})", secondMyRepeatedEntity.centroid.x, secondMyRepeatedEntity.centroid.y, secondMyRepeatedEntity.centroid.z); //KLdebug.Print(whatToWrite, nameFile); double[] originOfFirstTranslated = { originOfFirst[0] + translationalVector[0], originOfFirst[1] + translationalVector[1], originOfFirst[2] + translationalVector[2] }; var originOfFirstTranslatedMyVertex = new MyVertex(originOfFirstTranslated[0], originOfFirstTranslated[1], originOfFirstTranslated[2]); var pointOnAxisTranslatedMyVertex = originOfFirstTranslatedMyVertex.Rotate(teta, axisDirection); double[] pointOnAxis = { pointOnAxisTranslatedMyVertex.x - translationalVector[0], pointOnAxisTranslatedMyVertex.y - translationalVector[1], pointOnAxisTranslatedMyVertex.z - translationalVector[2] }; //whatToWrite = string.Format("Point on axis: ({0},{1},{2})", pointOnAxis[0], pointOnAxis[1], pointOnAxis[2]); //KLdebug.Print(whatToWrite, nameFile); var firstAxisDirectionMyVertex = new MyVertex(cylinderOfFirst.axisDirectionCylinder[0], cylinderOfFirst.axisDirectionCylinder[1], cylinderOfFirst.axisDirectionCylinder[2]); var rotatedFirstAxisDirectionMyVertex = firstAxisDirectionMyVertex.Rotate(teta, axisDirection); double[] rotatedFirstAxisDirection = { rotatedFirstAxisDirectionMyVertex.x, rotatedFirstAxisDirectionMyVertex.y, rotatedFirstAxisDirectionMyVertex.z }; var axisToFind = FunctionsLC.ConvertPointPlusDirectionInMyLine(pointOnAxis, rotatedFirstAxisDirection); var indOfFound = secondMyRepeatedEntity.listOfCylindricalSurfaces.FindIndex( cyl => cyl.axisCylinder.Equals(axisToFind)); if (indOfFound != -1) { var listOfPossibleCylinders = secondMyRepeatedEntity.listOfCylindricalSurfaces.FindAll( cyl => cyl.axisCylinder.Equals(axisToFind)); var numOfPossibleCylinders = listOfPossibleCylinders.Count; //If I find cylinders with right axis line, I check the radius correspondence, //the center of bases correspondence. //For elliptical bases I make a further control on radius and direction axis. var notFound = true; int j = 0; while (notFound && j < numOfPossibleCylinders) { var possibleCylinder = listOfPossibleCylinders[j]; if (Math.Abs(cylinderOfFirst.radiusCylinder - possibleCylinder.radiusCylinder) < tolerance) { if (CheckOfClosedEdgesCorrespondenceRot(cylinderOfFirst, possibleCylinder, teta, axisDirection, translationalVector)) { notFound = false; } } j++; } if (notFound) { return(false); } //if the previous cylinder is ok, i pass to the next cylinder: i++; } else { return(false); } return(true); }
// This function takes - the List<object> corresponding to the set of faces of a new RE // . - the progression number of the new RE in the list of selected entities // It returns a new MyRepeatedEntity public static MyRepeatedEntity BuildRepeatedEntity(List <object> setOfFaces, int idNewRepeatedEntity, SldWorks swapp) { List <Face2> listOfFacesForRepeatedEntity = new List <Face2>(); List <MyVertex> listOfMyVertexForRepeatedEntity = new List <MyVertex>(); List <MyVertex> listOfMyVertexAddedForRepeatedEntity = new List <MyVertex>(); List <MyVertex> listOfMyVertexOfCurrentFace = new List <MyVertex>(); List <MyVertex> listOfAddedMyVertexOfCurrentFace = new List <MyVertex>(); var listOfMyPlane = new List <MyPlane>(); var listOfMySphere = new List <MySphere>(); var listOfMyCone = new List <MyCone>(); var listOfMyCylinder = new List <MyCylinder>(); var listOfMyTorus = new List <MyTorus>(); //const string fileNameBuildRepeatedEntity = "buildRepeatedEntity.txt"; //string whatToWrite = ""; //whatToWrite = string.Format("Numero di facce : {0}", setOfFaces.Count); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); foreach (object obj in setOfFaces) { // face storing and classification: var face = (Face2)obj; listOfFacesForRepeatedEntity.Add(face); ClassifyFace(face, ref listOfMyPlane, ref listOfMySphere, ref listOfMyCone, ref listOfMyCylinder, ref listOfMyTorus); // vertex storing and classification (from a current face): listOfMyVertexOfCurrentFace.Clear(); listOfAddedMyVertexOfCurrentFace.Clear(); // FunctionsKL.BRepFunctions.MyGetPointFromFaceEntity(face, ref listOfMyVertexOfCurrentFace, ref listOfAddedMyVertexOfCurrentFace); // If in the face itself there are two MyVertex repeated (in listOfMyVertexOfCurrentFace) with // the following foreach instruction they are stored only once. foreach (MyVertex myVert in listOfMyVertexOfCurrentFace) { if (!(listOfMyVertexForRepeatedEntity.Contains(myVert))) { listOfMyVertexForRepeatedEntity.Add(myVert); //whatToWrite = string.Format("Aggiunto Vertice normale: ({0},{1},{2})", myVert.x, myVert.y, myVert.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); } } // If in the face itself there are two MyVertex repeated (in listOfAddedMyVertexOfCurrentFace) with // the following foreach instruction they are stored only once. foreach (MyVertex myVert in listOfAddedMyVertexOfCurrentFace) { if (!(listOfMyVertexAddedForRepeatedEntity.Contains(myVert))) { listOfMyVertexAddedForRepeatedEntity.Add(myVert); //whatToWrite = string.Format("Aggiunto Vertice su edge curvo chiuso: ({0},{1},{2})", myVert.x, myVert.y, myVert.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); } } } // Centroid computation: //KLdebug.Print(" ", fileNameBuildRepeatedEntity); var listOfAllVertices = new List <MyVertex>(); listOfAllVertices.AddRange(listOfMyVertexForRepeatedEntity); listOfAllVertices.AddRange(listOfMyVertexAddedForRepeatedEntity); MyVertex outputCentroid = computeCentroidsOfVertices(listOfAllVertices); // centroid of the vertices //whatToWrite = string.Format("Baricentro ({0},{1},{2})", outputCentroid.x, outputCentroid.y, outputCentroid.z); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); // Creation of new MyRepeatedEntity: MyRepeatedEntity outputRepeatedEntity = new MyRepeatedEntity(idNewRepeatedEntity, listOfFacesForRepeatedEntity, outputCentroid, listOfMyVertexForRepeatedEntity, listOfMyVertexAddedForRepeatedEntity, listOfMyPlane, listOfMySphere, listOfMyCone, listOfMyCylinder, listOfMyTorus); return(outputRepeatedEntity); }
public static bool CheckOfPlanesForRotation(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double teta, double[] axisDirection) { //const string nameFile = "GetRotationalPatterns.txt"; //KLdebug.Print(" ", nameFile); //KLdebug.Print("------>> CHECK DELLE NORMALI DELLE FACCE PLANARI:", nameFile); //var whatToWrite = ""; var numOfPlanarSurfacesFirst = firstMyRepeatedEntity.listOfPlanarSurfaces.Count; var numOfPlanarSurfacesSecond = secondMyRepeatedEntity.listOfPlanarSurfaces.Count; if (numOfPlanarSurfacesFirst == numOfPlanarSurfacesSecond) { //KLdebug.Print("Numero di facce planari prima RE: " + numOfPlanarSurfacesFirst, nameFile); //KLdebug.Print("Numero di facce planari seconda RE: " + numOfPlanarSurfacesSecond, nameFile); //KLdebug.Print("Il numero di facce planari corrisponde, passo alla verifica delle normali:", nameFile); //KLdebug.Print(" ", nameFile); //If there are planar faces I check the correct position of the normals if (numOfPlanarSurfacesFirst > 0) { var listOfFirstNormals = new List <MyVertex>(); var listOfSecondNormals = new List <MyVertex>(); //KLdebug.Print("Lista delle normali delle facce planari 1^ RE:", nameFile); foreach (var planarSurface in firstMyRepeatedEntity.listOfPlanarSurfaces) { var normalToAdd = new MyVertex(planarSurface.a, planarSurface.b, planarSurface.c); listOfFirstNormals.Add(normalToAdd); //whatToWrite = string.Format("-aggiunta ({0},{1},{2})", normalToAdd.x, normalToAdd.y, normalToAdd.z); //KLdebug.Print(whatToWrite, nameFile); } //KLdebug.Print(" ", nameFile); //KLdebug.Print("Lista delle normali delle facce planari 2^ RE:", nameFile); foreach (var planarSurface in secondMyRepeatedEntity.listOfPlanarSurfaces) { var normalToAdd = new MyVertex(planarSurface.a, planarSurface.b, planarSurface.c); listOfSecondNormals.Add(normalToAdd); //whatToWrite = string.Format("-aggiunta ({0},{1},{2})", normalToAdd.x, normalToAdd.y, normalToAdd.z); //KLdebug.Print(whatToWrite, nameFile); } //KLdebug.Print(" ", nameFile); //KLdebug.Print("Inizio della verifica della corrispondenza delle normali", nameFile); int i = 0; while (listOfSecondNormals.Count != 0 && i < numOfPlanarSurfacesFirst) // DOVREBBERO ESSERE FALSE O VERE CONTEMPORANEAMENTE!!! { //KLdebug.Print(i + "-esima normale della 1^RE:", nameFile); var rotatedNormal = listOfFirstNormals[i].Rotate(teta, axisDirection); var indexOfFound = listOfSecondNormals.FindIndex(normal => normal.Equals(rotatedNormal)); if (indexOfFound != -1) { //whatToWrite = string.Format("Analizzo la normale: ({0},{1},{2})", listOfFirstNormals[i].x, listOfFirstNormals[i].y, listOfFirstNormals[i].z); //KLdebug.Print(whatToWrite, nameFile); //KLdebug.Print(" -> Trovata corrispondenza con una faccia planare della 2^ RE: in posizione " + indexOfFound, nameFile); listOfSecondNormals.RemoveAt(indexOfFound); i++; } else { //KLdebug.Print(" -> Non è stata trovata corrispondenza con le normali della 2^ RE.", nameFile); //KLdebug.Print("FINE", nameFile); return(false); } // KLdebug.Print(" ", nameFile); } // KLdebug.Print(" ", nameFile); return(true); } else { //KLdebug.Print("NESSUNA FACCIA PLANARE.", nameFile); //KLdebug.Print("FINE", nameFile); return(true); } } else { // KLdebug.Print("NUMERO DI FACCE PLANARI NON CORRISPONDENTE", nameFile); // KLdebug.Print("FINE", nameFile); return(false); } }
public static bool CylinderOfFirstAtPosition_i_IsOkTranslation(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double[] candidateTranslationArray, MyCylinder cylinderOfFirst, double tolerance, ref int i) { const string nameFile = "GetTranslationalPatterns.txt"; //I compute the distance vector v between the centroidOfFirst and the Origin of the cylinderOfFirst (which pass through the axis) //The axis of the second MyRepeatedEntity should have the same axis direction and //should pass through the point = centroidOfSecond + v double[] originOfFirst = cylinderOfFirst.originCylinder; double[] centroidOfFirst = { firstMyRepeatedEntity.centroid.x, firstMyRepeatedEntity.centroid.y, firstMyRepeatedEntity.centroid.z }; // if centroid and origin of the cylinder are coinciding, I find another point on the cylinder axis to substitute the origin: if (FunctionsLC.MyEqualsArray(originOfFirst, centroidOfFirst)) { originOfFirst[0] = originOfFirst[0] + cylinderOfFirst.axisDirectionCylinder[0]; originOfFirst[1] = originOfFirst[1] + cylinderOfFirst.axisDirectionCylinder[1]; originOfFirst[2] = originOfFirst[2] + cylinderOfFirst.axisDirectionCylinder[2]; } double[] vectorToFindPointOnAxis = { originOfFirst[0] - centroidOfFirst[0], originOfFirst[1] - centroidOfFirst[1], originOfFirst[2] - centroidOfFirst[2] }; double[] centroidOfSecond = { secondMyRepeatedEntity.centroid.x, secondMyRepeatedEntity.centroid.y, secondMyRepeatedEntity.centroid.z }; double[] pointOnAxis = { centroidOfSecond[0] + vectorToFindPointOnAxis[0], centroidOfSecond[1] + vectorToFindPointOnAxis[1], centroidOfSecond[2] + vectorToFindPointOnAxis[2] }; var axisToFind = FunctionsLC.ConvertPointPlusDirectionInMyLine(pointOnAxis, cylinderOfFirst.axisDirectionCylinder); var listOfPossibleCylinders = secondMyRepeatedEntity.listOfCylindricalSurfaces.FindAll( cyl => cyl.axisCylinder.Equals(axisToFind)); if (listOfPossibleCylinders.Any()) { var numOfPossibleCylinders = listOfPossibleCylinders.Count; //If I find cylinders with right axis line, I check the radius correspondence, //the center of bases correspondence. //For elliptical bases I make a further control on radius axis. var notFound = true; int j = 0; while (notFound && j < numOfPossibleCylinders) { var possibleCylinder = listOfPossibleCylinders[j]; if (Math.Abs(cylinderOfFirst.radiusCylinder - possibleCylinder.radiusCylinder) < tolerance) { if (CheckOfClosedEdgesCorrespondenceTransl(cylinderOfFirst, possibleCylinder, candidateTranslationArray)) { notFound = false; } } j++; } if (notFound) { return(false); } //if the previous cylinder is ok, i pass to the next cylinder: i++; } else { return(false); } return(true); }
//It verifies if a symmetry ROTATIONAL relation between two MyRepeatedEntity exists //public static bool IsRotationTwoRE(MyRepeatedEntity firstMyRepeatedEntity, // MyRepeatedEntity secondMyRepeatedEntity, MyVertex circumCenter, double teta, double[] axisDirection) public static bool IsRotationTwoRE(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, double teta, double[] axisDirection, MyVertex circumCenter) { //const string nameFile = "GetRotationalPatterns.txt"; //KLdebug.Print(" ", nameFile); //var whatToWrite = ""; var firstListOfVertices = firstMyRepeatedEntity.listOfVertices; var firstNumOfVerteces = firstListOfVertices.Count; var secondListOfVertices = secondMyRepeatedEntity.listOfVertices; var secondNumOfVerteces = secondListOfVertices.Count; #region STAMPA DEI VERTICI DELLE DUE RE //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 1^ RE", nameFile); //foreach (var myVert in firstListOfVertices) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", firstListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 2^ RE", nameFile); //foreach (var myVert in secondListOfVertices) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", secondListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); #endregion if (firstNumOfVerteces == secondNumOfVerteces) { // I use the rotation matrix relative to a rotation around an axis passing through the origin. // For this reason I need to translate the vertices coherently to the translated axis //I consider an arbitrary point ON the candidate rotationAxis and I translate it to the origin. //I choose the center of the circumference path. //Then, I translate all the vertices to compare by the same translational vector. //KLdebug.Print(" ", nameFile); //KLdebug.Print("Numero di vertici prima RE: " + firstNumOfVerteces, nameFile); //KLdebug.Print("Numero di vertici seconda RE: " + secondNumOfVerteces, nameFile); //KLdebug.Print( // "Il numero di vertici corrisponde. Li traslo tutti:", // nameFile); //KLdebug.Print(" ", nameFile); double[] translationalVector = { -circumCenter.x, -circumCenter.y, -circumCenter.z }; var firstListOfVerticesTransl = translateListOfVertices(firstListOfVertices, translationalVector); var secondListOfVerticesTransl = translateListOfVertices(secondListOfVertices, translationalVector); #region STAMPA DEI VERTICI DELLE DUE RE TRASLATI //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 1^ RE TRASLATI ", nameFile); //foreach (var myVert in firstListOfVerticesTransl) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", firstListOfVerticesTransl.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 2^ RE TRASLATI", nameFile); //foreach (var myVert in secondListOfVerticesTransl) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", secondListOfVerticesTransl.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); #endregion int i = 0; while (i < firstNumOfVerteces) { if (secondListOfVerticesTransl.FindIndex( vert => vert.IsRotationOf(firstListOfVerticesTransl[i], teta, axisDirection)) != -1) { var found = secondListOfVerticesTransl.Find( vert => vert.IsRotationOf(firstListOfVerticesTransl[i], teta, axisDirection)); //whatToWrite = string.Format("Ho trovato che {0}-esimo vertice: ({1}, {2}, {3})", i, // firstListOfVerticesTransl[i].x, // firstListOfVerticesTransl[i].y, firstListOfVerticesTransl[i].z); //KLdebug.Print(whatToWrite, nameFile); //whatToWrite = string.Format("ha come suo ruotato ({0}, {1}, {2})", found.x, found.y, found.z); //KLdebug.Print(whatToWrite, nameFile); var scarto = new MyVertex(Math.Abs(firstListOfVerticesTransl[i].Rotate(teta, axisDirection).x - found.x), Math.Abs(firstListOfVerticesTransl[i].Rotate(teta, axisDirection).y - found.y), Math.Abs(firstListOfVerticesTransl[i].Rotate(teta, axisDirection).z - found.z)); //whatToWrite = string.Format("scarto: ({0}, {1}, {2})", scarto.x, scarto.y, scarto.z); //KLdebug.Print(whatToWrite, nameFile); //KLdebug.Print(" ", nameFile); i++; } else { // KLdebug.Print("TROVATO VERTICE NON CORRISPONDENTE ALLA CERCATA ROTAZIONE!", nameFile); // KLdebug.Print(" ", nameFile); return(false); } } //KLdebug.Print(" ANDATO A BUON FINE IL CHECK DEI VERTICI: PASSO AL CHECK DELLE FACCE.", nameFile); //KLdebug.Print(" ", nameFile); //Check of correct position of normals of all Planar face: if (!CheckOfPlanesForRotation(firstMyRepeatedEntity, secondMyRepeatedEntity, teta, axisDirection)) { return(false); } //KLdebug.Print(" ANDATO A BUON FINE IL CHECK DELLE NORMALI: PASSO AL CHECK DELLE FACCE CILINDRICHE.", nameFile); //Check of correct position of Cylindrical faces: if ( !CheckOfCylindersForRotation(firstMyRepeatedEntity, secondMyRepeatedEntity, teta, axisDirection, translationalVector)) { return(false); } //KLdebug.Print(" ANDATO A BUON FINE IL CHECK DELLE FACCE CILINDRICHE.", nameFile); ////CONTINUARE CON GLI ALTRI TIPI DI SUPERFICI............ // KLdebug.Print(" ====>>> ROTAZIONE TRA QUESTE DUE re VERIFICATA!", nameFile); return(true); } //KLdebug.Print( // "NUMERO DI VERTICI NELLE DUE RE NON CORRISPONDENTE. IMPOSSIBILE EFFETTUARE IL CHECK DEI VERTICI!", // nameFile); //KLdebug.Print(" ", nameFile); return(false); }
// The function takes as input - a MyRepeatedEntity //. - the list of MyGroupingSurface to update (ref) //It updates the list of MyGroupingSurface, adding the new MyGroupingSurface-s resulting //from the current MyRepeatedEntity public static void GetSurfacesOfFacesAdjacentToSetOfFaces(MyRepeatedEntity newRepeatedEntity, ref List <MyGroupingSurface> listOfGroupingSurfaces, SldWorks SwApplication) { const string fileNameBuildRepeatedEntity = "buildRepeatedEntity.txt"; var whatToWrite = ""; var inputSetOfFaces = newRepeatedEntity.listOfFaces; List <Surface> listOfSurfacesAdjacentToAFace = new List <Surface>(); List <Face2> listOfOtherFaces = new List <Face2>(inputSetOfFaces); foreach (Face2 face in inputSetOfFaces) { listOfSurfacesAdjacentToAFace.Clear(); listOfOtherFaces.Remove(face); listOfSurfacesAdjacentToAFace = GetSurfacesOfFacesAdjacentToFace(face, listOfOtherFaces, SwApplication); var index = 0; var indexbis = 0; foreach (Surface surface in listOfSurfacesAdjacentToAFace) { //SwApplication.SendMsgToUser("Ci sono superfici: " + listOfSurfacesAdjacentToAFace.Count); //Find if there already exists this MyGroupingSurface: var indexOfFound = listOfGroupingSurfaces.FindIndex( myGroupingSurface => MyEqualsSurface(myGroupingSurface.groupingSurface, surface, SwApplication)); if (indexOfFound == -1) { //If it does not, create a new MyGroupingSurface: var newListOfRepeatedEntityOfGroupingSurface = new List <MyRepeatedEntity>(); newListOfRepeatedEntityOfGroupingSurface.Add(newRepeatedEntity); //var newListOfIdOfRepeatedEntityOfGroupingSurface = new List<int>(); //newListOfIdOfRepeatedEntityOfGroupingSurface.Add(idOfNewRepeatedEntity); var newMyGroupingSurface = new MyGroupingSurface(surface, newListOfRepeatedEntityOfGroupingSurface); listOfGroupingSurfaces.Add(newMyGroupingSurface); index++; } else { //If it does, update the corresponding MyGroupingSurface if the current RE is not in the set yet: var myGroupingSurfaceOfFound = listOfGroupingSurfaces[indexOfFound]; if ( myGroupingSurfaceOfFound.listOfREOfGS.FindIndex(re => re.idRE == newRepeatedEntity.idRE) == -1) { myGroupingSurfaceOfFound.listOfREOfGS.Add(newRepeatedEntity); //myGroupingSurfaceOfFound.listOfIdOfRE.Add(idOfNewRepeatedEntity); indexbis++; } } } listOfOtherFaces.Add(face); } }
//It verifies if a symmetry TRANSLATIONAL relation of translational vector between two MyRepeatedEntity public static bool IsTranslationTwoRE(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity) { //const string nameFile = "GetTranslationalPatterns.txt"; //KLdebug.Print(" ", nameFile); //var whatToWrite = ""; double[] candidateTranslationArray = { secondMyRepeatedEntity.centroid.x - firstMyRepeatedEntity.centroid.x, secondMyRepeatedEntity.centroid.y - firstMyRepeatedEntity.centroid.y, secondMyRepeatedEntity.centroid.z - firstMyRepeatedEntity.centroid.z, }; //whatToWrite = string.Format("Candidate translational array: ({0}, {1}, {2})", candidateTranslationArray[0], // candidateTranslationArray[1], candidateTranslationArray[2]); //KLdebug.Print(whatToWrite, nameFile); #region levato per il momento //var firstListOfVertices = firstMyRepeatedEntity.listOfVertices; //var firstNumOfVerteces = firstListOfVertices.Count; //var secondListOfVertices = secondMyRepeatedEntity.listOfVertices; //var secondNumOfVerteces = secondListOfVertices.Count; //#region STAMPA DEI VERTICI DELLE DUE RE //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 1^ RE", nameFile); //foreach (var myVert in firstListOfVertices) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", firstListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 2^ RE", nameFile); //foreach (var myVert in secondListOfVertices) //{ // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", secondListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); //#endregion //if (firstNumOfVerteces == secondNumOfVerteces) //{ // KLdebug.Print(" ", nameFile); // KLdebug.Print("Numero di vertici prima RE: " + firstNumOfVerteces, nameFile); // KLdebug.Print("Numero di vertici seconda RE: " + secondNumOfVerteces, nameFile); // KLdebug.Print("Il numero di vertici corrisponde. Passo alla verifica della corrispondenza per traslazione:", nameFile); // KLdebug.Print(" ", nameFile); // int i = 0; // while (i < firstNumOfVerteces) // { // if (secondListOfVertices.FindIndex( // vert => vert.IsTranslationOf(firstListOfVertices[i], candidateTranslationArray)) != -1) // { // var found = // secondListOfVertices.Find( // vert => vert.IsTranslationOf(firstListOfVertices[i], candidateTranslationArray)); // whatToWrite = string.Format("Ho trovato che {0}-esimo vertice: ({1}, {2}, {3})", i, firstListOfVertices[i].x, // firstListOfVertices[i].y, firstListOfVertices[i].z); // KLdebug.Print(whatToWrite, nameFile); // whatToWrite = string.Format("ha come suo traslato ({0}, {1}, {2})", found.x, found.y, found.z); // var scarto = // new MyVertex(Math.Abs(firstListOfVertices[i].x + candidateTranslationArray[0] - found.x), // Math.Abs(firstListOfVertices[i].y + candidateTranslationArray[1] - found.y), // Math.Abs(firstListOfVertices[i].z + candidateTranslationArray[2] - found.z)); // whatToWrite = string.Format("scarto: ({0}, {1}, {2})", scarto.x, scarto.y, scarto.z); // KLdebug.Print(whatToWrite, nameFile); // KLdebug.Print(" ", nameFile); // i++; // } // else // { // KLdebug.Print("TROVATO VERTICE NON CORRISPONDENTE ALLA CERCATA TRASLAZIONE!", nameFile); // KLdebug.Print(" ", nameFile); // return false; // } // } //} //else //{ // KLdebug.Print("NUMERO DI VERTICI NELLE DUE RE NON CORRISPONDENTE. IMPOSSIBILE EFFETTUARE IL CHECK DEI VERTICI!", nameFile); // KLdebug.Print(" ", nameFile); // return false; //} #endregion var numberOfVerticesIsOk = true; var checkOfVertices = CheckOfVerticesForTranslation(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateTranslationArray, ref numberOfVerticesIsOk); if (numberOfVerticesIsOk) { if (checkOfVertices == false) { return(false); } } else { return(false); } //KLdebug.Print(" ANDATO A BUON FINE IL CHECK DEI VERTICI: PASSO AL CHECK DELLE FACCE.", nameFile); //KLdebug.Print(" ", nameFile); //Check of correct position of normals of all Planar face: if (!CheckOfPlanesForTranslation(firstMyRepeatedEntity, secondMyRepeatedEntity)) { return(false); } //////Check of correct position of cylinder faces: //if (!CheckOfCylindersForTranslation(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateTranslationArray)) //{ // return false; //} //CONTINUARE CON GLI ALTRI TIPI DI SUPERFICI............ //KLdebug.Print(" ====>>> TRASLAZIONE TRA QUESTE DUE re VERIFICATA!", nameFile); return(true); }
/****************************************************************************************************/ /* Parte aggiunta per permettere il riconoscimento di ripetizioni con la stessa origine (Katia) */ /****************************************************************************************************/ public static void GetRepeatedEntities(List <List <object> > RepeatedEntities, bool EntirePart, List <MyGroupingSurface> listOfInitialGroupingSurface, SldWorks swApp) { const string fileNameBuildRepeatedEntity = "buildRepeatedEntity.txt"; string whatToWrite = ""; var listOfMyRepeatedEntity = new List <MyRepeatedEntity>(); var listOfGroupingSurfaces = new List <MyGroupingSurface>(); if (!EntirePart) { foreach (List <object> selectedEntities in RepeatedEntities) { //whatToWrite = string.Format("NEW SELECTED ENTITY: "); //KLdebug.Print(whatToWrite, fileNameBuildRepeatedEntity); var idNewRepeatedEntity = RepeatedEntities.IndexOf(selectedEntities); MyRepeatedEntity newRepeatedEntity = ExtractInfoFromBRep.BuildRepeatedEntity( selectedEntities, idNewRepeatedEntity, swApp); ExtractInfoFromBRep.GetSurfacesOfFacesAdjacentToSetOfFaces( newRepeatedEntity, ref listOfGroupingSurfaces, swApp); //GeometryAnalysis.AddFacesInformationToMyRE(newRepeatedEntity, SwApplication); listOfMyRepeatedEntity.Add(newRepeatedEntity); } } else { /* * // Parte aggiunta da Katia per il conto delle parti ripetute. * if (RepeatedEntities.Count >= 3) * { * foreach (var entity in RepeatedEntities) * { * var faceEntity = new List<Face2>(); * foreach (var obj in entity) * { * var face = (Face2)obj; * faceEntity.Add(face); * } * * //var colorParam = 1 / (RepeatedEntities.IndexOf(entity) + 0.01); * //ColorFace.KLColorFace(faceEntity, swApp, colorParam); * * MyRepeatedEntity repeatedEntity = ExtractInfoFromBRep.BuildRepeatedEntity( * entity, RepeatedEntities.IndexOf(entity)); * listOfMyRepeatedEntity.Add(repeatedEntity); * * //var print = string.Format("Baricentro calcolato per entità {0}: {1}, {2}, {3}", RepeatedEntities.IndexOf(entity), repeatedEntity1.centroid.x, * // repeatedEntity1.centroid.y, repeatedEntity1.centroid.z); * //swApp.SendMsgToUser(print); * } * var firstCentroid = listOfMyRepeatedEntity[0].centroid; * var secondCentroid = listOfMyRepeatedEntity[1].centroid; * var thirdCentroid = listOfMyRepeatedEntity[2].centroid; * * var groupingPlane = FunctionsLC.PlanePassingThrough(firstCentroid, secondCentroid, thirdCentroid); * var groupingSurface = new MyGroupingSurface(groupingPlane, listOfMyRepeatedEntity); * listOfGroupingSurfaces.Add(groupingSurface); * * string whatToWritekl = * string.Format( * "Numero delle grouping surface create da katia: {0} \nnumero entità ripetute: {1}", * listOfGroupingSurfaces.Count, RepeatedEntities.Count); * KLdebug.Print(whatToWritekl, fileNameBuildRepeatedEntity); * KLdebug.Print(" ", fileNameBuildRepeatedEntity); * * } * */ } listOfInitialGroupingSurface = listOfGroupingSurfaces; //SwModel = (ModelDoc2)SwApplication.ActiveDoc; //SwModel.ClearSelection2(true); //SwModel.Insert3DSketch(); //foreach (var re in listOfMyRepeatedEntity) //{ // SwModel.CreatePoint2(re.centroid.x, re.centroid.y, re.centroid.z); //} //SwModel.InsertSketch(); #region stampa delle MyGroupingSurface trovate nelle varie MyRepeatedEntity //KLdebug.Print(" ", fileNameBuildRepeatedEntity); //KLdebug.Print(" ", fileNameBuildRepeatedEntity); //KLdebug.Print("LISTA DELLE GROUPING SURFACE TROVATE:", fileNameBuildRepeatedEntity); //string whatToWrite1 = string.Format("Numero delle grouping surface trovate: " + listOfGroupingSurfaces.Count); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //KLdebug.Print(" ", fileNameBuildRepeatedEntity); foreach (var myGroupingSurface in listOfGroupingSurfaces) { MyPlane firstPlane1; if (!myGroupingSurface.EntirePartAsRE) { var thisSurface = myGroupingSurface.groupingSurface; var firstPlaneParameters1 = thisSurface.PlaneParams; double[] firstPlanePoint1 = { firstPlaneParameters1[3], firstPlaneParameters1[4], firstPlaneParameters1[5] }; double[] firstPlaneNormal1 = { firstPlaneParameters1[0], firstPlaneParameters1[1], firstPlaneParameters1[2] }; // QUAL ERA PIù IL PROBLEMA DELLE NORMALI DELLE FACCE?????? // Forse vanno aggiustate le normali come ho fatto per le superfici prese da altre facce! // (vedi esempio quaderno, da' normale sbagliata di una dell superfici trovate) firstPlane1 = new MyPlane(firstPlaneNormal1, firstPlanePoint1); } else { firstPlane1 = new MyPlane(myGroupingSurface.KLplanareSurface.a, myGroupingSurface.KLplanareSurface.b, myGroupingSurface.KLplanareSurface.c, myGroupingSurface.KLplanareSurface.d); } //KLdebug.Print("Superficie:", fileNameBuildRepeatedEntity); //whatToWrite1 = string.Format("a {0}, b {1}, c {2}, d {3}", firstPlane1.a, firstPlane1.b, firstPlane1.c, // firstPlane1.d); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //whatToWrite1 = // string.Format("Numero di MyRepeatedEntity adiacenti: " + myGroupingSurface.listOfREOfGS.Count); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //KLdebug.Print(" ", "buildRepeatedEntity.txt"); } #endregion //I remove all the MyGroupingSurface with only one occurrence listOfGroupingSurfaces.RemoveAll(groupingSurface => groupingSurface.listOfREOfGS.Count == 1); #region stampa delle MyGroupingSurface dopo la rimozione di quelle con solo una occorrenza //KLdebug.Print(" ", fileNameBuildRepeatedEntity); //KLdebug.Print(" ", fileNameBuildRepeatedEntity); //KLdebug.Print("LISTA DELLE GROUPING SURFACE DOPO LA RIMOZIONE DI QUELLE CON SOLO UNA 1 OCCORRENZA:", fileNameBuildRepeatedEntity); //whatToWrite1 = string.Format("Numero delle grouping surface trovate: " + listOfGroupingSurfaces.Count); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //KLdebug.Print(" ", fileNameBuildRepeatedEntity); foreach (var myGroupingSurface in listOfGroupingSurfaces) { MyPlane firstPlane1; if (!EntirePart) { var thisSurface = myGroupingSurface.groupingSurface; var firstPlaneParameters1 = thisSurface.PlaneParams; double[] firstPlanePoint1 = { firstPlaneParameters1[3], firstPlaneParameters1[4], firstPlaneParameters1[5] }; double[] firstPlaneNormal1 = { firstPlaneParameters1[0], firstPlaneParameters1[1], firstPlaneParameters1[2] }; firstPlane1 = new MyPlane(firstPlaneNormal1, firstPlanePoint1); } else { firstPlane1 = myGroupingSurface.KLplanareSurface; } //KLdebug.Print("Superficie:", fileNameBuildRepeatedEntity); //whatToWrite1 = string.Format("a {0}, b {1}, c {2}, d {3}", firstPlane1.a, firstPlane1.b, firstPlane1.c, firstPlane1.d); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //whatToWrite1 = string.Format("Numero di MyRepeatedEntity adiacenti: " + myGroupingSurface.listOfREOfGS.Count); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //KLdebug.Print(" ", "buildRepeatedEntity.txt"); } #endregion //I order the list by decreasing ordering respect to number of elements of listOfREOfGS listOfGroupingSurfaces = listOfGroupingSurfaces.OrderByDescending( groupingSurface => groupingSurface.listOfREOfGS.Count).ToList(); #region stampa delle MyGroupingSurface dopo il riordino per numero di occorrenze //KLdebug.Print(" ", fileNameBuildRepeatedEntity); //KLdebug.Print(" ", fileNameBuildRepeatedEntity); //KLdebug.Print("LISTA DELLE GROUPING SURFACE DOPO IL RIORDINO:", fileNameBuildRepeatedEntity); //whatToWrite1 = string.Format("Numero delle grouping surface trovate: " + listOfGroupingSurfaces.Count); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //KLdebug.Print(" ", fileNameBuildRepeatedEntity); foreach (var myGroupingSurface in listOfGroupingSurfaces) { MyPlane firstPlane1; if (!EntirePart) { var thisSurface = myGroupingSurface.groupingSurface; var firstPlaneParameters1 = thisSurface.PlaneParams; double[] firstPlanePoint1 = { firstPlaneParameters1[3], firstPlaneParameters1[4], firstPlaneParameters1[5] }; double[] firstPlaneNormal1 = { firstPlaneParameters1[0], firstPlaneParameters1[1], firstPlaneParameters1[2] }; firstPlane1 = new MyPlane(firstPlaneNormal1, firstPlanePoint1); } else { firstPlane1 = myGroupingSurface.KLplanareSurface; } //KLdebug.Print("Superficie:", fileNameBuildRepeatedEntity); //whatToWrite1 = string.Format("a {0}, b {1}, c {2}, d {3}", firstPlane1.a, firstPlane1.b, firstPlane1.c, firstPlane1.d); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //whatToWrite1 = string.Format("Numero di MyRepeatedEntity adiacenti: " + myGroupingSurface.listOfREOfGS.Count); //KLdebug.Print(whatToWrite1, fileNameBuildRepeatedEntity); //KLdebug.Print(" ", "buildRepeatedEntity.txt"); } #endregion StringBuilder fileOutput = new StringBuilder(); fileOutput.AppendLine("RICERCA PATH"); GeometryAnalysis.MainPatternSearch_Part(true, ref listOfGroupingSurfaces, listOfInitialGroupingSurface, ref fileOutput, swApp); #region per test //var listOfOutputPattern = new List<MyPattern>(); //list of output patterns found //var listOfOutputPatternTwo = new List<MyPattern>(); //list of output patterns of length 2 found //var toleranceOK = true; //it is TRUE if the tolerance level is OK during the paths searching, FALSE otherwise //var currentGroupingSurface = new MyGroupingSurface(listOfGroupingSurfaces[0].groupingSurface, listOfGroupingSurfaces[0].listOfREOfGS); //listOfGroupingSurfaces.RemoveAt(0); //fileOutput.AppendLine(" "); //fileOutput.AppendLine("CURRENT SURFACE OF TYPE: " + currentGroupingSurface.groupingSurface.Identity()); //fileOutput.AppendLine("(Al momento sono rimaste " + listOfGroupingSurfaces.Count + " superfici, compresa questa.)"); //var ListOfREOnThisSurface = // currentGroupingSurface.listOfREOfGS.Select(myRepeatedEntity => myRepeatedEntity).ToList(); //var listOfCentroidsThisGS = // currentGroupingSurface.listOfREOfGS.Select(myRepeatedEntity => myRepeatedEntity.centroid).ToList(); //var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise. //List<MyMatrAdj> listOfMyMatrAdj = Functions.CreateMatrAdj(listOfCentroidsThisGS, ref fileOutput); //fileOutput.AppendLine(" ----> listOfMyMatrAdj.Count = " + listOfMyMatrAdj.Count + ". Ora rimuovo la posizione 0:"); //var currentMatrAdj = new MyMatrAdj(listOfMyMatrAdj[0].d, listOfMyMatrAdj[0].matr, listOfMyMatrAdj[0].nOccur); //listOfMyMatrAdj.Remove(listOfMyMatrAdj[0]); //fileOutput.AppendLine(" "); //fileOutput.AppendLine("Esamino NUOVA MatrAdj. La elimino dalla lista."); //fileOutput.AppendLine(" ----> aggiornato listOfMyMatrAdj.Count = " + listOfMyMatrAdj.Count); //fileOutput.AppendLine("AVVIO RICERCA PATH in questa MatrAdj!"); //fileOutput.AppendLine(" "); //bool onlyShortPath; //var listOfPathOfCentroids = new List<MyPathOfPoints>(); //maxPath = Functions.FindPaths(currentMatrAdj, ListOfREOnThisSurface, ref fileOutput, // out listOfPathOfCentroids, out onlyShortPath, ref toleranceOK, // ref listOfMyMatrAdj, ref listOfGroupingSurfaces, // ref listOfOutputPattern, // ref listOfOutputPatternTwo); //fileOutput.AppendLine(" "); //fileOutput.AppendLine("RISULTA DA QUESTA MATRADJ: "); //fileOutput.AppendLine("maxPath = " + maxPath); //fileOutput.AppendLine("listOfMyPattern.Count = " + listOfOutputPattern.Count); //fileOutput.AppendLine("listOfMyPatternTwo.Count = " + listOfOutputPatternTwo.Count); //fileOutput.AppendLine("onlyShortPath = " + onlyShortPath); //fileOutput.AppendLine("toleranceOK = " + toleranceOK); //fileOutput.AppendLine("listOfPathOfCentroids.Count = " + listOfPathOfCentroids.Count); ////PATTERN //var myPathOfCentroids = listOfPathOfCentroids[0]; //listOfPathOfCentroids.RemoveAt(0); //var listOfREOnThePath = myPathOfCentroids.path.Select(ind => ListOfREOnThisSurface[ind]).ToList(); //GeometryAnalysis.GetTranslationalPatterns(listOfREOnThePath, myPathOfCentroids.pathGeometricObject, // ref listOfPathOfCentroids, listOfCentroidsThisGS, // ref listOfMyMatrAdj, ref listOfGroupingSurfaces, ref listOfOutputPattern, ref listOfOutputPatternTwo); #endregion // Create a file to write to. string mydocpath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); using (StreamWriter outfile = new StreamWriter(mydocpath + @"\PathCreation.txt", true)) { outfile.Write(fileOutput.ToString()); outfile.Close(); } }
//It verifies if a symmetry REFLECTIONAL relation between two MyRepeatedEntity exists public static bool IsReflectionTwoRE(MyRepeatedEntity firstMyRepeatedEntity, MyRepeatedEntity secondMyRepeatedEntity, SldWorks swapplication) { //const string nameFile = "GetReflectionalPattern.txt"; //KLdebug.Print(" ", nameFile); //var whatToWrite = ""; var candidateReflMyPlane = GetCandidateReflectionalMyPlane(firstMyRepeatedEntity.centroid, secondMyRepeatedEntity.centroid, swapplication); //Vertex analysis for Reflection: var firstListOfVertices = firstMyRepeatedEntity.listOfVertices; var firstNumOfVerteces = firstListOfVertices.Count; var secondListOfVertices = secondMyRepeatedEntity.listOfVertices; var secondNumOfVerteces = secondListOfVertices.Count; #region STAMPA DEI VERTICI DELLE DUE RE //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 1^ RE", nameFile); //foreach (var myVert in firstListOfVertices) //{ // var reflectionVertex = myVert.Reflect(candidateReflMyPlane); // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", firstListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); // whatToWrite = string.Format("{0}-esimo riflessione: ({1}, {2}, {3})", firstListOfVertices.IndexOf(myVert), // reflectionVertex.x, reflectionVertex.y, reflectionVertex.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); //KLdebug.Print("STAMPA DEI VERTICI DELLA 2^ RE", nameFile); //foreach (var myVert in secondListOfVertices) //{ // var reflectionVertex = myVert.Reflect(candidateReflMyPlane); // whatToWrite = string.Format("{0}-esimo vertice: ({1}, {2}, {3})", secondListOfVertices.IndexOf(myVert), // myVert.x, myVert.y, myVert.z); // KLdebug.Print(whatToWrite, nameFile); // whatToWrite = string.Format("{0}-esimo riflessione: ({1}, {2}, {3})", firstListOfVertices.IndexOf(myVert), // reflectionVertex.x, reflectionVertex.y, reflectionVertex.z); // KLdebug.Print(whatToWrite, nameFile); //} //KLdebug.Print(" ", nameFile); #endregion if (firstNumOfVerteces == secondNumOfVerteces) { //KLdebug.Print(" ", nameFile); //KLdebug.Print("Numero di vertici prima RE: " + firstNumOfVerteces, nameFile); //KLdebug.Print("Numero di vertici seconda RE: " + secondNumOfVerteces, nameFile); //KLdebug.Print("Il numero di vertici corrisponde. Passo alla verifica della corrispondenza per riflessione:", nameFile); //KLdebug.Print(" ", nameFile); int i = 0; while (i < firstNumOfVerteces) { var found = secondListOfVertices.Find( vert => vert.IsReflectionOf(firstListOfVertices[i], candidateReflMyPlane)); if (found != null) { //whatToWrite = string.Format("Ho trovato che {0}-esimo vertice: ({1}, {2}, {3})", i, firstListOfVertices[i].x, // firstListOfVertices[i].y, firstListOfVertices[i].z); //KLdebug.Print(whatToWrite, nameFile); //whatToWrite = string.Format("ha come suo riflesso ({0}, {1}, {2})", found.x, found.y, found.z); //var scarto = new MyVertex(Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).x - found.x), Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).y - found.y), Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).z - found.z)); //whatToWrite = string.Format("scarto: ({0}, {1}, {2})", scarto.x, scarto.y, scarto.z); //KLdebug.Print(whatToWrite, nameFile); //KLdebug.Print(" ", nameFile); i++; } else { //KLdebug.Print("TROVATO VERTICE NON CORRISPONDENTE ALLA CERCATA RIFLESSIONE!", nameFile); //KLdebug.Print(" ", nameFile); return(false); } } } else { //KLdebug.Print("NUMERO DI VERTICI NELLE DUE RE NON CORRISPONDENTE. IMPOSSIBILE EFFETTUARE IL CHECK DEI VERTICI!", nameFile); //KLdebug.Print(" ", nameFile); return(false); } //KLdebug.Print(" ANDATO A BUON FINE IL CHECK DEI VERTICI: PASSO AL CHECK DELLE FACCE.", nameFile); //KLdebug.Print(" ", nameFile); //Check of correct position of normals of all Planar face: if (!CheckOfPlanesForReflection(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateReflMyPlane)) { return(false); } ////Check of correct position of cylinder faces: //if (!CheckOfCylindersForReflection(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateReflMyPlane)) //{ // return false; //} ////CONTINUARE CON GLI ALTRI TIPI DI SUPERFICI............ //KLdebug.Print(" ====>>> TRASLAZIONE TRA QUESTE DUE re VERIFICATA!", nameFile); return(true); }