surfaceFeatureExtract.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "triangle.H"
00034 #include "triSurface.H"
00035 #include "argList.H"
00036 #include "surfaceFeatures.H"
00037 #include "treeBoundBox.H"
00038 #include "meshTools.H"
00039 #include "OFstream.H"
00040
00041 using namespace Foam;
00042
00043
00044
00045 void dumpBox(const treeBoundBox& bb, const fileName& fName)
00046 {
00047 OFstream str(fName);
00048
00049 Pout<< "Dumping bounding box " << bb << " as lines to obj file "
00050 << str.name() << endl;
00051
00052
00053 pointField boxPoints(bb.points());
00054
00055 forAll(boxPoints, i)
00056 {
00057 meshTools::writeOBJ(str, boxPoints[i]);
00058 }
00059
00060 forAll(treeBoundBox::edges, i)
00061 {
00062 const edge& e = treeBoundBox::edges[i];
00063
00064 str<< "l " << e[0]+1 << ' ' << e[1]+1 << nl;
00065 }
00066 }
00067
00068
00069
00070 void deleteBox
00071 (
00072 const triSurface& surf,
00073 const treeBoundBox& bb,
00074 const bool removeInside,
00075 List<surfaceFeatures::edgeStatus>& edgeStat
00076 )
00077 {
00078 forAll(edgeStat, edgeI)
00079 {
00080 const point eMid = surf.edges()[edgeI].centre(surf.localPoints());
00081
00082 if
00083 (
00084 (removeInside && bb.contains(eMid))
00085 || (!removeInside && !bb.contains(eMid))
00086 )
00087 {
00088 edgeStat[edgeI] = surfaceFeatures::NONE;
00089 }
00090 }
00091 }
00092
00093
00094
00095
00096 int main(int argc, char *argv[])
00097 {
00098 argList::noParallel();
00099
00100 argList::validArgs.clear();
00101 argList::validArgs.append("surface");
00102 argList::validArgs.append("output set");
00103
00104 argList::validOptions.insert("includedAngle", "included angle [0..180]");
00105 argList::validOptions.insert("set", "input feature set");
00106
00107 argList::validOptions.insert("minLen", "cumulative length of feature");
00108 argList::validOptions.insert("minElem", "number of edges in feature");
00109 argList::validOptions.insert("subsetBox", "((x0 y0 z0)(x1 y1 z1))");
00110 argList::validOptions.insert("deleteBox", "((x0 y0 z0)(x1 y1 z1))");
00111 argList args(argc, argv);
00112
00113 Pout<< "Feature line extraction is only valid on closed manifold surfaces."
00114 << endl;
00115
00116
00117 fileName surfFileName(args.additionalArgs()[0]);
00118 fileName outFileName(args.additionalArgs()[1]);
00119
00120 Pout<< "Surface : " << surfFileName << nl
00121 << "Output feature set : " << outFileName << nl
00122 << endl;
00123
00124
00125
00126
00127
00128 triSurface surf(surfFileName);
00129
00130 Pout<< "Statistics:" << endl;
00131 surf.writeStats(Pout);
00132 Pout<< endl;
00133
00134
00135
00136
00137
00138
00139
00140 surfaceFeatures set(surf);
00141
00142 if (args.optionFound("set"))
00143 {
00144 fileName setName(args.option("set"));
00145
00146 Pout<< "Reading existing feature set from file " << setName << endl;
00147
00148 set = surfaceFeatures(surf, setName);
00149 }
00150 else if (args.optionFound("includedAngle"))
00151 {
00152 scalar includedAngle = args.optionRead<scalar>("includedAngle");
00153
00154 Pout<< "Constructing feature set from included angle " << includedAngle
00155 << endl;
00156
00157 set = surfaceFeatures(surf, includedAngle);
00158
00159 Pout<< endl << "Writing initial features" << endl;
00160 set.write("initial.fSet");
00161 set.writeObj("initial");
00162 }
00163 else
00164 {
00165 FatalErrorIn(args.executable())
00166 << "No initial feature set. Provide either one"
00167 << " of -set (to read existing set)" << nl
00168 << " or -includedAngle (to new set construct from angle)"
00169 << exit(FatalError);
00170 }
00171
00172
00173 Pout<< nl
00174 << "Initial feature set:" << nl
00175 << " feature points : " << set.featurePoints().size() << nl
00176 << " feature edges : " << set.featureEdges().size() << nl
00177 << " of which" << nl
00178 << " region edges : " << set.nRegionEdges() << nl
00179 << " external edges : " << set.nExternalEdges() << nl
00180 << " internal edges : " << set.nInternalEdges() << nl
00181 << endl;
00182
00183
00184
00185
00186
00187
00188
00189 scalar minLen = -GREAT;
00190 if (args.optionReadIfPresent("minLen", minLen))
00191 {
00192 Pout<< "Removing features of length < " << minLen << endl;
00193 }
00194
00195 label minElem = 0;
00196 if (args.optionReadIfPresent("minElem", minElem))
00197 {
00198 Pout<< "Removing features with number of edges < " << minElem << endl;
00199 }
00200
00201
00202 if (minLen > 0 || minLen > 0)
00203 {
00204 set.trimFeatures(minLen, minElem);
00205 Pout<< endl << "Removed small features" << endl;
00206 }
00207
00208
00209
00210
00211
00212
00213
00214 List<surfaceFeatures::edgeStatus> edgeStat(set.toStatus());
00215
00216 if (args.optionFound("subsetBox"))
00217 {
00218 treeBoundBox bb(args.optionLookup("subsetBox")());
00219
00220 Pout<< "Removing all edges outside bb " << bb << endl;
00221 dumpBox(bb, "subsetBox.obj");
00222
00223 deleteBox
00224 (
00225 surf,
00226 bb,
00227 false,
00228 edgeStat
00229 );
00230 }
00231 else if (args.optionFound("deleteBox"))
00232 {
00233 treeBoundBox bb(args.optionLookup("deleteBox")());
00234
00235 Pout<< "Removing all edges inside bb " << bb << endl;
00236 dumpBox(bb, "deleteBox.obj");
00237
00238 deleteBox
00239 (
00240 surf,
00241 bb,
00242 true,
00243 edgeStat
00244 );
00245 }
00246
00247 surfaceFeatures newSet(surf);
00248 newSet.setFromStatus(edgeStat);
00249
00250 Pout<< endl << "Writing trimmed features to " << outFileName << endl;
00251 newSet.write(outFileName);
00252
00253 Pout<< endl << "Writing edge objs." << endl;
00254 newSet.writeObj("final");
00255
00256
00257 Pout<< nl
00258 << "Final feature set:" << nl
00259 << " feature points : " << newSet.featurePoints().size() << nl
00260 << " feature edges : " << newSet.featureEdges().size() << nl
00261 << " of which" << nl
00262 << " region edges : " << newSet.nRegionEdges() << nl
00263 << " external edges : " << newSet.nExternalEdges() << nl
00264 << " internal edges : " << newSet.nInternalEdges() << nl
00265 << endl;
00266
00267 Pout<< "End\n" << endl;
00268
00269 return 0;
00270 }
00271
00272
00273
Copyright © 2000-2009 OpenCFD Ltd