mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge commit 'bundle/home' into olesenm
This commit is contained in:
@ -52,10 +52,11 @@ Note
|
||||
#include "timeSelector.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "triSurface.H"
|
||||
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "UnsortedMeshedSurfaces.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -69,7 +70,7 @@ int main(int argc, char *argv[])
|
||||
argList::validOptions.insert("clean", "");
|
||||
argList::validOptions.insert("scale", "scale");
|
||||
argList::validOptions.insert("triSurface", "");
|
||||
argList::validOptions.insert("keyed", "");
|
||||
argList::validOptions.insert("unsorted", "");
|
||||
# include "setRootCase.H"
|
||||
const stringList& params = args.additionalArgs();
|
||||
|
||||
@ -122,9 +123,9 @@ int main(int argc, char *argv[])
|
||||
// write sorted by region
|
||||
surf.write(exportName, true);
|
||||
}
|
||||
else if (args.options().found("keyed"))
|
||||
else if (args.options().found("unsorted"))
|
||||
{
|
||||
keyedSurface surf(importName);
|
||||
unsortedMeshedSurface surf(importName);
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
|
||||
@ -31,7 +31,7 @@ License
|
||||
const dataType Foam::className::staticData();
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
@ -71,10 +71,16 @@ Foam::className::~className()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::className::operator=(const className& rhs)
|
||||
{
|
||||
@ -87,11 +93,10 @@ void Foam::className::operator=(const className& rhs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -32,7 +32,7 @@ template<TemplateClassArgument>
|
||||
const dataType Foam::ClassName<TemplateArgument>::staticData();
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
@ -84,10 +84,16 @@ Foam::ClassName<TemplateArgument>::~ClassName()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||
|
||||
template<TemplateClassArgument>
|
||||
void Foam::ClassName<TemplateArgument>::operator=
|
||||
@ -108,10 +114,10 @@ void Foam::ClassName<TemplateArgument>::operator=
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -35,6 +35,8 @@ Description
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// add to hash-table of functions with typename as the key
|
||||
#define addToMemberFunctionSelectionTable\
|
||||
(baseType,thisType,memberFunction,argNames) \
|
||||
\
|
||||
@ -42,6 +44,9 @@ Description
|
||||
baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType> \
|
||||
add##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_
|
||||
|
||||
|
||||
|
||||
// add to hash-table of functions with 'lookup' as the key
|
||||
#define addNamedToMemberFunctionSelectionTable\
|
||||
(baseType,thisType,memberFunction,argNames,lookup) \
|
||||
\
|
||||
@ -49,6 +54,11 @@ Description
|
||||
baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType> \
|
||||
add_##lookup##_##thisType##memberFunction##argNames##MemberFunctionTo##baseType##Table_(#lookup)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// add to hash-table of functions with typename as the key
|
||||
// use when baseType doesn't need a template argument (eg, is a typedef)
|
||||
#define addTemplateToMemberFunctionSelectionTable\
|
||||
(baseType,thisType,Targ,memberFunction,argNames) \
|
||||
@ -57,6 +67,8 @@ Description
|
||||
baseType::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
|
||||
add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Table_
|
||||
|
||||
|
||||
// add to hash-table of functions with 'lookup' as the key
|
||||
// use when baseType doesn't need a template argument (eg, is a typedef)
|
||||
#define addNamedTemplateToMemberFunctionSelectionTable\
|
||||
(baseType,thisType,Targ,memberFunction,argNames,lookup) \
|
||||
@ -82,6 +94,29 @@ Description
|
||||
add_##lookup##_##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Targ##Table_(#lookup)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// add to hash-table of functions with typename as the key
|
||||
// use when baseType requires the Targ template argument as well
|
||||
#define addTemplatedToMemberFunctionSelectionTable\
|
||||
(baseType,thisType,Targ,memberFunction,argNames) \
|
||||
\
|
||||
/* Add the thisType memberFunction to the table */ \
|
||||
baseType<Targ>::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
|
||||
add##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Targ##Table_
|
||||
|
||||
|
||||
// add to hash-table of functions with 'lookup' as the key
|
||||
// use when baseType requires the Targ template argument as well
|
||||
#define addNamedTemplatedToMemberFunctionSelectionTable\
|
||||
(baseType,thisType,Targ,memberFunction,argNames,lookup) \
|
||||
\
|
||||
/* Add the thisType memberFunction to the table, find by lookup name */ \
|
||||
baseType<Targ>::add##memberFunction##argNames##MemberFunctionToTable<thisType<Targ> > \
|
||||
add_##lookup##_##thisType##Targ##memberFunction##argNames##MemberFunctionTo##baseType##Targ##Table_(#lookup)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
@ -39,6 +39,10 @@ Description
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// declare a run-time selection:
|
||||
#define declareMemberFunctionSelectionTable\
|
||||
(returnType,baseType,memberFunction,argNames,argList,parList) \
|
||||
\
|
||||
@ -86,6 +90,8 @@ Description
|
||||
static void destroy##memberFunction##argNames##MemberFunctionTables()
|
||||
|
||||
|
||||
// internal use:
|
||||
// constructor aid
|
||||
#define defineMemberFunctionSelectionTableMemberFunction\
|
||||
(baseType,memberFunction,argNames) \
|
||||
\
|
||||
@ -103,6 +109,9 @@ Description
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
// internal use:
|
||||
// destructor aid
|
||||
#define defineMemberFunctionSelectionTableDestructor\
|
||||
(baseType,memberFunction,argNames) \
|
||||
\
|
||||
@ -116,6 +125,9 @@ Description
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
// internal use:
|
||||
// create pointer to hash-table of functions
|
||||
#define defineMemberFunctionSelectionTablePtr\
|
||||
(baseType,memberFunction,argNames) \
|
||||
\
|
||||
@ -123,6 +135,8 @@ Description
|
||||
baseType::memberFunction##argNames##MemberFunctionTable* \
|
||||
baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
|
||||
|
||||
|
||||
// not much in use:
|
||||
#define defineTemplateMemberFunctionSelectionTablePtr\
|
||||
(baseType,memberFunction,argNames) \
|
||||
\
|
||||
@ -130,7 +144,14 @@ Description
|
||||
typename baseType::memberFunction##argNames##MemberFunctionTable* \
|
||||
baseType::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
|
||||
|
||||
#define defineMemberFunctionSelectionTable(baseType,memberFunction,argNames) \
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// define run-time selection table
|
||||
#define defineMemberFunctionSelectionTable\
|
||||
(baseType,memberFunction,argNames) \
|
||||
\
|
||||
defineMemberFunctionSelectionTablePtr \
|
||||
(baseType,memberFunction,argNames); \
|
||||
@ -139,6 +160,11 @@ Description
|
||||
defineMemberFunctionSelectionTableDestructor \
|
||||
(baseType,memberFunction,argNames)
|
||||
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// define run-time selection table for template classes
|
||||
// use when baseType doesn't need a template argument (eg, is a typedef)
|
||||
#define defineTemplateMemberFunctionSelectionTable\
|
||||
(baseType,memberFunction,argNames) \
|
||||
\
|
||||
@ -155,6 +181,74 @@ Description
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// internal use:
|
||||
// constructor aid
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedMemberFunctionSelectionTableMemberFunction\
|
||||
(baseType,memberFunction,argNames,Targ) \
|
||||
\
|
||||
/* Table memberFunction called from the table add function */ \
|
||||
void baseType<Targ>::construct##memberFunction##argNames##MemberFunctionTables()\
|
||||
{ \
|
||||
static bool constructed = false; \
|
||||
\
|
||||
if (!constructed) \
|
||||
{ \
|
||||
baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ \
|
||||
= new baseType<Targ>::memberFunction##argNames##MemberFunctionTable;\
|
||||
\
|
||||
constructed = true; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
// internal use:
|
||||
// destructor aid
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedMemberFunctionSelectionTableDestructor\
|
||||
(baseType,memberFunction,argNames,Targ) \
|
||||
\
|
||||
/* Table destructor called from the table add function destructor */ \
|
||||
void baseType<Targ>::destroy##memberFunction##argNames##MemberFunctionTables() \
|
||||
{ \
|
||||
if (baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_) \
|
||||
{ \
|
||||
delete baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_;\
|
||||
baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL;\
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
// internal use:
|
||||
// create pointer to hash-table of functions
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedMemberFunctionSelectionTablePtr\
|
||||
(baseType,memberFunction,argNames,Targ) \
|
||||
\
|
||||
/* Define the memberFunction table */ \
|
||||
baseType<Targ>::memberFunction##argNames##MemberFunctionTable* \
|
||||
baseType<Targ>::memberFunction##argNames##MemberFunctionTablePtr_ = NULL
|
||||
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// define run-time selection table for template classes
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedMemberFunctionSelectionTable\
|
||||
(baseType,memberFunction,argNames,Targ) \
|
||||
\
|
||||
template<> \
|
||||
defineTemplatedMemberFunctionSelectionTablePtr \
|
||||
(baseType,memberFunction,argNames,Targ); \
|
||||
template<> \
|
||||
defineTemplatedMemberFunctionSelectionTableMemberFunction \
|
||||
(baseType,memberFunction,argNames,Targ) \
|
||||
template<> \
|
||||
defineTemplatedMemberFunctionSelectionTableDestructor \
|
||||
(baseType,memberFunction,argNames,Targ)
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -35,6 +35,8 @@ Description
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// add to hash-table of functions with typename as the key
|
||||
#define addToRunTimeSelectionTable\
|
||||
(baseType,thisType,argNames) \
|
||||
\
|
||||
@ -42,6 +44,8 @@ Description
|
||||
baseType::add##argNames##ConstructorToTable<thisType> \
|
||||
add##thisType##argNames##ConstructorTo##baseType##Table_
|
||||
|
||||
|
||||
// add to hash-table of functions with 'lookup' as the key
|
||||
#define addNamedToRunTimeSelectionTable\
|
||||
(baseType,thisType,argNames,lookup) \
|
||||
\
|
||||
@ -49,6 +53,10 @@ Description
|
||||
baseType::add##argNames##ConstructorToTable<thisType> \
|
||||
add_##lookup##_##thisType##argNames##ConstructorTo##baseType##Table_(#lookup)
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// add to hash-table of functions with typename as the key
|
||||
// use when baseType doesn't need a template argument (eg, is a typedef)
|
||||
#define addTemplateToRunTimeSelectionTable\
|
||||
(baseType,thisType,Targ,argNames) \
|
||||
@ -57,6 +65,8 @@ Description
|
||||
baseType::add##argNames##ConstructorToTable<thisType<Targ> > \
|
||||
add##thisType##Targ##argNames##ConstructorTo##baseType##Table_
|
||||
|
||||
|
||||
// add to hash-table of functions with 'lookup' as the key
|
||||
// use when baseType doesn't need a template argument (eg, is a typedef)
|
||||
#define addNamedTemplateToRunTimeSelectionTable\
|
||||
(baseType,thisType,Targ,argNames,lookup) \
|
||||
@ -65,6 +75,11 @@ Description
|
||||
baseType::add##argNames##ConstructorToTable<thisType<Targ> > \
|
||||
add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Table_(#lookup)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// add to hash-table of functions with typename as the key
|
||||
// use when baseType requires the Targ template argument as well
|
||||
#define addTemplatedToRunTimeSelectionTable\
|
||||
(baseType,thisType,Targ,argNames) \
|
||||
@ -73,6 +88,8 @@ Description
|
||||
baseType<Targ>::add##argNames##ConstructorToTable<thisType<Targ> > \
|
||||
add##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_
|
||||
|
||||
|
||||
// add to hash-table of functions with 'lookup' as the key
|
||||
// use when baseType requires the Targ template argument as well
|
||||
#define addNamedTemplatedToRunTimeSelectionTable\
|
||||
(baseType,thisType,Targ,argNames,lookup) \
|
||||
@ -81,6 +98,7 @@ Description
|
||||
baseType<Targ>::add##argNames##ConstructorToTable<thisType<Targ> > \
|
||||
add_##lookup##_##thisType##Targ##argNames##ConstructorTo##baseType##Targ##Table_(#lookup)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
@ -40,6 +40,10 @@ Description
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// declare a run-time selection:
|
||||
#define declareRunTimeSelectionTable\
|
||||
(autoPtr,baseType,argNames,argList,parList) \
|
||||
\
|
||||
@ -86,7 +90,10 @@ Description
|
||||
static void destroy##argNames##ConstructorTables()
|
||||
|
||||
|
||||
#define defineRunTimeSelectionTableConstructor(baseType,argNames) \
|
||||
// internal use:
|
||||
// constructor aid
|
||||
#define defineRunTimeSelectionTableConstructor\
|
||||
(baseType,argNames) \
|
||||
\
|
||||
/* Table constructor called from the table add function */ \
|
||||
void baseType::construct##argNames##ConstructorTables() \
|
||||
@ -102,7 +109,11 @@ Description
|
||||
} \
|
||||
}
|
||||
|
||||
#define defineRunTimeSelectionTableDestructor(baseType,argNames) \
|
||||
|
||||
// internal use:
|
||||
// destructor aid
|
||||
#define defineRunTimeSelectionTableDestructor\
|
||||
(baseType,argNames) \
|
||||
\
|
||||
/* Table destructor called from the table add function destructor */ \
|
||||
void baseType::destroy##argNames##ConstructorTables() \
|
||||
@ -114,24 +125,43 @@ Description
|
||||
} \
|
||||
}
|
||||
|
||||
#define defineRunTimeSelectionTablePtr(baseType,argNames) \
|
||||
|
||||
// internal use:
|
||||
// create pointer to hash-table of functions
|
||||
#define defineRunTimeSelectionTablePtr\
|
||||
(baseType,argNames) \
|
||||
\
|
||||
/* Define the constructor function table */ \
|
||||
baseType::argNames##ConstructorTable* \
|
||||
baseType::argNames##ConstructorTablePtr_ = NULL
|
||||
|
||||
|
||||
// not much in use:
|
||||
#define defineTemplateRunTimeSelectionTablePtr(baseType,argNames) \
|
||||
\
|
||||
/* Define the constructor function table */ \
|
||||
typename baseType::argNames##ConstructorTable* \
|
||||
baseType::argNames##ConstructorTablePtr_ = NULL
|
||||
|
||||
#define defineRunTimeSelectionTable(baseType,argNames) \
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// define run-time selection table
|
||||
#define defineRunTimeSelectionTable\
|
||||
(baseType,argNames) \
|
||||
\
|
||||
defineRunTimeSelectionTablePtr(baseType,argNames); \
|
||||
defineRunTimeSelectionTableConstructor(baseType,argNames) \
|
||||
defineRunTimeSelectionTableDestructor(baseType,argNames)
|
||||
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// define run-time selection table for template classes
|
||||
// use when baseType doesn't need a template argument (eg, is a typedef)
|
||||
#define defineTemplateRunTimeSelectionTable(baseType,argNames) \
|
||||
\
|
||||
template<> \
|
||||
@ -142,6 +172,73 @@ Description
|
||||
defineRunTimeSelectionTableDestructor(baseType,argNames)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// internal use:
|
||||
// constructor aid
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedRunTimeSelectionTableConstructor\
|
||||
(baseType,argNames,Targ) \
|
||||
\
|
||||
/* Table constructor called from the table add function */ \
|
||||
void baseType<Targ>::construct##argNames##ConstructorTables() \
|
||||
{ \
|
||||
static bool constructed = false; \
|
||||
\
|
||||
if (!constructed) \
|
||||
{ \
|
||||
baseType<Targ>::argNames##ConstructorTablePtr_ \
|
||||
= new baseType<Targ>::argNames##ConstructorTable; \
|
||||
\
|
||||
constructed = true; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
// internal use:
|
||||
// destructor aid
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedRunTimeSelectionTableDestructor\
|
||||
(baseType,argNames,Targ) \
|
||||
\
|
||||
/* Table destructor called from the table add function destructor */ \
|
||||
void baseType<Targ>::destroy##argNames##ConstructorTables() \
|
||||
{ \
|
||||
if (baseType<Targ>::argNames##ConstructorTablePtr_) \
|
||||
{ \
|
||||
delete baseType<Targ>::argNames##ConstructorTablePtr_; \
|
||||
baseType<Targ>::argNames##ConstructorTablePtr_ = NULL; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
// internal use:
|
||||
// create pointer to hash-table of functions
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedRunTimeSelectionTablePtr\
|
||||
(baseType,argNames,Targ) \
|
||||
\
|
||||
/* Define the constructor function table */ \
|
||||
baseType<Targ>::argNames##ConstructorTable* \
|
||||
baseType<Targ>::argNames##ConstructorTablePtr_ = NULL
|
||||
|
||||
|
||||
// external use:
|
||||
// ~~~~~~~~~~~~~
|
||||
// define run-time selection table for template classes
|
||||
// use when baseType requires the Targ template argument
|
||||
#define defineTemplatedRunTimeSelectionTable\
|
||||
(baseType,argNames,Targ) \
|
||||
\
|
||||
template<> \
|
||||
defineTemplatedRunTimeSelectionTablePtr(baseType,argNames,Targ); \
|
||||
template<> \
|
||||
defineTemplatedRunTimeSelectionTableConstructor(baseType,argNames,Targ) \
|
||||
template<> \
|
||||
defineTemplatedRunTimeSelectionTableDestructor(baseType,argNames,Targ)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,27 +2,24 @@ surfGroup/surfGroup.C
|
||||
surfGroup/surfGroupIOList.C
|
||||
surfPatchIdentifier/surfPatchIdentifier.C
|
||||
|
||||
keyedSurface/keyedSurface.C
|
||||
keyedSurface/keyedSurfaceCleanup.C
|
||||
keyedSurface/newKeyedSurface.C
|
||||
MeshedSurface/MeshedSurfaces.C
|
||||
UnsortedMeshedSurface/UnsortedMeshedSurfaces.C
|
||||
|
||||
meshedSurface/meshedSurface.C
|
||||
meshedSurface/meshedSurfaceCleanup.C
|
||||
meshedSurface/newMeshedSurface.C
|
||||
|
||||
fileFormats = keyedSurface/fileFormats
|
||||
$(fileFormats)/ac3d/AC3DfileFormat.C
|
||||
$(fileFormats)/ftr/FTRfileFormat.C
|
||||
$(fileFormats)/gts/GTSfileFormat.C
|
||||
$(fileFormats)/nas/NASfileFormat.C
|
||||
$(fileFormats)/obj/OBJfileFormat.C
|
||||
$(fileFormats)/off/OFFfileFormat.C
|
||||
$(fileFormats)/smesh/SMESHfileFormat.C
|
||||
$(fileFormats)/starcd/STARCDfileFormat.C
|
||||
$(fileFormats)/stl/STLfileFormat.C
|
||||
$(fileFormats)/stl/STLfileFormatASCII.L
|
||||
$(fileFormats)/tri/TRIfileFormat.C
|
||||
$(fileFormats)/vtk/VTKfileFormat.C
|
||||
surfaceFormats = surfaceFormats
|
||||
$(surfaceFormats)/surfaceFormatsCore.C
|
||||
$(surfaceFormats)/ac3d/AC3DsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/ftr/FTRsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/nas/NASsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/off/OFFsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/stl/STLsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/stl/STLsurfaceFormatASCII.L
|
||||
$(surfaceFormats)/stl/STLsurfaceFormatCore.C
|
||||
$(surfaceFormats)/tri/TRIsurfaceFormatRunTime.C
|
||||
$(surfaceFormats)/vtk/VTKsurfaceFormatRunTime.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libsurfMesh
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -23,34 +23,35 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::meshedSurface
|
||||
Foam::MeshedSurface
|
||||
|
||||
Description
|
||||
A surface geometry mesh with patch information, not to be confused
|
||||
with a similarily named surfaceMesh, which actually refers to
|
||||
the cell faces of a volume mesh!
|
||||
|
||||
The meshedSurface is intended to surfaces from a variety of sources.
|
||||
The MeshedSurface is intended to surfaces from a variety of sources.
|
||||
- A set of points and faces without any patch information.
|
||||
- A set of points and faces with randomly sorted patch information.
|
||||
This could arise, for example, from reading external file formats
|
||||
such as STL, etc.
|
||||
|
||||
SourceFiles
|
||||
meshedSurface.C
|
||||
MeshedSurface.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef meshedSurface_H
|
||||
#define meshedSurface_H
|
||||
#ifndef MeshedSurface_H
|
||||
#define MeshedSurface_H
|
||||
|
||||
#include "pointField.H"
|
||||
#include "PrimitivePatchExtra.H"
|
||||
#include "boolList.H"
|
||||
#include "surfGroupList.H"
|
||||
#include "face.H"
|
||||
#include "Keyed.H"
|
||||
#include "surfaceFormatsCore.H"
|
||||
#include "xfer.H"
|
||||
#include "face.H"
|
||||
#include "triFace.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "memberFunctionSelectionTables.H"
|
||||
|
||||
@ -62,48 +63,39 @@ namespace Foam
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
class Time;
|
||||
class keyedSurface;
|
||||
class meshedSurface;
|
||||
template<class Face> class MeshedSurface;
|
||||
template<class Face> class UnsortedMeshedSurface;
|
||||
|
||||
class polyBoundaryMesh;
|
||||
class surfMesh;
|
||||
|
||||
Istream& operator>>(Istream&, meshedSurface&);
|
||||
Ostream& operator<<(Ostream&, const meshedSurface&);
|
||||
template<class Face>
|
||||
Ostream& operator<<(Ostream&, const MeshedSurface<Face>&);
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class meshedSurface Declaration
|
||||
Class MeshedSurface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class meshedSurface
|
||||
template<class Face>
|
||||
class MeshedSurface
|
||||
:
|
||||
public PrimitivePatchExtra<face, ::Foam::List, pointField, point>
|
||||
public PrimitivePatchExtra<Face, ::Foam::List, pointField, point>,
|
||||
public fileFormats::surfaceFormatsCore
|
||||
{
|
||||
friend class keyedSurface;
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Data
|
||||
|
||||
//- Typedef if this type has not already been defined
|
||||
typedef Keyed<face> keyedFace;
|
||||
|
||||
//- Typedef for similar code in keyedSurface and meshedSurface
|
||||
typedef face FaceType;
|
||||
friend class UnsortedMeshedSurface<Face>;
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Data
|
||||
|
||||
// Private typedefs
|
||||
|
||||
//- Private typedefs for convenience
|
||||
typedef MeshedSurface<Face> ThisType;
|
||||
typedef PrimitivePatchExtra
|
||||
<
|
||||
FaceType,
|
||||
Face,
|
||||
::Foam::List,
|
||||
pointField,
|
||||
point
|
||||
>
|
||||
MeshStorage;
|
||||
ParentType;
|
||||
|
||||
// Private Member Data
|
||||
|
||||
@ -113,17 +105,17 @@ private:
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Sort faces by regionIds and set patches
|
||||
void sortFacesByRegion(const List<label>&, const Map<word>&);
|
||||
|
||||
//- set a single patch
|
||||
void onePatch();
|
||||
|
||||
//- basic sanity check on patches
|
||||
void checkPatches();
|
||||
|
||||
//- Sort faces by regionIds and set patches
|
||||
void sortFacesByRegion(const UList<label>&, const Map<word>&);
|
||||
|
||||
//- Read OpenFOAM Surface format
|
||||
bool read(Istream&, const bool triangulate=false);
|
||||
bool read(Istream&);
|
||||
|
||||
|
||||
protected:
|
||||
@ -133,139 +125,146 @@ protected:
|
||||
//- Return non-const access to global points
|
||||
pointField& points()
|
||||
{
|
||||
return const_cast<pointField&>(MeshStorage::points());
|
||||
return const_cast<pointField&>(ParentType::points());
|
||||
}
|
||||
|
||||
//- Return non-const access to the faces
|
||||
List<FaceType>& faces()
|
||||
List<Face>& faces()
|
||||
{
|
||||
return static_cast<List<FaceType> &>(*this);
|
||||
return static_cast<List<Face> &>(*this);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
ClassName("meshedSurface");
|
||||
ClassName("MeshedSurface");
|
||||
|
||||
// Static
|
||||
|
||||
//- Name of meshedSurface directory to use.
|
||||
//- Name of MeshedSurface directory to use.
|
||||
static fileName triSurfInstance(const Time&);
|
||||
|
||||
//- Name of meshedSurface directory to use.
|
||||
//- Name of MeshedSurface directory to use.
|
||||
static fileName triSurfName(const Time&);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const word& ext, const bool verbose=false);
|
||||
|
||||
//- Can we write this file format?
|
||||
static bool canWrite(const word& ext, const bool verbose=false);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
meshedSurface();
|
||||
MeshedSurface();
|
||||
|
||||
//- Construct by transferring components
|
||||
// (points, faces and patches).
|
||||
meshedSurface
|
||||
MeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&,
|
||||
const xfer<List<Face> >&,
|
||||
const xfer<surfGroupList>&
|
||||
);
|
||||
|
||||
//- Construct from points, faces, and patch information
|
||||
meshedSurface
|
||||
MeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&,
|
||||
const List<label>& patchSizes,
|
||||
const List<word>& patchNames,
|
||||
const List<word>& patchTypes
|
||||
const xfer<List<Face> >&,
|
||||
const UList<label>& patchSizes,
|
||||
const UList<word>& patchNames,
|
||||
const UList<word>& patchTypes
|
||||
);
|
||||
|
||||
//- Construct by transferring points, faces.
|
||||
// Sort faces according to regionIds with the names of the regions,
|
||||
// or jsut set a single default patch.
|
||||
meshedSurface
|
||||
MeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&,
|
||||
const List<label>& regionIds = List<label>::null(),
|
||||
const xfer<List<Face> >&,
|
||||
const UList<label>& regionIds = UList<label>::null(),
|
||||
const Map<word>& regionNames = Map<word>::null()
|
||||
);
|
||||
|
||||
//- Construct by transferring points, faces.
|
||||
// Sort faces according to regionIds with patch-names from hash
|
||||
meshedSurface
|
||||
MeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&,
|
||||
const List<label>& regionIds,
|
||||
const xfer<List<Face> >&,
|
||||
const UList<label>& regionIds,
|
||||
const HashTable<label>& nameToRegionMapping
|
||||
);
|
||||
|
||||
//- Construct from a boundary mesh with local points/faces
|
||||
meshedSurface
|
||||
MeshedSurface
|
||||
(
|
||||
const polyBoundaryMesh&,
|
||||
const bool globalPoints=false
|
||||
);
|
||||
|
||||
//- Construct from a keyedSurface
|
||||
meshedSurface(const keyedSurface&);
|
||||
//- Construct from a UnsortedMeshedSurface
|
||||
MeshedSurface(const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
//- Construct from a surfMesh
|
||||
meshedSurface(const surfMesh&);
|
||||
MeshedSurface(const surfMesh&);
|
||||
|
||||
//- Construct by transferring the contents from a keyedSurface
|
||||
meshedSurface(const xfer<keyedSurface>&);
|
||||
|
||||
//- Construct by transferring the contents from a meshedSurface
|
||||
meshedSurface(const xfer<meshedSurface>&);
|
||||
//- Construct by transferring the contents from a UnsortedMeshedSurface
|
||||
MeshedSurface(const xfer<UnsortedMeshedSurface<Face> >&);
|
||||
|
||||
//- Construct by transferring the contents from a MeshedSurface
|
||||
MeshedSurface(const xfer<MeshedSurface<Face> >&);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
meshedSurface
|
||||
(
|
||||
const fileName&,
|
||||
const bool triangulate=false
|
||||
);
|
||||
MeshedSurface(const fileName&);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
meshedSurface
|
||||
(
|
||||
const fileName&,
|
||||
const word& ext,
|
||||
const bool triangulate=false
|
||||
);
|
||||
MeshedSurface(const fileName&, const word& ext);
|
||||
|
||||
//- Construct from Istream
|
||||
meshedSurface(Istream&, const bool triangulate=false);
|
||||
MeshedSurface(Istream&);
|
||||
|
||||
//- Construct from objectRegistry
|
||||
meshedSurface(const Time&);
|
||||
MeshedSurface(const Time&);
|
||||
|
||||
//- Construct as copy
|
||||
meshedSurface(const meshedSurface&);
|
||||
MeshedSurface(const MeshedSurface&);
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
MeshedSurface,
|
||||
fileExtension,
|
||||
(
|
||||
const fileName& fName
|
||||
),
|
||||
(fName)
|
||||
);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select constructed from filename (implicit extension)
|
||||
static autoPtr<meshedSurface> New
|
||||
static autoPtr<MeshedSurface> New
|
||||
(
|
||||
const fileName&,
|
||||
const bool triangulate=false
|
||||
const fileName&
|
||||
);
|
||||
|
||||
//- Select constructed from filename (explicit extension)
|
||||
static autoPtr<meshedSurface> New
|
||||
static autoPtr<MeshedSurface> New
|
||||
(
|
||||
const fileName&,
|
||||
const word&,
|
||||
const bool triangulate=false
|
||||
const word& ext
|
||||
);
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~meshedSurface();
|
||||
virtual ~MeshedSurface();
|
||||
|
||||
|
||||
// Member Function Selectors
|
||||
@ -273,24 +272,18 @@ public:
|
||||
declareMemberFunctionSelectionTable
|
||||
(
|
||||
void,
|
||||
meshedSurface,
|
||||
MeshedSurface,
|
||||
write,
|
||||
fileExtension,
|
||||
(
|
||||
const fileName& fName,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
),
|
||||
(fName, surf)
|
||||
);
|
||||
|
||||
//- Write to file
|
||||
static void write(const fileName&, const meshedSurface&);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const word& ext, const bool verbose=false);
|
||||
|
||||
//- Can we write this file format?
|
||||
static bool canWrite(const word& ext, const bool verbose=false);
|
||||
static void write(const fileName&, const MeshedSurface<Face>&);
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -306,25 +299,25 @@ public:
|
||||
//- Return the number of faces
|
||||
label nFaces() const
|
||||
{
|
||||
return MeshStorage::size();
|
||||
return ParentType::size();
|
||||
}
|
||||
|
||||
//- The surface size is the number of faces
|
||||
label size() const
|
||||
{
|
||||
return MeshStorage::size();
|
||||
return ParentType::size();
|
||||
}
|
||||
|
||||
//- Return const access to global points
|
||||
const pointField& points() const
|
||||
{
|
||||
return MeshStorage::points();
|
||||
return ParentType::points();
|
||||
}
|
||||
|
||||
//- Return const access to the faces
|
||||
const List<FaceType>& faces() const
|
||||
const List<Face>& faces() const
|
||||
{
|
||||
return static_cast<const List<FaceType> &>(*this);
|
||||
return static_cast<const List<Face> &>(*this);
|
||||
}
|
||||
|
||||
const surfGroupList& patches() const
|
||||
@ -339,6 +332,9 @@ public:
|
||||
|
||||
// Edit
|
||||
|
||||
//- Clear all storage
|
||||
virtual void clear();
|
||||
|
||||
//- Move points
|
||||
virtual void movePoints(const pointField&);
|
||||
|
||||
@ -361,29 +357,28 @@ public:
|
||||
|
||||
//- Return new surface.
|
||||
// Returns pointMap, faceMap from subsetMeshMap
|
||||
meshedSurface subsetMesh
|
||||
MeshedSurface subsetMesh
|
||||
(
|
||||
const boolList& include,
|
||||
const UList<bool>& include,
|
||||
labelList& pointMap,
|
||||
labelList& faceMap
|
||||
) const;
|
||||
|
||||
//- Transfer the contents of the argument and annull the argument
|
||||
void transfer(meshedSurface&);
|
||||
void transfer(MeshedSurface<Face>&);
|
||||
|
||||
//- Transfer the contents of the argument and annull the argument
|
||||
void transfer(keyedSurface&);
|
||||
void transfer(UnsortedMeshedSurface<Face>&);
|
||||
|
||||
|
||||
// Read
|
||||
|
||||
//- Read from file. Chooses reader based on extension
|
||||
bool read
|
||||
(
|
||||
const fileName&,
|
||||
const word& ext,
|
||||
const bool triangulate=false
|
||||
);
|
||||
//- Read from file. Chooses reader based on explicit extension
|
||||
bool read(const fileName&, const word& ext);
|
||||
|
||||
|
||||
//- Read from file. Chooses reader based on detected extension
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
|
||||
// Write
|
||||
@ -406,12 +401,16 @@ public:
|
||||
|
||||
// Member operators
|
||||
|
||||
void operator=(const meshedSurface&);
|
||||
void operator=(const MeshedSurface<Face>&);
|
||||
|
||||
// Ostream Operator
|
||||
|
||||
// friend Istream& operator>>(Istream&, meshedSurface&);
|
||||
friend Ostream& operator<<(Ostream&, const meshedSurface&);
|
||||
friend Ostream& operator<<
|
||||
<Face>
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@ -421,6 +420,12 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "MeshedSurface.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,24 +24,29 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "mergePoints.H"
|
||||
#include "triFace.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Remove badly degenerate faces, double faces.
|
||||
void Foam::meshedSurface::cleanup(const bool verbose)
|
||||
template<class Face>
|
||||
void Foam::MeshedSurface<Face>::cleanup(const bool verbose)
|
||||
{
|
||||
// merge points (already done for STL, TRI)
|
||||
stitchFaces(SMALL, verbose);
|
||||
|
||||
checkFaces(verbose);
|
||||
checkEdges(verbose);
|
||||
ParentType::checkEdges(verbose);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
template<class Face>
|
||||
bool Foam::MeshedSurface<Face>::stitchFaces
|
||||
(
|
||||
const scalar tol,
|
||||
const bool verbose
|
||||
)
|
||||
{
|
||||
pointField& pointLst = points();
|
||||
|
||||
@ -58,14 +63,14 @@ bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "meshedSurface::stitchFaces : Renumbering all faces"
|
||||
Info<< "MeshedSurface::stitchFaces : Renumbering all faces"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// Set the coordinates to the merged ones
|
||||
pointLst.transfer(newPoints);
|
||||
|
||||
List<FaceType>& faceLst = faces();
|
||||
List<Face>& faceLst = faces();
|
||||
|
||||
// ensure we have at some patches, and they cover all the faces
|
||||
checkPatches();
|
||||
@ -83,7 +88,7 @@ bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
label patchEnd = oldFaceI + p.size();
|
||||
for (; oldFaceI < patchEnd; ++oldFaceI)
|
||||
{
|
||||
FaceType& f = faceLst[oldFaceI];
|
||||
Face& f = faceLst[oldFaceI];
|
||||
forAll (f, fp)
|
||||
{
|
||||
f[fp] = pointMap[f[fp]];
|
||||
@ -99,7 +104,7 @@ bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
}
|
||||
else if (verbose)
|
||||
{
|
||||
Pout<< "meshedSurface::stitchFaces : "
|
||||
Pout<< "MeshedSurface::stitchFaces : "
|
||||
<< "Removing collapsed face " << oldFaceI << endl
|
||||
<< " vertices :" << f << endl;
|
||||
}
|
||||
@ -113,7 +118,7 @@ bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
Pout<< "meshedSurface::stitchFaces : "
|
||||
Pout<< "MeshedSurface::stitchFaces : "
|
||||
<< "Removed " << faceLst.size() - newFaceI
|
||||
<< " faces" << endl;
|
||||
}
|
||||
@ -122,7 +127,7 @@ bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
|
||||
|
||||
// Merging points might have changed geometric factors
|
||||
clearOut();
|
||||
ParentType::clearOut();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -130,23 +135,24 @@ bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
|
||||
|
||||
// Remove badly degenerate faces and double faces.
|
||||
void Foam::meshedSurface::checkFaces(const bool verbose)
|
||||
template<class Face>
|
||||
void Foam::MeshedSurface<Face>::checkFaces(const bool verbose)
|
||||
{
|
||||
// Simple check on indices ok.
|
||||
const label maxPointI = points().size() - 1;
|
||||
|
||||
List<FaceType>& faceLst = faces();
|
||||
List<Face>& faceLst = faces();
|
||||
|
||||
// Phase 0: detect badly labelled faces
|
||||
forAll (faceLst, faceI)
|
||||
{
|
||||
const FaceType& f = faceLst[faceI];
|
||||
const Face& f = faceLst[faceI];
|
||||
|
||||
forAll (f, fp)
|
||||
{
|
||||
if (f[fp] < 0 || f[fp] > maxPointI)
|
||||
{
|
||||
FatalErrorIn("meshedSurface::checkFaces(bool)")
|
||||
FatalErrorIn("MeshedSurface::checkFaces(bool)")
|
||||
<< "face " << f
|
||||
<< " uses point indices outside point range 0.."
|
||||
<< maxPointI
|
||||
@ -160,7 +166,7 @@ void Foam::meshedSurface::checkFaces(const bool verbose)
|
||||
|
||||
// Phase 1: find and skip over invalid faces
|
||||
// Phase 2: pack
|
||||
const labelListList& fFaces = faceFaces();
|
||||
const labelListList& fFaces = ParentType::faceFaces();
|
||||
|
||||
label oldFaceI = 0;
|
||||
label newFaceI = 0;
|
||||
@ -174,7 +180,7 @@ void Foam::meshedSurface::checkFaces(const bool verbose)
|
||||
label patchEnd = oldFaceI + p.size();
|
||||
for (; oldFaceI < patchEnd; ++oldFaceI)
|
||||
{
|
||||
FaceType& f = faceLst[oldFaceI];
|
||||
Face& f = faceLst[oldFaceI];
|
||||
|
||||
// 'degenerate' face check
|
||||
if (f.collapse() >= 3)
|
||||
@ -203,7 +209,7 @@ void Foam::meshedSurface::checkFaces(const bool verbose)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"meshedSurface::checkFaces(bool verbose)"
|
||||
"MeshedSurface::checkFaces(bool verbose)"
|
||||
) << "faces share the same vertices:\n"
|
||||
<< " face 1 :" << oldFaceI << endl;
|
||||
// printFace(Warning, " ", f, points());
|
||||
@ -232,7 +238,7 @@ void Foam::meshedSurface::checkFaces(const bool verbose)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"meshedSurface::checkFaces(bool verbose)"
|
||||
"MeshedSurface::checkFaces(bool verbose)"
|
||||
) << "face " << oldFaceI
|
||||
<< " has fewer than three unique vertices:\n";
|
||||
// printTriangle(Warning, " ", f, points());
|
||||
@ -249,22 +255,23 @@ void Foam::meshedSurface::checkFaces(const bool verbose)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"meshedSurface::checkFaces(bool verbose)"
|
||||
"MeshedSurface::checkFaces(bool verbose)"
|
||||
) << "Removed " << faceLst.size() - newFaceI
|
||||
<< " illegal faces." << endl;
|
||||
}
|
||||
faceLst.setSize(newFaceI);
|
||||
|
||||
// Topology can change because of renumbering
|
||||
clearOut();
|
||||
ParentType::clearOut();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::meshedSurface::triangulate()
|
||||
template<class Face>
|
||||
Foam::label Foam::MeshedSurface<Face>::triangulate()
|
||||
{
|
||||
label nTri = 0;
|
||||
List<FaceType>& faceLst = faces();
|
||||
List<Face>& faceLst = faces();
|
||||
|
||||
// determine how many triangles are needed
|
||||
forAll (faceLst, faceI)
|
||||
@ -278,7 +285,7 @@ Foam::label Foam::meshedSurface::triangulate()
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<FaceType> newFaces(nTri);
|
||||
List<Face> newFaces(nTri);
|
||||
|
||||
// note the number of *additional* faces
|
||||
nTri -= faceLst.size();
|
||||
@ -296,7 +303,7 @@ Foam::label Foam::meshedSurface::triangulate()
|
||||
label patchEnd = oldFaceI + p.size();
|
||||
for (; oldFaceI < patchEnd; ++oldFaceI)
|
||||
{
|
||||
const FaceType& f = faceLst[oldFaceI];
|
||||
const Face& f = faceLst[oldFaceI];
|
||||
triFace fTri;
|
||||
|
||||
// Do simple face triangulation around f[0].
|
||||
125
src/surfMesh/MeshedSurface/MeshedSurfaceIO.C
Normal file
125
src/surfMesh/MeshedSurface/MeshedSurfaceIO.C
Normal file
@ -0,0 +1,125 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Read surf grouping, points, faces directly from Istream
|
||||
template<class Face>
|
||||
bool Foam::MeshedSurface<Face>::read(Istream& is)
|
||||
{
|
||||
clear();
|
||||
|
||||
// triangulation required?
|
||||
bool mustTriangulate = false;
|
||||
{
|
||||
Face f;
|
||||
if (f.max_size() == 3)
|
||||
{
|
||||
mustTriangulate = true;
|
||||
}
|
||||
}
|
||||
|
||||
List<surfGroup> patchLst(is);
|
||||
|
||||
// copy and set the indices
|
||||
patches_.setSize(patchLst.size());
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
patches_[patchI] = surfGroup
|
||||
(
|
||||
patchLst[patchI],
|
||||
patchI
|
||||
);
|
||||
}
|
||||
|
||||
// read points:
|
||||
is >> points();
|
||||
|
||||
// read faces:
|
||||
// TODO - specialization to triangulate on-the-fly
|
||||
if (mustTriangulate)
|
||||
{
|
||||
is >> faces();
|
||||
}
|
||||
else
|
||||
{
|
||||
is >> faces();
|
||||
}
|
||||
|
||||
return is.good();
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::MeshedSurface<Face>::write(Ostream& os) const
|
||||
{
|
||||
// just emit some information until we get a nice IOobject
|
||||
IOobject::writeBanner(os);
|
||||
os << "// OpenFOAM Surface format" << nl
|
||||
<< "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl
|
||||
<< "// regions:" << nl
|
||||
<< patches_.size() << nl << token::BEGIN_LIST << incrIndent << nl;
|
||||
|
||||
forAll(patches_, patchI)
|
||||
{
|
||||
patches_[patchI].writeDict(os);
|
||||
}
|
||||
os << decrIndent << token::END_LIST << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
|
||||
// Note: Write with global point numbering
|
||||
os << "\n// points:" << nl << points() << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
os << "\n// faces:" << nl << faces() << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
|
||||
// Check state of Ostream
|
||||
os.check("MeshedSurface::write(Ostream&)");
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
surf.write(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,50 +24,49 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// all input is indirect via keyedSurface
|
||||
Foam::autoPtr<Foam::meshedSurface>
|
||||
Foam::meshedSurface::New
|
||||
// all input is indirect via UnsortedMeshedSurface
|
||||
template<class Face>
|
||||
Foam::autoPtr<Foam::MeshedSurface<Face> >
|
||||
Foam::MeshedSurface<Face>::New
|
||||
(
|
||||
const fileName& fName,
|
||||
const word& ext,
|
||||
const bool triangulate
|
||||
const word& ext
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "meshedSurface::New(const fileName&, const word&, const bool) : "
|
||||
"constructing meshedSurface"
|
||||
Info<< "MeshedSurface::New(const fileName&, const word&) : "
|
||||
"constructing MeshedSurface"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// created indirectly via keyedSurface
|
||||
autoPtr<meshedSurface> surf(new meshedSurface);
|
||||
surf().transfer( keyedSurface::New(fName,ext,triangulate)() );
|
||||
// created indirectly via UnsortedMeshedSurface
|
||||
autoPtr<MeshedSurface<Face> > surf(new MeshedSurface<Face>);
|
||||
surf().transfer( UnsortedMeshedSurface<Face>::New(fName,ext)() );
|
||||
|
||||
return surf;
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::meshedSurface>
|
||||
Foam::meshedSurface::New
|
||||
template<class Face>
|
||||
Foam::autoPtr<Foam::MeshedSurface<Face> >
|
||||
Foam::MeshedSurface<Face>::New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "meshedSurface::New(const fileName&, const bool) : "
|
||||
"constructing meshedSurface"
|
||||
Info<< "MeshedSurface::New(const fileName&) : "
|
||||
"constructing MeshedSurface"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return New(fName, fName.ext(), triangulate);
|
||||
return New(fName, fName.ext());
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
52
src/surfMesh/MeshedSurface/MeshedSurfaces.C
Normal file
52
src/surfMesh/MeshedSurface/MeshedSurfaces.C
Normal file
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "MeshedSurfaces.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
#define makeMeshedSurface(faceType) \
|
||||
defineNamedTemplateTypeNameAndDebug \
|
||||
(MeshedSurface<faceType>, 0); \
|
||||
defineTemplatedRunTimeSelectionTable \
|
||||
(MeshedSurface, fileExtension,faceType); \
|
||||
defineTemplatedMemberFunctionSelectionTable \
|
||||
(MeshedSurface, write,fileExtension,faceType);
|
||||
|
||||
|
||||
makeMeshedSurface(face)
|
||||
makeMeshedSurface(triFace)
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
35
src/surfMesh/MeshedSurface/MeshedSurfaces.H
Normal file
35
src/surfMesh/MeshedSurface/MeshedSurfaces.H
Normal file
@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef MeshedSurfaces_H
|
||||
#define MeshedSurfaces_H
|
||||
|
||||
#include "MeshedSurface.H"
|
||||
#include "MeshedSurfacesFwd.H"
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
53
src/surfMesh/MeshedSurface/MeshedSurfacesFwd.H
Normal file
53
src/surfMesh/MeshedSurface/MeshedSurfacesFwd.H
Normal file
@ -0,0 +1,53 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef MeshedSurfacesFwd_H
|
||||
#define MeshedSurfacesFwd_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class face;
|
||||
class triFace;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face> class MeshedSurface;
|
||||
|
||||
typedef MeshedSurface<face> meshedSurface;
|
||||
typedef MeshedSurface<triFace> triMeshedSurface;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
873
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
Normal file
873
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
Normal file
@ -0,0 +1,873 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "Time.H"
|
||||
#include "boundBox.H"
|
||||
#include "polyBoundaryMesh.H"
|
||||
#include "polyMesh.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "SortableList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::fileName Foam::UnsortedMeshedSurface<Face>::triSurfInstance(const Time& d)
|
||||
{
|
||||
return triSurfInstance(d, typeName);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::fileName Foam::UnsortedMeshedSurface<Face>::triSurfName(const Time& d)
|
||||
{
|
||||
return triSurfName(d, typeName);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::canRead
|
||||
(
|
||||
const word& ext,
|
||||
const bool verbose
|
||||
)
|
||||
{
|
||||
// perhaps sent an entire name
|
||||
word fExt(ext);
|
||||
|
||||
string::size_type dot = fExt.find_last_of(".");
|
||||
if (dot != string::npos)
|
||||
{
|
||||
fExt = fExt.substr(dot+1);
|
||||
}
|
||||
|
||||
// handle 'native' format directly
|
||||
if (isNative(fExt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
typename fileExtensionConstructorTable::iterator cstrIter =
|
||||
fileExtensionConstructorTablePtr_->find(fExt);
|
||||
|
||||
// would be nice to have information about which format this actually is
|
||||
if (cstrIter == fileExtensionConstructorTablePtr_->end())
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
SortableList<word> known
|
||||
(
|
||||
fileExtensionConstructorTablePtr_->toc()
|
||||
);
|
||||
|
||||
Info<<"Unknown file extension for reading: " << fExt << nl;
|
||||
// compact output:
|
||||
Info<<"Valid types: ( " << nativeExt;
|
||||
forAll(known, i)
|
||||
{
|
||||
Info<<" " << known[i];
|
||||
}
|
||||
Info<<" )" << endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::canWrite
|
||||
(
|
||||
const word& ext,
|
||||
const bool verbose
|
||||
)
|
||||
{
|
||||
// perhaps sent an entire name
|
||||
word fExt(ext);
|
||||
|
||||
string::size_type dot = ext.find_last_of(".");
|
||||
if (dot != string::npos)
|
||||
{
|
||||
fExt = ext.substr(dot+1);
|
||||
}
|
||||
|
||||
// handle 'native' format directly
|
||||
if (isNative(fExt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
typename writefileExtensionMemberFunctionTable::iterator mfIter =
|
||||
writefileExtensionMemberFunctionTablePtr_->find(fExt);
|
||||
|
||||
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
SortableList<word> known
|
||||
(
|
||||
writefileExtensionMemberFunctionTablePtr_->toc()
|
||||
);
|
||||
|
||||
Info<<"Unknown file extension for writing: " << fExt << nl;
|
||||
// compact output:
|
||||
Info<<"Valid types: ( " << nativeExt;
|
||||
forAll(known, i)
|
||||
{
|
||||
Info<<" " << known[i];
|
||||
}
|
||||
Info<<" )" << endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "UnsortedMeshedSurface::write(const fileName&, const UnsortedMeshedSurface&) : "
|
||||
"writing UnsortedMeshedSurface to " << fName
|
||||
<< endl;
|
||||
}
|
||||
|
||||
const word ext = fName.ext();
|
||||
|
||||
// handle 'native' format directly
|
||||
if (isNative(ext))
|
||||
{
|
||||
surf.write(OFstream(fName)());
|
||||
return;
|
||||
}
|
||||
|
||||
typename writefileExtensionMemberFunctionTable::iterator mfIter =
|
||||
writefileExtensionMemberFunctionTablePtr_->find(ext);
|
||||
|
||||
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"UnsortedMeshedSurface::write"
|
||||
"(const fileName&, const UnsortedMeshedSurface&)"
|
||||
) << "Unknown file extension " << ext << nl << nl
|
||||
<< "Valid types are :" << endl
|
||||
<< writefileExtensionMemberFunctionTablePtr_->toc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
mfIter()(fName, surf);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface()
|
||||
:
|
||||
ParentType(List<Face>(), pointField())
|
||||
{}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>& pointLst,
|
||||
const xfer<List<Face> >& faceLst,
|
||||
const xfer<List<label> >& regionIds,
|
||||
const xfer<surfPatchIdentifierList>& patchLst
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField()),
|
||||
regions_(regionIds),
|
||||
patches_(patchLst)
|
||||
{
|
||||
points().transfer(pointLst());
|
||||
faces().transfer(faceLst());
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>& pointLst,
|
||||
const xfer<List<Face> >& faceLst,
|
||||
const xfer<List<label> >& regionIds,
|
||||
const Map<word>& regionNames
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField()),
|
||||
regions_(regionIds)
|
||||
{
|
||||
faces().transfer(faceLst());
|
||||
points().transfer(pointLst());
|
||||
|
||||
if (®ionNames)
|
||||
{
|
||||
// set patch names from (id => name) mapping
|
||||
setPatches(regionNames);
|
||||
}
|
||||
else
|
||||
{
|
||||
// find highest region ID and set patch names automatically
|
||||
setPatches();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>& pointLst,
|
||||
const xfer<List<Face> >& faceLst,
|
||||
const xfer<List<label> >& regionIds,
|
||||
const HashTable<label>& labelToRegion
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField()),
|
||||
regions_(regionIds)
|
||||
{
|
||||
points().transfer(pointLst());
|
||||
faces().transfer(faceLst());
|
||||
|
||||
// set patch names from (name => id) mapping
|
||||
setPatches(labelToRegion);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>& pointLst,
|
||||
const xfer<List<Face> >& faceLst
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField()),
|
||||
regions_(faceLst().size(), 0), // single default patch
|
||||
patches_()
|
||||
{
|
||||
points().transfer(pointLst());
|
||||
faces().transfer(faceLst());
|
||||
|
||||
setPatches(0);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const polyBoundaryMesh& bMesh,
|
||||
const bool useGlobalPoints
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField())
|
||||
{
|
||||
const polyMesh& mesh = bMesh.mesh();
|
||||
const polyPatchList& bPatches = bMesh;
|
||||
const label nIntFaces = mesh.nInternalFaces();
|
||||
|
||||
List<PatchRegionType> newPatches(bPatches.size());
|
||||
|
||||
// Get patch for all of outside
|
||||
primitivePatch allBoundary
|
||||
(
|
||||
SubList<Face>
|
||||
(
|
||||
mesh.faces(),
|
||||
mesh.nFaces() - nIntFaces,
|
||||
nIntFaces
|
||||
),
|
||||
mesh.points()
|
||||
);
|
||||
|
||||
List<Face> newFaces(allBoundary.size());
|
||||
List<label> newRegions(allBoundary.size());
|
||||
|
||||
if (useGlobalPoints)
|
||||
{
|
||||
// copy in the global points
|
||||
points() = mesh.points();
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy in the local points
|
||||
points() = allBoundary.localPoints();
|
||||
}
|
||||
|
||||
// global or local face addressing
|
||||
const List<Face>& bfaces =
|
||||
(
|
||||
useGlobalPoints
|
||||
? allBoundary
|
||||
: allBoundary.localFaces()
|
||||
);
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(bPatches, patchI)
|
||||
{
|
||||
const polyPatch& p = bPatches[patchI];
|
||||
|
||||
newPatches[patchI] = PatchRegionType
|
||||
(
|
||||
bPatches[patchI].name(),
|
||||
patchI
|
||||
);
|
||||
|
||||
forAll(p, patchFaceI)
|
||||
{
|
||||
newFaces[faceIndex] = bfaces[faceIndex];
|
||||
newRegions[faceIndex] = patchI;
|
||||
faceIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
faces().transfer(newFaces);
|
||||
regions_.transfer(newRegions);
|
||||
patches_.transfer(newPatches);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), surf.points())
|
||||
{
|
||||
const List<Face>& origFaces = surf.faces();
|
||||
const surfGroupList& patchLst = surf.patches();
|
||||
|
||||
List<Face> newFaces(origFaces.size());
|
||||
List<label> newRegions(origFaces.size());
|
||||
List<PatchRegionType> newPatches(patchLst.size());
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
newPatches[patchI] = patchLst[patchI];
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
newFaces[faceIndex] = origFaces[faceIndex];
|
||||
newRegions[faceIndex] = patchI;
|
||||
faceIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
faces().transfer(newFaces);
|
||||
regions_.transfer(newRegions);
|
||||
patches_.transfer(newPatches);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const fileName& fName,
|
||||
const word& ext
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField())
|
||||
{
|
||||
read(fName, ext);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField())
|
||||
{
|
||||
read(fName, fName.ext());
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
Istream& is
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField())
|
||||
{
|
||||
read(is);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const Time& d)
|
||||
:
|
||||
ParentType(List<Face>(), pointField())
|
||||
{
|
||||
read(IFstream(triSurfName(d))());
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
:
|
||||
ParentType(surf.faces(), surf.points()),
|
||||
regions_(surf.regions_),
|
||||
patches_(surf.patches_)
|
||||
{}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<UnsortedMeshedSurface<Face> >& surf
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField()),
|
||||
regions_(),
|
||||
patches_()
|
||||
{
|
||||
transfer(surf());
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<MeshedSurface<Face> >& surf
|
||||
)
|
||||
:
|
||||
ParentType(List<Face>(), pointField()),
|
||||
regions_(),
|
||||
patches_()
|
||||
{
|
||||
transfer(surf());
|
||||
}
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face>::~UnsortedMeshedSurface()
|
||||
{}
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::setPatches(const label maxPatch)
|
||||
{
|
||||
patches_.setSize(maxPatch+1);
|
||||
|
||||
forAll(patches_, patchI)
|
||||
{
|
||||
patches_[patchI] = PatchRegionType
|
||||
(
|
||||
"patch" + ::Foam::name(patchI),
|
||||
patchI
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::setPatches()
|
||||
{
|
||||
label maxPatch = 0;
|
||||
|
||||
// find the max region that occurs
|
||||
forAll(regions_, faceI)
|
||||
{
|
||||
const label regId = regions_[faceI];
|
||||
|
||||
if (maxPatch < regId)
|
||||
{
|
||||
maxPatch = regId;
|
||||
}
|
||||
}
|
||||
|
||||
setPatches(maxPatch);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::setPatches
|
||||
(
|
||||
const Map<word>& regionNames,
|
||||
const label maxPatchHint
|
||||
)
|
||||
{
|
||||
label maxPatch = maxPatchHint;
|
||||
|
||||
// determine max patch ID if required
|
||||
if (maxPatchHint < 0)
|
||||
{
|
||||
maxPatch = 0;
|
||||
forAllConstIter(Map<word>, regionNames, iter)
|
||||
{
|
||||
if (maxPatch < iter.key())
|
||||
{
|
||||
maxPatch = iter.key();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Info<< "setPatches with maxPatch: " << maxPatch << endl;
|
||||
|
||||
patches_.setSize(maxPatch+1);
|
||||
|
||||
forAll(patches_, patchI)
|
||||
{
|
||||
Map<word>::const_iterator findPatch = regionNames.find(patchI);
|
||||
word patchName;
|
||||
|
||||
if (findPatch != regionNames.end())
|
||||
{
|
||||
patchName = findPatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
patchName = "patch" + ::Foam::name(patchI);
|
||||
}
|
||||
|
||||
patches_[patchI] = PatchRegionType
|
||||
(
|
||||
patchName,
|
||||
patchI
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::setPatches
|
||||
(
|
||||
const HashTable<label>& groupToPatch
|
||||
)
|
||||
{
|
||||
// determine max patch Id
|
||||
label maxPatch = 0;
|
||||
Map<word> regionNames;
|
||||
|
||||
forAllConstIter(HashTable<label>, groupToPatch, iter)
|
||||
{
|
||||
regionNames.insert(iter(), iter.key());
|
||||
if (maxPatch < iter())
|
||||
{
|
||||
maxPatch = iter();
|
||||
}
|
||||
}
|
||||
|
||||
setPatches(regionNames, maxPatch);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::setSize(const label s)
|
||||
{
|
||||
ParentType::setSize(s);
|
||||
regions_.setSize(s);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::clear()
|
||||
{
|
||||
ParentType::clearOut();
|
||||
|
||||
points().clear();
|
||||
faces().clear();
|
||||
regions_.clear();
|
||||
patches_.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::surfGroupList Foam::UnsortedMeshedSurface<Face>::sortedRegions
|
||||
(
|
||||
labelList& faceMap
|
||||
) const
|
||||
{
|
||||
// supply some patch names
|
||||
Map<word> patchNames;
|
||||
forAll(patches_, patchI)
|
||||
{
|
||||
patchNames.insert(patchI, patches_[patchI].name());
|
||||
}
|
||||
|
||||
return sortedPatchRegions(regions_, patchNames, faceMap);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::movePoints(const pointField& newPoints)
|
||||
{
|
||||
// Remove all geometry dependent data
|
||||
ParentType::clearTopology();
|
||||
|
||||
// Adapt for new point position
|
||||
ParentType::movePoints(newPoints);
|
||||
|
||||
// Copy new points
|
||||
points() = newPoints;
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::scalePoints(const scalar& scaleFactor)
|
||||
{
|
||||
// avoid bad scaling
|
||||
if (scaleFactor > 0 && scaleFactor != 1.0)
|
||||
{
|
||||
// Remove all geometry dependent data
|
||||
ParentType::clearTopology();
|
||||
|
||||
// Adapt for new point position
|
||||
ParentType::movePoints(pointField());
|
||||
|
||||
points() *= scaleFactor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::UnsortedMeshedSurface<Face> Foam::UnsortedMeshedSurface<Face>::subsetMesh
|
||||
(
|
||||
const UList<bool>& include,
|
||||
labelList& pointMap,
|
||||
labelList& faceMap
|
||||
) const
|
||||
{
|
||||
const pointField& locPoints = ParentType::localPoints();
|
||||
const List<Face>& locFaces = ParentType::localFaces();
|
||||
|
||||
// Fill pointMap, faceMap
|
||||
ParentType::subsetMap(include, pointMap, faceMap);
|
||||
|
||||
// Create compact coordinate list and forward mapping array
|
||||
pointField newPoints(pointMap.size());
|
||||
labelList oldToNew(locPoints.size());
|
||||
forAll(pointMap, pointI)
|
||||
{
|
||||
newPoints[pointI] = locPoints[pointMap[pointI]];
|
||||
oldToNew[pointMap[pointI]] = pointI;
|
||||
}
|
||||
|
||||
// Renumber face node labels and compact
|
||||
List<Face> newFaces(faceMap.size());
|
||||
|
||||
forAll(faceMap, faceI)
|
||||
{
|
||||
// Get old vertex labels
|
||||
const Face& oldFace = locFaces[faceMap[faceI]];
|
||||
|
||||
newFaces[faceI] = Face(oldFace);
|
||||
|
||||
// Renumber labels for face
|
||||
Face& f = newFaces[faceI];
|
||||
forAll(f, fp)
|
||||
{
|
||||
f[fp] = oldToNew[oldFace[fp]];
|
||||
}
|
||||
}
|
||||
|
||||
// construct a sub-surface
|
||||
UnsortedMeshedSurface<Face> subSurf;
|
||||
(
|
||||
xferMove(newPoints),
|
||||
xferMove(newFaces),
|
||||
xferCopy(patches_)
|
||||
);
|
||||
|
||||
return subSurf;
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::transfer
|
||||
(
|
||||
UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
clear();
|
||||
|
||||
faces().transfer(surf.faces());
|
||||
points().transfer(surf.points());
|
||||
regions_.transfer(surf.regions_);
|
||||
patches_.transfer(surf.patches_);
|
||||
|
||||
surf.clear();
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::transfer
|
||||
(
|
||||
MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
surfGroupList& patchLst = surf.patches();
|
||||
|
||||
clear();
|
||||
|
||||
points().transfer(surf.points());
|
||||
faces().transfer(surf.faces());
|
||||
regions_.setSize(size());
|
||||
patches_.setSize(patchLst.size());
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
// copy info
|
||||
patches_[patchI] = patchLst[patchI];
|
||||
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
regions_[faceIndex++] = patchI;
|
||||
}
|
||||
}
|
||||
|
||||
patchLst.clear();
|
||||
surf.clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Read from file in given format
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
clear();
|
||||
const word ext = fName.ext();
|
||||
|
||||
// handle 'native' format directly
|
||||
if (isNative(ext))
|
||||
{
|
||||
return read(IFstream(fName)());
|
||||
}
|
||||
else
|
||||
{
|
||||
// use selector mechanism
|
||||
transfer(New(fName, ext)());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Read from file in given format
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::read
|
||||
(
|
||||
const fileName& fName,
|
||||
const word& ext
|
||||
)
|
||||
{
|
||||
clear();
|
||||
|
||||
// handle 'native' format directly
|
||||
if (isNative(ext))
|
||||
{
|
||||
return read(IFstream(fName)());
|
||||
}
|
||||
else
|
||||
{
|
||||
// use selector mechanism
|
||||
transfer(New(fName, ext)());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::write(const Time& d) const
|
||||
{
|
||||
write(OFstream(triSurfName(d))());
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::writeStats(Ostream& os) const
|
||||
{
|
||||
// os << "Faces : " << size() << endl
|
||||
// << "Edges : " << nEdges() << endl
|
||||
// << "Vertices : " << nPoints() << endl
|
||||
// << "Bounding Box : " << boundBox(localPoints(), false) << endl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::operator=
|
||||
(
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
clear();
|
||||
faces() = surf.faces();
|
||||
points() = surf.points();
|
||||
regions_ = surf.regions_;
|
||||
patches_ = surf.patches_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "UnsortedMeshedSurfaceCleanup.C"
|
||||
#include "UnsortedMeshedSurfaceIO.C"
|
||||
#include "UnsortedMeshedSurfaceNew.C"
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::keyedSurface
|
||||
Foam::UnsortedMeshedSurface
|
||||
|
||||
Description
|
||||
A surface geometry mesh, in which the patch information is conveyed by
|
||||
@ -40,21 +40,22 @@ See Also
|
||||
with independent patch information.
|
||||
|
||||
SourceFiles
|
||||
keyedSurface.C
|
||||
UnsortedMeshedSurface.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef keyedSurface_H
|
||||
#define keyedSurface_H
|
||||
#ifndef UnsortedMeshedSurface_H
|
||||
#define UnsortedMeshedSurface_H
|
||||
|
||||
#include "pointField.H"
|
||||
#include "PrimitivePatchExtra.H"
|
||||
#include "boolList.H"
|
||||
#include "surfPatchIdentifierList.H"
|
||||
#include "surfGroupList.H"
|
||||
#include "face.H"
|
||||
#include "Keyed.H"
|
||||
#include "surfaceFormatsCore.H"
|
||||
#include "xfer.H"
|
||||
#include "face.H"
|
||||
#include "triFace.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "memberFunctionSelectionTables.H"
|
||||
|
||||
@ -67,49 +68,46 @@ namespace Foam
|
||||
|
||||
class Time;
|
||||
class IFstream;
|
||||
class keyedSurface;
|
||||
class meshedSurface;
|
||||
template<class Face> class UnsortedMeshedSurface;
|
||||
template<class Face> class MeshedSurface;
|
||||
|
||||
class polyBoundaryMesh;
|
||||
|
||||
// Istream& operator>>(Istream&, keyedSurface&);
|
||||
Ostream& operator<<(Ostream&, const keyedSurface&);
|
||||
template<class Face>
|
||||
Ostream& operator<<(Ostream&, const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class keyedSurface Declaration
|
||||
Class UnsortedMeshedSurface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class keyedSurface
|
||||
template<class Face>
|
||||
class UnsortedMeshedSurface
|
||||
:
|
||||
public PrimitivePatchExtra<face, ::Foam::List, pointField, point>
|
||||
public PrimitivePatchExtra<Face, ::Foam::List, pointField, point>,
|
||||
public fileFormats::surfaceFormatsCore
|
||||
{
|
||||
friend class meshedSurface;
|
||||
friend class MeshedSurface<Face>;
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Data
|
||||
|
||||
//- Typedef if this type has not already been defined
|
||||
typedef Keyed<face> keyedFace;
|
||||
|
||||
//- Typedef for similar code in keyedSurface and meshedSurface
|
||||
typedef face FaceType;
|
||||
|
||||
//- Typedef for type holding the region (patch) informationm
|
||||
typedef surfPatchIdentifier PatchRegionType;
|
||||
|
||||
private:
|
||||
|
||||
// Private typedefs
|
||||
|
||||
//- Private typedefs for convenience
|
||||
typedef UnsortedMeshedSurface<Face> ThisType;
|
||||
typedef PrimitivePatchExtra
|
||||
<
|
||||
FaceType,
|
||||
Face,
|
||||
::Foam::List,
|
||||
pointField,
|
||||
point
|
||||
>
|
||||
MeshStorage;
|
||||
ParentType;
|
||||
|
||||
// Private Member Data
|
||||
|
||||
@ -122,19 +120,16 @@ private:
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Read OpenFOAM Surface format
|
||||
bool read(Istream&, const bool triangulate=false);
|
||||
|
||||
//- Disable setSize with value
|
||||
void setSize(const label, const FaceType&);
|
||||
void setSize(const label, const Face&);
|
||||
|
||||
//- Read OpenFOAM Surface format
|
||||
bool read(Istream&);
|
||||
|
||||
protected:
|
||||
|
||||
// Static protected functions
|
||||
|
||||
//- Read non-comment line
|
||||
static string getLineNoComment(IFstream&);
|
||||
|
||||
// Protected Member functions
|
||||
|
||||
//- Sets default patch names based on the maximum patch number
|
||||
@ -156,13 +151,13 @@ protected:
|
||||
//- Return non-const access to global points
|
||||
pointField& points()
|
||||
{
|
||||
return const_cast<pointField&>(MeshStorage::points());
|
||||
return const_cast<pointField&>(ParentType::points());
|
||||
}
|
||||
|
||||
//- Return non-const access to the faces
|
||||
List<FaceType>& faces()
|
||||
List<Face>& faces()
|
||||
{
|
||||
return static_cast<List<FaceType> &>(*this);
|
||||
return static_cast<List<Face> &>(*this);
|
||||
}
|
||||
|
||||
//- Return non-const access to the region Ids
|
||||
@ -174,135 +169,129 @@ protected:
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
ClassName("keyedSurface");
|
||||
TypeName("UnsortedMeshedSurface");
|
||||
|
||||
// Static
|
||||
|
||||
//- Name of keyedSurface directory to use.
|
||||
//- Name of UnsortedMeshedSurface directory to use.
|
||||
static fileName triSurfInstance(const Time&);
|
||||
|
||||
//- Name of keyedSurface directory to use.
|
||||
//- Name of UnsortedMeshedSurface directory to use.
|
||||
static fileName triSurfName(const Time&);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const word& ext, const bool verbose=false);
|
||||
|
||||
//- Can we write this file format?
|
||||
static bool canWrite(const word& ext, const bool verbose=false);
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
keyedSurface();
|
||||
UnsortedMeshedSurface();
|
||||
|
||||
//- Construct by transferring components
|
||||
// (points, faces, region ids, patches).
|
||||
keyedSurface
|
||||
UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&,
|
||||
const xfer<List<Face> >&,
|
||||
const xfer<List<label> >& regionIds,
|
||||
const xfer<surfPatchIdentifierList>&
|
||||
);
|
||||
|
||||
//- Construct by transferring points, faces and regionIds
|
||||
// with region names per map or set to default.
|
||||
keyedSurface
|
||||
UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&,
|
||||
const xfer<List<Face> >&,
|
||||
const xfer<List<label> >& regionIds,
|
||||
const Map<word>& regionNames = Map<word>::null()
|
||||
);
|
||||
|
||||
//- Construct by transferring points, faces and regionIds
|
||||
// with patch-names from hash
|
||||
keyedSurface
|
||||
UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&,
|
||||
const xfer<List<Face> >&,
|
||||
const xfer<List<label> >& regionIds,
|
||||
const HashTable<label>& labelToRegion
|
||||
);
|
||||
|
||||
//- Construct by transferring points, faces.
|
||||
// Set single default patch.
|
||||
keyedSurface
|
||||
UnsortedMeshedSurface
|
||||
(
|
||||
const xfer<pointField>&,
|
||||
const xfer<List<face> >&
|
||||
const xfer<List<Face> >&
|
||||
);
|
||||
|
||||
#if 0
|
||||
//- Construct from a boundary mesh with local points/faces
|
||||
keyedSurface
|
||||
UnsortedMeshedSurface
|
||||
(
|
||||
const polyBoundaryMesh&,
|
||||
const bool globalPoints=false
|
||||
);
|
||||
#endif
|
||||
|
||||
//- Construct from a meshedSurface
|
||||
keyedSurface(const meshedSurface&);
|
||||
UnsortedMeshedSurface(const MeshedSurface<Face>&);
|
||||
|
||||
//- Construct by transferring the contents from a keyedSurface
|
||||
keyedSurface(const xfer<keyedSurface>&);
|
||||
//- Construct by transferring the contents from a UnsortedMeshedSurface
|
||||
UnsortedMeshedSurface(const xfer<UnsortedMeshedSurface<Face> >&);
|
||||
|
||||
//- Construct by transferring the contents from a meshedSurface
|
||||
keyedSurface(const xfer<meshedSurface>&);
|
||||
|
||||
UnsortedMeshedSurface(const xfer<MeshedSurface<Face> >&);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
keyedSurface
|
||||
(
|
||||
const fileName&,
|
||||
const bool triangulate=false
|
||||
);
|
||||
UnsortedMeshedSurface(const fileName&);
|
||||
|
||||
//- Construct from file name (uses extension to determine type)
|
||||
keyedSurface
|
||||
(
|
||||
const fileName&,
|
||||
const word&,
|
||||
const bool triangulate=false
|
||||
);
|
||||
UnsortedMeshedSurface(const fileName&, const word&);
|
||||
|
||||
//- Construct from Istream
|
||||
keyedSurface(Istream&, const bool triangulate=false);
|
||||
UnsortedMeshedSurface(Istream&);
|
||||
|
||||
//- Construct from objectRegistry
|
||||
keyedSurface(const Time&);
|
||||
UnsortedMeshedSurface(const Time&);
|
||||
|
||||
//- Construct as copy
|
||||
keyedSurface(const keyedSurface&);
|
||||
|
||||
UnsortedMeshedSurface(const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
keyedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
fileExtension,
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
),
|
||||
(fName, triangulate)
|
||||
(fName)
|
||||
);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select constructed from filename (implicit extension)
|
||||
static autoPtr<keyedSurface> New
|
||||
static autoPtr<UnsortedMeshedSurface> New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=false
|
||||
const fileName&
|
||||
);
|
||||
|
||||
//- Select constructed from filename (explicit extension)
|
||||
static autoPtr<keyedSurface> New
|
||||
static autoPtr<UnsortedMeshedSurface> New
|
||||
(
|
||||
const fileName& fName,
|
||||
const word& ext,
|
||||
const bool triangulate=false
|
||||
const fileName&,
|
||||
const word& ext
|
||||
);
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~keyedSurface();
|
||||
virtual ~UnsortedMeshedSurface();
|
||||
|
||||
|
||||
// Member Function Selectors
|
||||
@ -310,24 +299,18 @@ public:
|
||||
declareMemberFunctionSelectionTable
|
||||
(
|
||||
void,
|
||||
keyedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
write,
|
||||
fileExtension,
|
||||
(
|
||||
const fileName& fName,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
),
|
||||
(fName, surf)
|
||||
);
|
||||
|
||||
//- Write to file
|
||||
static void write(const fileName&, const keyedSurface&);
|
||||
|
||||
//- Can we read this file format?
|
||||
static bool canRead(const word& ext, const bool verbose=false);
|
||||
|
||||
//- Can we write this file format?
|
||||
static bool canWrite(const word& ext, const bool verbose=false);
|
||||
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -343,13 +326,13 @@ public:
|
||||
//- Return the number of faces
|
||||
label nFaces() const
|
||||
{
|
||||
return MeshStorage::size();
|
||||
return ParentType::size();
|
||||
}
|
||||
|
||||
//- The surface size is the number of faces
|
||||
label size() const
|
||||
{
|
||||
return MeshStorage::size();
|
||||
return ParentType::size();
|
||||
}
|
||||
|
||||
//- Reset size of face and region list
|
||||
@ -358,13 +341,13 @@ public:
|
||||
//- Return const access to global points
|
||||
const pointField& points() const
|
||||
{
|
||||
return MeshStorage::points();
|
||||
return ParentType::points();
|
||||
}
|
||||
|
||||
//- Return const access to the faces
|
||||
const List<FaceType>& faces() const
|
||||
const List<Face>& faces() const
|
||||
{
|
||||
return static_cast<const List<FaceType> &>(*this);
|
||||
return static_cast<const List<Face> &>(*this);
|
||||
}
|
||||
|
||||
//- Return const access to the regions
|
||||
@ -383,65 +366,56 @@ public:
|
||||
return patches_;
|
||||
}
|
||||
|
||||
//- Determine the sort order from the region list.
|
||||
// Returns patch list and sets faceMap to indices within faceLst
|
||||
static surfGroupList sortedRegions
|
||||
(
|
||||
const List<label>& regionLst,
|
||||
const Map<word>& patchNames,
|
||||
labelList& faceMap
|
||||
);
|
||||
|
||||
//- Sort faces according to region.
|
||||
// Returns patch list and sets faceMap to index within faces()
|
||||
surfGroupList sortedRegions(labelList& faceMap) const;
|
||||
|
||||
// Edit
|
||||
|
||||
//- Clear all storage
|
||||
virtual void clear();
|
||||
|
||||
//- Move points
|
||||
virtual void movePoints(const pointField&);
|
||||
|
||||
//- Scale points. A non-positive factor is ignored
|
||||
virtual void scalePoints(const scalar&);
|
||||
|
||||
//- Triangulate the surface, return the number of added faces.
|
||||
label triangulate();
|
||||
//- Remove invalid faces
|
||||
void cleanup(const bool verbose);
|
||||
|
||||
//- Check/fix duplicate/degenerate faces
|
||||
void checkFaces(const bool verbose);
|
||||
|
||||
//- Join the faces by removing duplicate points.
|
||||
// Returns true if any points merged
|
||||
bool stitchFaces(const scalar tol=SMALL, const bool verbose=false);
|
||||
|
||||
//- Check/fix duplicate/degenerate faces
|
||||
void checkFaces(const bool verbose);
|
||||
|
||||
//- Remove invalid faces
|
||||
void cleanup(const bool verbose);
|
||||
//- Triangulate the surface, return the number of added faces.
|
||||
label triangulate();
|
||||
|
||||
//- Return new surface. Returns pointMap, faceMap from
|
||||
// subsetMeshMap
|
||||
keyedSurface subsetMesh
|
||||
UnsortedMeshedSurface subsetMesh
|
||||
(
|
||||
const boolList& include,
|
||||
const UList<bool>& include,
|
||||
labelList& pointMap,
|
||||
labelList& faceMap
|
||||
) const;
|
||||
|
||||
//- Transfer the contents of the argument and annull the argument
|
||||
void transfer(keyedSurface&);
|
||||
void transfer(UnsortedMeshedSurface<Face>&);
|
||||
|
||||
//- Transfer the contents of the argument and annull the argument
|
||||
void transfer(meshedSurface&);
|
||||
void transfer(MeshedSurface<Face>&);
|
||||
|
||||
// Read
|
||||
|
||||
//- Read from file. Chooses reader based on extension
|
||||
bool read
|
||||
(
|
||||
const fileName&,
|
||||
const word& ext,
|
||||
const bool triangulate=false
|
||||
);
|
||||
//- Read from file. Chooses reader based on explicit extension
|
||||
bool read(const fileName&, const word& ext);
|
||||
|
||||
//- Read from file. Chooses reader based on detected extension
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
// Write
|
||||
|
||||
@ -463,13 +437,17 @@ public:
|
||||
|
||||
// Member operators
|
||||
|
||||
void operator=(const keyedSurface&);
|
||||
void operator=(const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
|
||||
// Ostream Operator
|
||||
|
||||
// friend Istream& operator>>(Istream&, keyedSurface&);
|
||||
friend Ostream& operator<<(Ostream&, const keyedSurface&);
|
||||
friend Ostream& operator<<
|
||||
<Face>
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
@ -480,6 +458,12 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "UnsortedMeshedSurface.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,24 +24,29 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "keyedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "mergePoints.H"
|
||||
#include "triFace.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Remove badly degenerate faces, double faces.
|
||||
void Foam::keyedSurface::cleanup(const bool verbose)
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::cleanup(const bool verbose)
|
||||
{
|
||||
// merge points (already done for STL, TRI)
|
||||
stitchFaces(SMALL, verbose);
|
||||
|
||||
checkFaces(verbose);
|
||||
checkEdges(verbose);
|
||||
ParentType::checkEdges(verbose);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::keyedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::stitchFaces
|
||||
(
|
||||
const scalar tol,
|
||||
const bool verbose
|
||||
)
|
||||
{
|
||||
pointField& pointLst = points();
|
||||
|
||||
@ -58,20 +63,20 @@ bool Foam::keyedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "keyedSurface::stitchFaces : Renumbering all faces"
|
||||
Info<< "UnsortedMeshedSurface::stitchFaces : Renumbering all faces"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// Set the coordinates to the merged ones
|
||||
pointLst.transfer(newPoints);
|
||||
|
||||
List<FaceType>& faceLst = faces();
|
||||
List<Face>& faceLst = faces();
|
||||
|
||||
// Reset the point labels to the unique points array
|
||||
label newFaceI = 0;
|
||||
forAll (faceLst, faceI)
|
||||
{
|
||||
FaceType& f = faceLst[faceI];
|
||||
Face& f = faceLst[faceI];
|
||||
forAll (f, fp)
|
||||
{
|
||||
f[fp] = pointMap[f[fp]];
|
||||
@ -88,7 +93,7 @@ bool Foam::keyedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
}
|
||||
else if (verbose)
|
||||
{
|
||||
Pout<< "keyedSurface::stitchFaces : "
|
||||
Pout<< "UnsortedMeshedSurface::stitchFaces : "
|
||||
<< "Removing collapsed face " << faceI << endl
|
||||
<< " vertices :" << f << endl;
|
||||
}
|
||||
@ -98,7 +103,7 @@ bool Foam::keyedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
Pout<< "keyedSurface::stitchFaces : "
|
||||
Pout<< "UnsortedMeshedSurface::stitchFaces : "
|
||||
<< "Removed " << faceLst.size() - newFaceI
|
||||
<< " faces" << endl;
|
||||
}
|
||||
@ -107,30 +112,31 @@ bool Foam::keyedSurface::stitchFaces(const scalar tol, const bool verbose)
|
||||
}
|
||||
|
||||
// Merging points might have changed geometric factors
|
||||
clearOut();
|
||||
ParentType::clearOut();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Remove badly degenerate faces and double faces.
|
||||
void Foam::keyedSurface::checkFaces(const bool verbose)
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::checkFaces(const bool verbose)
|
||||
{
|
||||
// Simple check on indices ok.
|
||||
const label maxPointI = points().size() - 1;
|
||||
|
||||
List<FaceType>& faceLst = faces();
|
||||
List<Face>& faceLst = faces();
|
||||
|
||||
// Phase 0: detect badly labelled faces
|
||||
forAll (faceLst, faceI)
|
||||
{
|
||||
const FaceType& f = faceLst[faceI];
|
||||
const Face& f = faceLst[faceI];
|
||||
|
||||
forAll (f, fp)
|
||||
{
|
||||
if (f[fp] < 0 || f[fp] > maxPointI)
|
||||
{
|
||||
FatalErrorIn("keyedSurface::checkFaces(bool)")
|
||||
FatalErrorIn("UnsortedMeshedSurface::checkFaces(bool)")
|
||||
<< "face " << f
|
||||
<< " uses point indices outside point range 0.."
|
||||
<< maxPointI
|
||||
@ -142,12 +148,12 @@ void Foam::keyedSurface::checkFaces(const bool verbose)
|
||||
// Phase 1: mark invalid faces
|
||||
// Phase 1: pack
|
||||
// Done to keep numbering constant in phase 1
|
||||
const labelListList& fFaces = faceFaces();
|
||||
const labelListList& fFaces = ParentType::faceFaces();
|
||||
label newFaceI = 0;
|
||||
|
||||
forAll (faceLst, faceI)
|
||||
{
|
||||
FaceType& f = faceLst[faceI];
|
||||
Face& f = faceLst[faceI];
|
||||
|
||||
// avoid degenerate faces
|
||||
if (f.collapse() >= 3)
|
||||
@ -176,7 +182,7 @@ void Foam::keyedSurface::checkFaces(const bool verbose)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"keyedSurface::checkFaces(bool verbose)"
|
||||
"UnsortedMeshedSurface::checkFaces(bool verbose)"
|
||||
) << "faces share the same vertices:\n"
|
||||
<< " face 1 :" << faceI << endl;
|
||||
// printFace(Warning, " ", f, points());
|
||||
@ -206,7 +212,7 @@ void Foam::keyedSurface::checkFaces(const bool verbose)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"keyedSurface::checkFaces(bool verbose)"
|
||||
"UnsortedMeshedSurface::checkFaces(bool verbose)"
|
||||
) << "face " << faceI
|
||||
<< " does not at least three unique vertices:\n";
|
||||
// printFace(Warning, " ", f, points());
|
||||
@ -219,7 +225,7 @@ void Foam::keyedSurface::checkFaces(const bool verbose)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"keyedSurface::checkFaces(bool verbose)"
|
||||
"UnsortedMeshedSurface::checkFaces(bool verbose)"
|
||||
) << "Removed " << faceLst.size() - newFaceI
|
||||
<< " illegal faces." << endl;
|
||||
}
|
||||
@ -227,15 +233,16 @@ void Foam::keyedSurface::checkFaces(const bool verbose)
|
||||
regions_.setSize(newFaceI);
|
||||
|
||||
// Topology can change because of renumbering
|
||||
clearOut();
|
||||
ParentType::clearOut();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::keyedSurface::triangulate()
|
||||
template<class Face>
|
||||
Foam::label Foam::UnsortedMeshedSurface<Face>::triangulate()
|
||||
{
|
||||
label nTri = 0;
|
||||
List<FaceType>& faceLst = faces();
|
||||
List<Face>& faceLst = faces();
|
||||
|
||||
// determine how many triangles are needed
|
||||
forAll (faceLst, faceI)
|
||||
@ -249,8 +256,8 @@ Foam::label Foam::keyedSurface::triangulate()
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<FaceType> newFaces(nTri);
|
||||
List<label> newRegions(nTri);
|
||||
List<Face> newFaces(nTri);
|
||||
List<label> newRegions(nTri);
|
||||
|
||||
// note the number of *additional* faces
|
||||
nTri -= faceLst.size();
|
||||
@ -259,7 +266,7 @@ Foam::label Foam::keyedSurface::triangulate()
|
||||
label newFaceI = 0;
|
||||
forAll (faceLst, faceI)
|
||||
{
|
||||
const FaceType& f = faceLst[faceI];
|
||||
const Face& f = faceLst[faceI];
|
||||
triFace fTri;
|
||||
|
||||
// Do simple face triangulation around f[0].
|
||||
153
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceIO.C
Normal file
153
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceIO.C
Normal file
@ -0,0 +1,153 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Read surf grouping, points, faces directly from Istream
|
||||
template<class Face>
|
||||
bool Foam::UnsortedMeshedSurface<Face>::read(Istream& is)
|
||||
{
|
||||
clear();
|
||||
|
||||
// triangulation required?
|
||||
bool mustTriangulate = false;
|
||||
{
|
||||
Face f;
|
||||
if (f.max_size() == 3)
|
||||
{
|
||||
mustTriangulate = true;
|
||||
}
|
||||
}
|
||||
|
||||
List<surfGroup> patchLst(is);
|
||||
// read points:
|
||||
is >> points();
|
||||
|
||||
|
||||
// read faces:
|
||||
// TODO - specialization to triangulate on-the-fly
|
||||
if (mustTriangulate)
|
||||
{
|
||||
is >> faces();
|
||||
}
|
||||
else
|
||||
{
|
||||
is >> faces();
|
||||
}
|
||||
|
||||
patches_.setSize(patchLst.size());
|
||||
regions_.setSize(size());
|
||||
|
||||
// copy patch info and set regions:
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
patches_[patchI] = PatchRegionType
|
||||
(
|
||||
patchLst[patchI],
|
||||
patchI
|
||||
);
|
||||
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
regions_[faceIndex++] = patchI;
|
||||
}
|
||||
}
|
||||
|
||||
return is.good();
|
||||
}
|
||||
|
||||
|
||||
// write (sorted)
|
||||
template<class Face>
|
||||
void Foam::UnsortedMeshedSurface<Face>::write(Ostream& os) const
|
||||
{
|
||||
const List<Face>& faceLst = faces();
|
||||
labelList faceMap;
|
||||
List<surfGroup> patchLst = sortedRegions(faceMap);
|
||||
|
||||
// just emit some information until we get a nice IOobject
|
||||
IOobject::writeBanner(os);
|
||||
os << "// OpenFOAM Surface format" << nl
|
||||
<< "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl
|
||||
<< "// regions:" << nl
|
||||
<< patchLst.size() << nl << token::BEGIN_LIST << incrIndent << nl;
|
||||
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
patchLst[patchI].writeDict(os);
|
||||
}
|
||||
os << decrIndent << token::END_LIST << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
|
||||
// Note: Write with global point numbering
|
||||
os << "\n// points:" << nl << points() << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
os << "\n// faces:" << nl;
|
||||
os << faceLst.size() << nl << token::BEGIN_LIST << nl;
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
// Print all faces belonging to this region
|
||||
const surfGroup& patch = patchLst[patchI];
|
||||
|
||||
forAll(patch, patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceMap[faceIndex++]];
|
||||
|
||||
os << f << nl;
|
||||
}
|
||||
}
|
||||
os << token::END_LIST << nl;
|
||||
|
||||
IOobject::writeDivider(os);
|
||||
|
||||
// Check state of Ostream
|
||||
os.check("meshedSurface::write(Ostream&)");
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
surf.write(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,60 +24,64 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "keyedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::keyedSurface>
|
||||
Foam::keyedSurface::New
|
||||
template<class Face>
|
||||
Foam::autoPtr<Foam::UnsortedMeshedSurface<Face> >
|
||||
Foam::UnsortedMeshedSurface<Face>::New
|
||||
(
|
||||
const fileName& fName,
|
||||
const word& ext,
|
||||
const bool triangulate
|
||||
const word& ext
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "keyedSurface::New"
|
||||
"(const fileName&, const word&, const bool) : "
|
||||
"constructing keyedSurface"
|
||||
Info<< "UnsortedMeshedSurface<Face>::New"
|
||||
"(const fileName&, const word&) : "
|
||||
"constructing UnsortedMeshedSurface"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
fileExtensionConstructorTable::iterator cstrIter =
|
||||
typename fileExtensionConstructorTable::iterator cstrIter =
|
||||
fileExtensionConstructorTablePtr_->find(ext);
|
||||
|
||||
if (cstrIter == fileExtensionConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"keyedSurface::New(const fileName&, const word&, const bool) : "
|
||||
"constructing keyedSurface"
|
||||
"UnsortedMeshedSurface<Face>::New"
|
||||
"(const fileName&, const word&) : "
|
||||
"constructing UnsortedMeshedSurface"
|
||||
) << "Unknown file extension " << ext << nl << nl
|
||||
<< "Valid types are :" << nl
|
||||
<< fileExtensionConstructorTablePtr_->toc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<keyedSurface>(cstrIter()(fName, triangulate));
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
cstrIter()(fName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::keyedSurface>
|
||||
Foam::keyedSurface::New
|
||||
template<class Face>
|
||||
Foam::autoPtr<Foam::UnsortedMeshedSurface<Face> >
|
||||
Foam::UnsortedMeshedSurface<Face>::New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
const word ext = fName.ext();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "keyedSurface::New(const fileName&, const bool) : "
|
||||
"constructing keyedSurface"
|
||||
Info<< "UnsortedMeshedSurface<Face>::New"
|
||||
"(const fileName&) : "
|
||||
"constructing UnsortedMeshedSurface"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
@ -89,7 +93,7 @@ Foam::keyedSurface::New
|
||||
// return New(unzipName, unzipName.ext(), ext);
|
||||
// }
|
||||
|
||||
return New(fName, ext, triangulate);
|
||||
return New(fName, ext);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
52
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaces.C
Normal file
52
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaces.C
Normal file
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "UnsortedMeshedSurfaces.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
#define makeUnsortedMeshedSurface(faceType) \
|
||||
defineNamedTemplateTypeNameAndDebug \
|
||||
(UnsortedMeshedSurface<faceType>, 0); \
|
||||
defineTemplatedRunTimeSelectionTable \
|
||||
(UnsortedMeshedSurface, fileExtension,faceType); \
|
||||
defineTemplatedMemberFunctionSelectionTable \
|
||||
(UnsortedMeshedSurface, write,fileExtension,faceType);
|
||||
|
||||
|
||||
makeUnsortedMeshedSurface(face)
|
||||
makeUnsortedMeshedSurface(triFace)
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
35
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaces.H
Normal file
35
src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaces.H
Normal file
@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef UnsortedMeshedSurfaces_H
|
||||
#define UnsortedMeshedSurfaces_H
|
||||
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "UnsortedMeshedSurfacesFwd.H"
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef UnsortedMeshedSurfacesFwd_H
|
||||
#define UnsortedMeshedSurfacesFwd_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
class face;
|
||||
class triFace;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face> class UnsortedMeshedSurface;
|
||||
|
||||
typedef UnsortedMeshedSurface<face> unsortedMeshedSurface;
|
||||
typedef UnsortedMeshedSurface<triFace> triUnsortedMeshedSurface;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,599 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STLfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "clock.H"
|
||||
#include "OSspecific.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
STLfileFormat,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
STLfileFormat,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
STLfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
STLfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
STLfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
STLfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
// check binary by getting the header and number of facets
|
||||
// this seems to work better than the old token-based method
|
||||
// - some programs (eg, pro-STAR) have 'solid' as the first word in
|
||||
// the binary header.
|
||||
// - using wordToken can cause an abort if non-word (binary) content
|
||||
// is detected ... this is not exactly what we want.
|
||||
bool Foam::fileFormats::STLfileFormat::detectBINARY
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
off_t fileSize = Foam::size(fName);
|
||||
|
||||
IFstream ifs(fName, IOstream::BINARY);
|
||||
istream& is = ifs.stdStream();
|
||||
|
||||
// Read the STL header
|
||||
char header[headerSize];
|
||||
is.read(header, headerSize);
|
||||
|
||||
// Check that stream is OK, if not this may be an ASCII file
|
||||
if (!is.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the number of triangles in the STl file
|
||||
// (note: read as int so we can check whether >2^31)
|
||||
int nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
// Check that stream is OK and number of triangles is positive,
|
||||
// if not this maybe an ASCII file
|
||||
//
|
||||
// Also compare the file size with that expected from the number of tris
|
||||
// If the comparison is not sensible then it may be an ASCII file
|
||||
if
|
||||
(
|
||||
!is
|
||||
|| nTris < 0
|
||||
|| nTris < (fileSize - headerSize)/50
|
||||
|| nTris > (fileSize - headerSize)/25
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// looks like it might be BINARY
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#undef DEBUG_STLBINARY
|
||||
|
||||
bool Foam::fileFormats::STLfileFormat::readBINARY
|
||||
(
|
||||
IFstream& ifs,
|
||||
const off_t fileSize
|
||||
)
|
||||
{
|
||||
istream& is = ifs.stdStream();
|
||||
|
||||
// Read the STL header
|
||||
char header[headerSize];
|
||||
is.read(header, headerSize);
|
||||
|
||||
// Check that stream is OK, if not this may be an ASCII file
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STLfileFormat::readBINARY(Istream&)"
|
||||
)
|
||||
<< "problem reading header, perhaps file is not binary "
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Read the number of triangles in the STl file
|
||||
// (note: read as int so we can check whether >2^31)
|
||||
int nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
// Check that stream is OK and number of triangles is positive,
|
||||
// if not this maybe an ASCII file
|
||||
//
|
||||
// Also compare the file size with that expected from the number of tris
|
||||
// If the comparison is not sensible then it may be an ASCII file
|
||||
if
|
||||
(
|
||||
!is
|
||||
|| nTris < 0
|
||||
|| nTris < (fileSize - headerSize)/50
|
||||
|| nTris > (fileSize - headerSize)/25
|
||||
)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STLfileFormat::readBINARY(Istream&)"
|
||||
)
|
||||
<< "problem reading number of triangles, perhaps file is not binary"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_STLBINARY
|
||||
Info<< "# " << nTris << " facets" << endl;
|
||||
label prevRegion = -1;
|
||||
#endif
|
||||
|
||||
|
||||
// write directly into the lists:
|
||||
pointField& pointLst = points();
|
||||
List<face>& faceLst = faces();
|
||||
List<label>& regionLst = regions();
|
||||
|
||||
pointLst.setSize(3*nTris);
|
||||
faceLst.setSize(nTris);
|
||||
regionLst.setSize(nTris);
|
||||
|
||||
label maxRegionId = 0;
|
||||
|
||||
label pointI = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
// Read an STL triangle
|
||||
STLtriangle stlTri(is);
|
||||
|
||||
// Set the rawPoints to the vertices of the STL triangle
|
||||
// and set the point labels of the face
|
||||
|
||||
pointLst[pointI] = stlTri.a();
|
||||
fTri[0] = pointI++;
|
||||
|
||||
pointLst[pointI] = stlTri.b();
|
||||
fTri[1] = pointI++;
|
||||
|
||||
pointLst[pointI] = stlTri.c();
|
||||
fTri[2] = pointI++;
|
||||
|
||||
faceLst[faceI] = fTri;
|
||||
|
||||
// interprete colour as a region
|
||||
regionLst[faceI] = stlTri.region();
|
||||
|
||||
if (maxRegionId < stlTri.region())
|
||||
{
|
||||
maxRegionId = stlTri.region();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_STLBINARY
|
||||
if
|
||||
(
|
||||
prevRegion != stlTri.region()
|
||||
)
|
||||
{
|
||||
if (prevRegion != -1)
|
||||
{
|
||||
Info<< "endsolid region" << prevRegion << nl;
|
||||
}
|
||||
prevRegion = stlTri.region();
|
||||
|
||||
Info<< "solid region" << prevRegion << nl;
|
||||
}
|
||||
|
||||
Info<< " facet normal " << stlTri.normal() << nl;
|
||||
Info<< " outer loop" << nl;
|
||||
Info<< " vertex " << stlTri.a() << nl;
|
||||
Info<< " vertex " << stlTri.b() << nl;
|
||||
Info<< " vertex " << stlTri.c() << nl;
|
||||
Info<< " outer loop" << nl;
|
||||
Info<< " endfacet" << endl;
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG_STLBINARY
|
||||
Info<< "endsolid region" << prevRegion << nl;
|
||||
#endif
|
||||
|
||||
setPatches(maxRegionId);
|
||||
stitchFaces(SMALL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::fileFormats::STLfileFormat::writeShell
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const face& f,
|
||||
const vector& norm
|
||||
)
|
||||
{
|
||||
// simple triangulation about f[0].
|
||||
// better triangulation should have been done before
|
||||
const point& p0 = pointLst[f[0]];
|
||||
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
|
||||
{
|
||||
label fp2 = (fp1 + 1) % f.size();
|
||||
|
||||
const point& p1 = pointLst[f[fp1]];
|
||||
const point& p2 = pointLst[f[fp2]];
|
||||
|
||||
// write STL triangle
|
||||
os << " facet normal "
|
||||
<< norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl
|
||||
<< " outer loop\n"
|
||||
<< " vertex "
|
||||
<< p0.x() << ' ' << p0.y() << ' ' << p0.z() << nl
|
||||
<< " vertex "
|
||||
<< p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl
|
||||
<< " vertex "
|
||||
<< p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl
|
||||
<< " endloop\n"
|
||||
<< " endfacet" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::fileFormats::STLfileFormat::writeShell
|
||||
(
|
||||
ostream& os,
|
||||
const pointField& pointLst,
|
||||
const face& f,
|
||||
const vector& norm,
|
||||
const label patchI
|
||||
)
|
||||
{
|
||||
// simple triangulation about f[0].
|
||||
// better triangulation should have been done before
|
||||
const point& p0 = pointLst[f[0]];
|
||||
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
|
||||
{
|
||||
label fp2 = (fp1 + 1) % f.size();
|
||||
|
||||
STLtriangle stlTri
|
||||
(
|
||||
norm,
|
||||
p0,
|
||||
pointLst[f[fp1]],
|
||||
pointLst[f[fp2]],
|
||||
patchI
|
||||
);
|
||||
|
||||
stlTri.write(os);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// write sorted:
|
||||
void Foam::fileFormats::STLfileFormat::writeASCII
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
|
||||
labelList faceMap;
|
||||
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
// Print all faces belonging to this region
|
||||
const surfGroup& patch = patchLst[patchI];
|
||||
|
||||
os << "solid " << patch.name() << endl;
|
||||
|
||||
forAll(patch, patchFaceI)
|
||||
{
|
||||
const label faceI = faceMap[faceIndex++];
|
||||
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
|
||||
}
|
||||
|
||||
os << "endsolid " << patch.name() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// write sorted:
|
||||
void Foam::fileFormats::STLfileFormat::writeASCII
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
|
||||
// force triangulation, but just do the cheapest form possible
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
// Print all faces belonging to this region
|
||||
const surfGroup& patch = patchLst[patchI];
|
||||
|
||||
os << "solid " << patch.name() << endl;
|
||||
|
||||
forAll(patch, patchFaceI)
|
||||
{
|
||||
const label faceI = faceIndex++;
|
||||
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
|
||||
}
|
||||
|
||||
os << "endsolid " << patch.name() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write unsorted:
|
||||
void Foam::fileFormats::STLfileFormat::writeBINARY
|
||||
(
|
||||
ostream& os,
|
||||
const keyedSurface& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<label>& regionLst = surf.regions();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
|
||||
// Write the STL header
|
||||
string header("STL binary file", headerSize);
|
||||
|
||||
// clear possible trailing junk
|
||||
for (label i = header.size(); i < headerSize; ++i)
|
||||
{
|
||||
header[i] = 0;
|
||||
}
|
||||
os.write(header.c_str(), headerSize);
|
||||
|
||||
// force triangulation, but just do the cheapest form possible
|
||||
unsigned int nTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
nTris += faceLst[faceI].size() - 2;
|
||||
}
|
||||
|
||||
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
// always write unsorted
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
writeShell
|
||||
(
|
||||
os,
|
||||
pointLst,
|
||||
faceLst[faceI],
|
||||
normLst[faceI],
|
||||
regionLst[faceI]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STLfileFormat::writeBINARY
|
||||
(
|
||||
ostream& os,
|
||||
const meshedSurface& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
// Write the STL header
|
||||
string header("STL binary file", headerSize);
|
||||
os.write(header.c_str(), headerSize);
|
||||
|
||||
// force triangulation, but just do the cheapest form possible
|
||||
|
||||
unsigned int nTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
nTris += faceLst[faceI].size() - 2;
|
||||
}
|
||||
|
||||
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
writeShell
|
||||
(
|
||||
os,
|
||||
pointLst,
|
||||
faceLst[faceIndex],
|
||||
normLst[faceIndex],
|
||||
patchI
|
||||
);
|
||||
|
||||
++faceIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::STLfileFormat::STLfileFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::STLfileFormat::STLfileFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
{
|
||||
off_t fileSize = Foam::size(fName);
|
||||
|
||||
// auto-detect ascii/binary
|
||||
if (detectBINARY(fName))
|
||||
{
|
||||
readBINARY(IFstream(fName, IOstream::BINARY)(), fileSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
readASCII(IFstream(fName)(), fileSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
void Foam::fileFormats::STLfileFormat::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
)
|
||||
{
|
||||
writeASCII(os, surf);
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STLfileFormat::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
)
|
||||
{
|
||||
writeASCII(os, surf);
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STLfileFormat::write
|
||||
(
|
||||
const fileName& fName,
|
||||
const keyedSurface& surf
|
||||
)
|
||||
{
|
||||
const word ext = fName.ext();
|
||||
|
||||
// handle 'stlb' as binary directly
|
||||
if (ext == "stlb")
|
||||
{
|
||||
std::ofstream ofs(fName.c_str(), std::ios::binary);
|
||||
writeBINARY(ofs, surf);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeASCII(OFstream(fName)(), surf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STLfileFormat::write
|
||||
(
|
||||
const fileName& fName,
|
||||
const meshedSurface& surf
|
||||
)
|
||||
{
|
||||
const word ext = fName.ext();
|
||||
|
||||
// handle 'stlb' as binary directly
|
||||
if (ext == "stlb")
|
||||
{
|
||||
std::ofstream ofs(fName.c_str(), std::ios::binary);
|
||||
writeBINARY(ofs, surf);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeASCII(OFstream(fName)(), surf);
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
File diff suppressed because it is too large
Load Diff
@ -24,171 +24,64 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "AC3DfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "AC3DsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "tensor.H"
|
||||
#include "triFace.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
AC3DfileFormat,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
AC3DfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
AC3DfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Type Foam::fileFormats::AC3DfileFormat::parse(const string& str)
|
||||
{
|
||||
IStringStream ss(str);
|
||||
|
||||
Type t;
|
||||
ss >> t;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileFormats::AC3DfileFormat::readCmd
|
||||
(
|
||||
IFstream& is,
|
||||
string& cmd,
|
||||
string& args
|
||||
)
|
||||
{
|
||||
if (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
|
||||
string::size_type space = line.find(' ');
|
||||
|
||||
if (space != string::npos)
|
||||
{
|
||||
cmd = line.substr(0, space);
|
||||
args = line.substr(space+1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Read up to line starting with cmd. Sets args to rest of line.
|
||||
// Returns true if found, false if stream is not good anymore.
|
||||
bool Foam::fileFormats::AC3DfileFormat::cueTo
|
||||
(
|
||||
IFstream& is,
|
||||
const string& cmd,
|
||||
string& args
|
||||
)
|
||||
{
|
||||
while (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
|
||||
string::size_type space = line.find(' ');
|
||||
|
||||
if (space != string::npos)
|
||||
{
|
||||
if (line.substr(0, space) == cmd)
|
||||
{
|
||||
args = line.substr(space+1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Similar to cueTo(), but throws error if cmd not found
|
||||
Foam::string Foam::fileFormats::AC3DfileFormat::cueToOrDie
|
||||
(
|
||||
IFstream& is,
|
||||
const string& cmd,
|
||||
const string& errorMsg
|
||||
)
|
||||
{
|
||||
string args;
|
||||
if (!cueTo(is, cmd, args))
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::AC3DfileFormat::AC3DfileFormat"
|
||||
"(const fileName&)"
|
||||
)
|
||||
<< "Cannot find command " << cmd
|
||||
<< " " << errorMsg
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::AC3DfileFormat::AC3DfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::AC3DsurfaceFormat<Face>::AC3DsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::AC3DsurfaceFormat<Face>::AC3DsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
IFstream is(fName);
|
||||
read(fName);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
// triangulation required?
|
||||
bool mustTriangulate = false;
|
||||
{
|
||||
Face f;
|
||||
if (f.max_size() == 3)
|
||||
{
|
||||
mustTriangulate = true;
|
||||
}
|
||||
}
|
||||
|
||||
IFstream is(fName);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::AC3DfileFormat::AC3DfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::AC3DsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << fName
|
||||
<< exit(FatalError);
|
||||
@ -204,8 +97,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"fileFormats::AC3DfileFormat::AC3DfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::AC3DsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "When reading AC3D file " << fName
|
||||
<< " read header " << line << " with version "
|
||||
@ -219,8 +111,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::AC3DfileFormat::AC3DfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::AC3DsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot find \"OBJECT world\" in file " << fName
|
||||
<< exit(FatalError);
|
||||
@ -233,9 +124,9 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
// Start of vertices for object/patch
|
||||
label patchVertOffset = 0;
|
||||
|
||||
DynamicList<point> pointLst;
|
||||
DynamicList<FaceType> faceLst;
|
||||
DynamicList<label> regionLst;
|
||||
DynamicList<point> pointLst;
|
||||
DynamicList<Face> faceLst;
|
||||
DynamicList<label> regionLst;
|
||||
|
||||
// patchId => patchName
|
||||
Map<word> regionNames;
|
||||
@ -260,8 +151,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::AC3DfileFormat::AC3DfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::AC3DsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Did not read up to \"kids 0\" while reading patch "
|
||||
<< patchI << " from file " << fName
|
||||
@ -289,7 +179,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
|
||||
WarningIn
|
||||
(
|
||||
"fileFormats::AC3DfileFormat::AC3DfileFormat"
|
||||
"fileFormats::AC3DsurfaceFormat::read"
|
||||
"(const fileName&)"
|
||||
)
|
||||
<< "rot (rotation tensor) command not implemented"
|
||||
@ -342,14 +232,16 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
|
||||
label nVert = parse<int>(args);
|
||||
|
||||
face verts(nVert);
|
||||
List<label> verts(nVert);
|
||||
forAll(verts, vertI)
|
||||
{
|
||||
is.getLine(line);
|
||||
verts[vertI] = parse<int>(line) + patchVertOffset;
|
||||
}
|
||||
|
||||
if (triangulate && verts.size() > 3)
|
||||
UList<label>& f = static_cast<UList<label>&>(verts);
|
||||
|
||||
if (mustTriangulate)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
@ -370,7 +262,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
}
|
||||
else
|
||||
{
|
||||
faceLst.append(verts);
|
||||
faceLst.append(Face(f));
|
||||
regionLst.append(patchI);
|
||||
}
|
||||
}
|
||||
@ -388,8 +280,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::AC3DfileFormat::AC3DfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::AC3DsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Can only read objects without kids."
|
||||
<< " Encountered " << nKids << " kids when"
|
||||
@ -405,67 +296,22 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
|
||||
}
|
||||
|
||||
// transfer to normal lists
|
||||
points().transfer(pointLst);
|
||||
faces().transfer(faceLst);
|
||||
regions().transfer(regionLst);
|
||||
ParentType::points().transfer(pointLst);
|
||||
ParentType::faces().transfer(faceLst);
|
||||
|
||||
setPatches(regionNames);
|
||||
stitchFaces(SMALL);
|
||||
ParentType::regions().transfer(regionLst);
|
||||
|
||||
ParentType::setPatches(regionNames);
|
||||
ParentType::stitchFaces(SMALL);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::AC3DfileFormat::writeHeader
|
||||
template<class Face>
|
||||
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const List<surfGroup>& patchLst
|
||||
)
|
||||
{
|
||||
// Write with patches as separate objects under "world" object.
|
||||
// Header is taken over from sample file.
|
||||
// Defines separate materials for all patches. Recycle colours.
|
||||
|
||||
// Define 8 standard colours as r,g,b components
|
||||
static scalar colourMap[] =
|
||||
{
|
||||
1, 1, 1,
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1,
|
||||
1, 1, 0,
|
||||
0, 1, 1,
|
||||
1, 0, 1,
|
||||
0.5, 0.5, 1
|
||||
};
|
||||
|
||||
// Write header. Define materials.
|
||||
os << "AC3Db" << nl;
|
||||
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
const word& pName = patchLst[patchI].name();
|
||||
|
||||
label colourI = patchI % 8;
|
||||
label colourCompI = 3 * colourI;
|
||||
|
||||
os << "MATERIAL \"" << pName << "Mat\" rgb "
|
||||
<< colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
|
||||
<< ' ' << colourMap[colourCompI+2]
|
||||
<< " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
|
||||
<< " trans 0"
|
||||
<< nl;
|
||||
}
|
||||
|
||||
os << "OBJECT world" << nl
|
||||
<< "kids " << patchLst.size() << endl;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::AC3DfileFormat::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
labelList faceMap;
|
||||
@ -494,7 +340,7 @@ void Foam::fileFormats::AC3DfileFormat::write
|
||||
labelList pMap;
|
||||
labelList fMap;
|
||||
|
||||
keyedSurface patch = surf.subsetMesh
|
||||
ParentType patch = surf.subsetMesh
|
||||
(
|
||||
include, pMap, fMap
|
||||
);
|
||||
@ -530,14 +376,15 @@ void Foam::fileFormats::AC3DfileFormat::write
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::AC3DfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<FaceType>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
writeHeader(os, patchLst);
|
||||
@ -549,15 +396,11 @@ void Foam::fileFormats::AC3DfileFormat::write
|
||||
os << "OBJECT poly" << nl
|
||||
<< "name \"" << p.name() << '"' << endl;
|
||||
|
||||
// Temporary primitivePatch to calculate compact points & faces
|
||||
primitivePatch patch
|
||||
// Temporary PrimitivePatch to calculate compact points & faces
|
||||
// use 'UList' to avoid allocations!
|
||||
PrimitivePatch<Face, UList, const pointField&> patch
|
||||
(
|
||||
SubList<face>
|
||||
(
|
||||
faceLst,
|
||||
p.start(),
|
||||
p.size()
|
||||
),
|
||||
faceLst,
|
||||
pointLst
|
||||
);
|
||||
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::AC3DfileFormat
|
||||
Foam::fileFormats::AC3DsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing AC3D format.
|
||||
@ -35,17 +35,18 @@ Note
|
||||
optimized for this, but at expense of losing a common reading approach.
|
||||
|
||||
SourceFiles
|
||||
AC3DfileFormat.C
|
||||
AC3DsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef AC3DfileFormat_H
|
||||
#define AC3DfileFormat_H
|
||||
#ifndef AC3DsurfaceFormat_H
|
||||
#define AC3DsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "AC3DsurfaceFormatCore.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -54,92 +55,93 @@ namespace Foam
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
class AC3DfileFormat;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class AC3DfileFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class AC3DfileFormat
|
||||
template<class Face>
|
||||
class AC3DsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>,
|
||||
public AC3DsurfaceFormatCore
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef AC3DsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Read a type via IStringStream
|
||||
template<class Type>
|
||||
static Type parse(const string&);
|
||||
|
||||
//- Read cmd, args from IFstream
|
||||
static bool readCmd(IFstream&, string& cmd, string& args);
|
||||
|
||||
//- Cue up to cmd, reading args
|
||||
static bool cueTo(IFstream&, const string& cmd, string& args);
|
||||
|
||||
//- Cue up to cmd, reading args or exit with a FatalError
|
||||
// returns the command args
|
||||
static string cueToOrDie
|
||||
(
|
||||
IFstream&,
|
||||
const string& cmd,
|
||||
const string& errorMsg=string::null
|
||||
);
|
||||
|
||||
//- Write header with materials
|
||||
static void writeHeader(Ostream&, const List<surfGroup>&);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
AC3DfileFormat(const AC3DfileFormat&);
|
||||
AC3DsurfaceFormat(const AC3DsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const AC3DfileFormat&);
|
||||
void operator=(const AC3DsurfaceFormat<Face>&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
AC3DfileFormat();
|
||||
AC3DsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
AC3DfileFormat(const fileName&, const bool triangulate=false);
|
||||
AC3DsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=false
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new AC3DfileFormat(fName, triangulate)
|
||||
new AC3DsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~AC3DsurfaceFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName& fName, const keyedSurface& surf)
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName& fName, const meshedSurface& surf)
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
@ -160,6 +162,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "AC3DsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
174
src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.C
Normal file
174
src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.C
Normal file
@ -0,0 +1,174 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "AC3DsurfaceFormatCore.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Type Foam::fileFormats::AC3DsurfaceFormatCore::parse(const string& str)
|
||||
{
|
||||
IStringStream ss(str);
|
||||
|
||||
Type t;
|
||||
ss >> t;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
|
||||
(
|
||||
IFstream& is,
|
||||
string& cmd,
|
||||
string& args
|
||||
)
|
||||
{
|
||||
if (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
|
||||
string::size_type space = line.find(' ');
|
||||
|
||||
if (space != string::npos)
|
||||
{
|
||||
cmd = line.substr(0, space);
|
||||
args = line.substr(space+1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Read up to line starting with cmd. Sets args to rest of line.
|
||||
// Returns true if found, false if stream is not good anymore.
|
||||
bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo
|
||||
(
|
||||
IFstream& is,
|
||||
const string& cmd,
|
||||
string& args
|
||||
)
|
||||
{
|
||||
while (is.good())
|
||||
{
|
||||
string line;
|
||||
is.getLine(line);
|
||||
|
||||
string::size_type space = line.find(' ');
|
||||
|
||||
if (space != string::npos)
|
||||
{
|
||||
if (line.substr(0, space) == cmd)
|
||||
{
|
||||
args = line.substr(space+1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Similar to cueTo(), but throws error if cmd not found
|
||||
Foam::string Foam::fileFormats::AC3DsurfaceFormatCore::cueToOrDie
|
||||
(
|
||||
IFstream& is,
|
||||
const string& cmd,
|
||||
const string& errorMsg
|
||||
)
|
||||
{
|
||||
string args;
|
||||
if (!cueTo(is, cmd, args))
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::AC3DsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot find command " << cmd
|
||||
<< " " << errorMsg
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::AC3DsurfaceFormatCore::writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const List<surfGroup>& patchLst
|
||||
)
|
||||
{
|
||||
// Write with patches as separate objects under "world" object.
|
||||
// Header is taken over from sample file.
|
||||
// Defines separate materials for all patches. Recycle colours.
|
||||
|
||||
// Define 8 standard colours as r,g,b components
|
||||
static scalar colourMap[] =
|
||||
{
|
||||
1, 1, 1,
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1,
|
||||
1, 1, 0,
|
||||
0, 1, 1,
|
||||
1, 0, 1,
|
||||
0.5, 0.5, 1
|
||||
};
|
||||
|
||||
// Write header. Define materials.
|
||||
os << "AC3Db" << nl;
|
||||
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
const word& pName = patchLst[patchI].name();
|
||||
|
||||
label colourI = patchI % 8;
|
||||
label colourCompI = 3 * colourI;
|
||||
|
||||
os << "MATERIAL \"" << pName << "Mat\" rgb "
|
||||
<< colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
|
||||
<< ' ' << colourMap[colourCompI+2]
|
||||
<< " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
|
||||
<< " trans 0"
|
||||
<< nl;
|
||||
}
|
||||
|
||||
os << "OBJECT world" << nl
|
||||
<< "kids " << patchLst.size() << endl;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// ************************************************************************* //
|
||||
111
src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H
Normal file
111
src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatCore.H
Normal file
@ -0,0 +1,111 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::AC3DsurfaceFormatCore
|
||||
|
||||
Description
|
||||
Internal class used by the AC3DsurfaceFormat
|
||||
|
||||
SourceFiles
|
||||
AC3DsurfaceFormatCore.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef AC3DsurfaceFormatCore_H
|
||||
#define AC3DsurfaceFormatCore_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class AC3DfileFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class AC3DsurfaceFormatCore
|
||||
{
|
||||
protected:
|
||||
// Protected Member Functions
|
||||
|
||||
//- Read a type via IStringStream
|
||||
template<class Type>
|
||||
static Type parse(const string&);
|
||||
|
||||
//- Read cmd, args from IFstream
|
||||
static bool readCmd(IFstream&, string& cmd, string& args);
|
||||
|
||||
//- Cue up to cmd, reading args
|
||||
static bool cueTo(IFstream&, const string& cmd, string& args);
|
||||
|
||||
//- Cue up to cmd, reading args or exit with a FatalError
|
||||
// returns the command args
|
||||
static string cueToOrDie
|
||||
(
|
||||
IFstream&,
|
||||
const string& cmd,
|
||||
const string& errorMsg=string::null
|
||||
);
|
||||
|
||||
//- Write header with materials
|
||||
static void writeHeader(Ostream&, const List<surfGroup>&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
AC3DsurfaceFormatCore()
|
||||
{}
|
||||
|
||||
// Destructor
|
||||
|
||||
~AC3DsurfaceFormatCore()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
99
src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatRunTime.C
Normal file
99
src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "AC3DsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
ac
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,53 +24,48 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "FTRfileFormat.H"
|
||||
#include "clock.H"
|
||||
#include "FTRsurfaceFormat.H"
|
||||
#include "Keyed.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
FTRfileFormat,
|
||||
fileExtension,
|
||||
ftr
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::FTRfileFormat::FTRfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::FTRsurfaceFormat<Face>::FTRsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::FTRfileFormat::FTRfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::FTRsurfaceFormat<Face>::FTRsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
IFstream is(fName);
|
||||
ThisType::read(fName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::FTRsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
IFstream is(fName);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::FTRfileFormat::FTRfileFormat(const fileName&)"
|
||||
"fileFormats::FTRsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << fName
|
||||
<< exit(FatalError);
|
||||
@ -80,23 +75,24 @@ Foam::fileFormats::FTRfileFormat::FTRfileFormat
|
||||
List<point> pointLst(is);
|
||||
|
||||
// transfer to normal list
|
||||
points().transfer(pointLst);
|
||||
ParentType::points().transfer(pointLst);
|
||||
|
||||
// read face with keys
|
||||
List<keyedFace> readFaces(is);
|
||||
// read faces with keys
|
||||
List<Keyed<triFace> > readFaces(is);
|
||||
|
||||
List<face> faceLst(readFaces.size());
|
||||
List<label> regionLst(readFaces.size());
|
||||
List<Face> faceLst(readFaces.size());
|
||||
List<label> regionLst(readFaces.size());
|
||||
|
||||
// disentangle faces/keys - already triangulated
|
||||
forAll(readFaces, faceI)
|
||||
{
|
||||
faceLst[faceI].transfer(readFaces[faceI]);
|
||||
// unfortunately cannot transfer to save memory
|
||||
faceLst[faceI] = readFaces[faceI];
|
||||
regionLst[faceI] = readFaces[faceI].key();
|
||||
}
|
||||
|
||||
faces().transfer(faceLst);
|
||||
regions().transfer(regionLst);
|
||||
ParentType::faces().transfer(faceLst);
|
||||
ParentType::regions().transfer(regionLst);
|
||||
|
||||
Map<word> regionNames;
|
||||
forAll(readPatches, patchI)
|
||||
@ -104,7 +100,8 @@ Foam::fileFormats::FTRfileFormat::FTRfileFormat
|
||||
regionNames.insert(patchI, readPatches[patchI].name());
|
||||
}
|
||||
|
||||
setPatches(regionNames, readPatches.size() - 1);
|
||||
ParentType::setPatches(regionNames, readPatches.size() - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -23,22 +23,22 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::FTRfileFormat
|
||||
Foam::fileFormats::FTRsurfaceFormat
|
||||
|
||||
Description
|
||||
Reading of Foam Trisurface Format
|
||||
|
||||
SourceFiles
|
||||
FTRfileFormat.C
|
||||
FTRsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef FTRfileFormat_H
|
||||
#define FTRfileFormat_H
|
||||
#ifndef FTRsurfaceFormat_H
|
||||
#define FTRsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "IFstream.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -48,21 +48,25 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class FTRfileFormat Declaration
|
||||
Class FTRsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class FTRfileFormat
|
||||
template<class Face>
|
||||
class FTRsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef FTRsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
FTRfileFormat(const FTRfileFormat&);
|
||||
FTRsurfaceFormat(const FTRsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const FTRfileFormat&);
|
||||
void operator=(const FTRsurfaceFormat<Face>&);
|
||||
|
||||
|
||||
//- read compatibility for ftr format
|
||||
@ -84,7 +88,6 @@ class FTRfileFormat
|
||||
friend Istream& operator>>(Istream& is, ftrPatch& p)
|
||||
{
|
||||
is >> p.name_ >> p.type_;
|
||||
|
||||
return is;
|
||||
}
|
||||
};
|
||||
@ -94,26 +97,37 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
FTRfileFormat();
|
||||
FTRsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
FTRfileFormat(const fileName&, const bool triangulate=false);
|
||||
FTRsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=false
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new FTRfileFormat(fName, triangulate)
|
||||
new FTRsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~FTRsurfaceFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -124,6 +138,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "FTRsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
59
src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormatRunTime.C
Normal file
59
src/surfMesh/surfaceFormats/ftr/FTRsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,59 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "FTRsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
FTRsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
ftr
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
FTRsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
ftr
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,85 +24,59 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "GTSfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "GTSsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "tensor.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
GTSfileFormat,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
GTSfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
GTSfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::GTSfileFormat::GTSfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::GTSsurfaceFormat<Face>::GTSsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::GTSsurfaceFormat<Face>::GTSsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
IFstream is(fName);
|
||||
read(fName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
IFstream is(fName);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::GTSfileFormat::GTSfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::GTSsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << fName
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Read header
|
||||
string line = getLineNoComment(is);
|
||||
string line = ParentType::getLineNoComment(is);
|
||||
|
||||
label nPoints, nEdges, nElems;
|
||||
{
|
||||
@ -115,9 +89,9 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
|
||||
|
||||
// write directly into the lists:
|
||||
pointField& pointLst = points();
|
||||
List<FaceType>& faceLst = faces();
|
||||
List<label>& regionLst = regions();
|
||||
pointField& pointLst = ParentType::points();
|
||||
List<Face>& faceLst = ParentType::faces();
|
||||
List<label>& regionLst = ParentType::regions();
|
||||
|
||||
pointLst.setSize(nPoints);
|
||||
faceLst.setSize(nElems);
|
||||
@ -128,7 +102,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
forAll(pointLst, pointI)
|
||||
{
|
||||
scalar x, y, z;
|
||||
line = getLineNoComment(is);
|
||||
line = ParentType::getLineNoComment(is);
|
||||
{
|
||||
IStringStream lineStream(line);
|
||||
lineStream
|
||||
@ -143,7 +117,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
forAll(edges, edgei)
|
||||
{
|
||||
label beg, end;
|
||||
line = getLineNoComment(is);
|
||||
line = ParentType::getLineNoComment(is);
|
||||
{
|
||||
IStringStream lineStream(line);
|
||||
lineStream
|
||||
@ -160,7 +134,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
label e0Label, e1Label, e2Label;
|
||||
label regionI = 0;
|
||||
|
||||
line = getLineNoComment(is);
|
||||
line = ParentType::getLineNoComment(is);
|
||||
{
|
||||
IStringStream lineStream(line);
|
||||
lineStream
|
||||
@ -195,8 +169,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::GTSfileFormat::GTSfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::GTSsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Edges 0 and 1 of triangle " << faceI
|
||||
<< " do not share a point.\n"
|
||||
@ -213,8 +186,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::GTSfileFormat::GTSfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::GTSsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Edges 1 and 2 of triangle " << faceI
|
||||
<< " do not share a point.\n"
|
||||
@ -229,8 +201,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::GTSfileFormat::GTSfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::GTSsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Edges of triangle " << faceI
|
||||
<< " reference more than three points.\n"
|
||||
@ -244,44 +215,50 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
|
||||
regionLst[faceI] = regionI;
|
||||
}
|
||||
|
||||
setPatches(maxPatch);
|
||||
// stitchFaces(SMALL);
|
||||
ParentType::setPatches(maxPatch);
|
||||
// ParentType::stitchFaces(SMALL);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::GTSfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::GTSsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<FaceType>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
|
||||
// check if output triangulation would be required
|
||||
// It is too annoying to triangulate on-the-fly
|
||||
// just issue a warning and get out
|
||||
label nNonTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
//
|
||||
if (faceLst.size() && faceLst[0].max_size() != 3)
|
||||
{
|
||||
if (faceLst[faceI].size() > 3)
|
||||
label nNonTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
++nNonTris;
|
||||
if (faceLst[faceI].size() != 3)
|
||||
{
|
||||
++nNonTris;
|
||||
}
|
||||
}
|
||||
|
||||
if (nNonTris)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::GTSsurfaceFormat::write"
|
||||
"(Ostream&, const UnsortedMeshedSurfaces<Face>&)"
|
||||
)
|
||||
<< "Surface has " << nNonTris << "/" << faceLst.size()
|
||||
<< " non-triangulated faces - not writing!" << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (nNonTris)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::GTSfileFormat::write"
|
||||
"(Ostream&, const keyedSurface&)"
|
||||
)
|
||||
<< "Surface has " << nNonTris << "/" << faceLst.size()
|
||||
<< " non-triangulated faces - not writing!" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
labelList faceMap;
|
||||
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
|
||||
@ -344,38 +321,44 @@ void Foam::fileFormats::GTSfileFormat::write
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::GTSfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::GTSsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<FaceType>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
|
||||
// check if output triangulation would be required
|
||||
// It is too annoying to triangulate on-the-fly
|
||||
// just issue a warning and get out
|
||||
label nNonTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
//
|
||||
if (faceLst.size() && faceLst[0].max_size() != 3)
|
||||
{
|
||||
if (faceLst[faceI].size() > 3)
|
||||
label nNonTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
++nNonTris;
|
||||
if (faceLst[faceI].size() != 3)
|
||||
{
|
||||
++nNonTris;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nNonTris)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"fileFormats::GTSfileFormat::write"
|
||||
"(Ostream&, const meshedSurface&)"
|
||||
)
|
||||
<< "Surface has " << nNonTris << "/" << faceLst.size()
|
||||
<< " non-triangulated faces - not writing!" << endl;
|
||||
|
||||
return;
|
||||
if (nNonTris)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::GTSsurfaceFormat::write"
|
||||
"(Ostream&, const MeshedSurface<Face>&)"
|
||||
)
|
||||
<< "Surface has " << nNonTris << "/" << faceLst.size()
|
||||
<< " non-triangulated faces - not writing!" << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Write header, print patch names as comment
|
||||
@ -23,23 +23,23 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::GTSfileFormat
|
||||
Foam::fileFormats::GTSsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing GTS format.
|
||||
|
||||
SourceFiles
|
||||
GTSfileFormat.C
|
||||
GTSsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef GTSfileFormat_H
|
||||
#define GTSfileFormat_H
|
||||
#ifndef GTSsurfaceFormat_H
|
||||
#define GTSsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -48,70 +48,90 @@ namespace Foam
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
class GTSfileFormat;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class GTSfileFormat Declaration
|
||||
Class GTSsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class GTSfileFormat
|
||||
template<class Face>
|
||||
class GTSsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef GTSsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
GTSfileFormat(const GTSfileFormat&);
|
||||
GTSsurfaceFormat(const GTSsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const GTSfileFormat&);
|
||||
void operator=(const GTSsurfaceFormat<Face>&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
GTSfileFormat();
|
||||
GTSsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
GTSfileFormat(const fileName&, const bool triangulate=true);
|
||||
GTSsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=true
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new GTSfileFormat(fName, triangulate)
|
||||
new GTSsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
virtual ~GTSsurfaceFormat()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName& fName, const keyedSurface& surf)
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName& fName, const meshedSurface& surf)
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
@ -132,6 +152,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "GTSsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
98
src/surfMesh/surfaceFormats/gts/GTSsurfaceFormatRunTime.C
Normal file
98
src/surfMesh/surfaceFormats/gts/GTSsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,98 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "GTSsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
gts
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,117 +24,73 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "NASfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "clock.H"
|
||||
#include "NASsurfaceFormat.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// .bdf (Bulk Data Format)
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
NASfileFormat,
|
||||
fileExtension,
|
||||
bdf
|
||||
);
|
||||
|
||||
// .nas (Nastran)
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
NASfileFormat,
|
||||
fileExtension,
|
||||
nas
|
||||
);
|
||||
|
||||
// addNamedToMemberFunctionSelectionTable
|
||||
// (
|
||||
// keyedSurface,
|
||||
// NASfileFormat,
|
||||
// write,
|
||||
// fileExtension,
|
||||
// nas
|
||||
// );
|
||||
//
|
||||
// addNamedToMemberFunctionSelectionTable
|
||||
// (
|
||||
// meshedSurface,
|
||||
// NASfileFormat,
|
||||
// write,
|
||||
// fileExtension,
|
||||
// nas
|
||||
// );
|
||||
|
||||
}
|
||||
}
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// Do weird things to extract number
|
||||
Foam::scalar Foam::fileFormats::NASfileFormat::parseNASCoord(const string& s)
|
||||
{
|
||||
size_t expSign = s.find_last_of("+-");
|
||||
|
||||
if (expSign != string::npos && expSign > 0 && !isspace(s[expSign-1]))
|
||||
{
|
||||
scalar mantissa = readScalar(IStringStream(s.substr(0, expSign))());
|
||||
scalar exponent = readScalar(IStringStream(s.substr(expSign+1))());
|
||||
|
||||
if (s[expSign] == '-')
|
||||
{
|
||||
exponent = -exponent;
|
||||
}
|
||||
return mantissa*pow(10, exponent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return readScalar(IStringStream(s)());
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::NASfileFormat::NASfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::NASsurfaceFormat<Face>::NASsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::NASsurfaceFormat<Face>::NASsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
IFstream is(fName);
|
||||
ThisType::read(fName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
// triangulation required?
|
||||
bool mustTriangulate = false;
|
||||
{
|
||||
Face f;
|
||||
if (f.max_size() == 3)
|
||||
{
|
||||
mustTriangulate = true;
|
||||
}
|
||||
}
|
||||
|
||||
IFstream is(fName);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::NASfileFormat::NASfileFormat(const fileName&)"
|
||||
"fileFormats::NASsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << fName
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
DynamicList<point> pointLst;
|
||||
DynamicList<point> pointLst;
|
||||
// Nastran index of points
|
||||
DynamicList<label> pointId;
|
||||
DynamicList<FaceType> faceLst;
|
||||
DynamicList<label> regionLst;
|
||||
HashTable<label> groupToPatch;
|
||||
DynamicList<label> pointId;
|
||||
DynamicList<Face> faceLst;
|
||||
DynamicList<label> regionLst;
|
||||
HashTable<label> groupToPatch;
|
||||
|
||||
// From face groupId to patchId
|
||||
Map<label> groupIdToPatchId;
|
||||
@ -294,6 +250,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
else if (cmd == "CQUAD4")
|
||||
{
|
||||
face fQuad(4);
|
||||
UList<label>& f = static_cast<UList<label>&>(fQuad);
|
||||
|
||||
label groupId = readLabel(IStringStream(line.substr(16,8))());
|
||||
fQuad[0] = readLabel(IStringStream(line.substr(24,8))());
|
||||
@ -316,19 +273,19 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
patchI = iter();
|
||||
}
|
||||
|
||||
if (triangulate)
|
||||
if (mustTriangulate)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
// simple face triangulation about f[0].
|
||||
// cannot use face::triangulation since points are incomplete
|
||||
fTri[0] = fQuad[0];
|
||||
for (label fp1 = 1; fp1 < fQuad.size() - 1; fp1++)
|
||||
fTri[0] = f[0];
|
||||
for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
|
||||
{
|
||||
label fp2 = (fp1 + 1) % fQuad.size();
|
||||
label fp2 = (fp1 + 1) % f.size();
|
||||
|
||||
fTri[1] = fQuad[fp1];
|
||||
fTri[2] = fQuad[fp2];
|
||||
fTri[1] = f[fp1];
|
||||
fTri[2] = f[fp2];
|
||||
|
||||
faceLst.append(fTri);
|
||||
regionLst.append(patchI);
|
||||
@ -336,7 +293,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
}
|
||||
else
|
||||
{
|
||||
faceLst.append(fQuad);
|
||||
faceLst.append(Face(f));
|
||||
regionLst.append(patchI);
|
||||
}
|
||||
}
|
||||
@ -378,8 +335,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::NASfileFormat::NASfileFormat"
|
||||
"(const fileName&)"
|
||||
"fileFormats::NASsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Expected continuation symbol '*' when reading GRID*"
|
||||
<< " (double precision coordinate) output" << nl
|
||||
@ -408,8 +364,8 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
|
||||
|
||||
// transfer to normal lists
|
||||
points().transfer(pointLst);
|
||||
regions().transfer(regionLst);
|
||||
ParentType::points().transfer(pointLst);
|
||||
ParentType::regions().transfer(regionLst);
|
||||
|
||||
pointId.shrink();
|
||||
faceLst.shrink();
|
||||
@ -427,7 +383,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
// Relabel faces
|
||||
forAll(faceLst, i)
|
||||
{
|
||||
face& f = faceLst[i];
|
||||
Face& f = faceLst[i];
|
||||
forAll(f, fp)
|
||||
{
|
||||
f[fp] = nasToFoamPoint[f[fp]];
|
||||
@ -449,11 +405,10 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
|
||||
}
|
||||
|
||||
// transfer to normal lists
|
||||
faces().transfer(faceLst);
|
||||
ParentType::faces().transfer(faceLst);
|
||||
|
||||
setPatches(regionNames);
|
||||
ParentType::setPatches(regionNames);
|
||||
return true;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::NASfileFormat
|
||||
Foam::fileFormats::NASsurfaceFormat
|
||||
|
||||
Description
|
||||
Nastran surface reader.
|
||||
@ -37,17 +37,18 @@ Description
|
||||
@endverbatim
|
||||
|
||||
SourceFiles
|
||||
NASfileFormat.C
|
||||
NASsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef NASfileFormat_H
|
||||
#define NASfileFormat_H
|
||||
#ifndef NASsurfaceFormat_H
|
||||
#define NASsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "NASsurfaceFormatCore.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -57,54 +58,61 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class NASfileFormat Declaration
|
||||
Class NASsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class NASfileFormat
|
||||
template<class Face>
|
||||
class NASsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>,
|
||||
public NASsurfaceFormatCore
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef NASsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Do weird things to extract number
|
||||
static scalar parseNASCoord(const string&);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
NASfileFormat(const NASfileFormat&);
|
||||
NASsurfaceFormat(const NASsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const NASfileFormat&);
|
||||
void operator=(const NASsurfaceFormat<Face>&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
NASfileFormat();
|
||||
NASsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
NASfileFormat(const fileName&, const bool triangulate=false);
|
||||
NASsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=false
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new NASfileFormat(fName,triangulate)
|
||||
new NASsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~NASsurfaceFormat()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read from a file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -115,6 +123,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "NASsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
63
src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.C
Normal file
63
src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.C
Normal file
@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "NASsurfaceFormatCore.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
// Do weird things to extract number
|
||||
Foam::scalar Foam::fileFormats::NASsurfaceFormatCore::parseNASCoord
|
||||
(
|
||||
const string& s
|
||||
)
|
||||
{
|
||||
size_t expSign = s.find_last_of("+-");
|
||||
|
||||
if (expSign != string::npos && expSign > 0 && !isspace(s[expSign-1]))
|
||||
{
|
||||
scalar mantissa = readScalar(IStringStream(s.substr(0, expSign))());
|
||||
scalar exponent = readScalar(IStringStream(s.substr(expSign+1))());
|
||||
|
||||
if (s[expSign] == '-')
|
||||
{
|
||||
exponent = -exponent;
|
||||
}
|
||||
return mantissa*pow(10, exponent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return readScalar(IStringStream(s)());
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
89
src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.H
Normal file
89
src/surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.H
Normal file
@ -0,0 +1,89 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::NASsurfaceFormatCore
|
||||
|
||||
Description
|
||||
Internal class used by the NASsurfaceFormat
|
||||
|
||||
SourceFiles
|
||||
NASsurfaceFormatCore.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef NASsurfaceFormatCore_H
|
||||
#define NASsurfaceFormatCore_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class NASsurfaceFormatCore Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class NASsurfaceFormatCore
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Do weird things to extract number
|
||||
static scalar parseNASCoord(const string&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
NASsurfaceFormatCore()
|
||||
{}
|
||||
|
||||
// Destructor
|
||||
|
||||
~NASsurfaceFormatCore()
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
78
src/surfMesh/surfaceFormats/nas/NASsurfaceFormatRunTime.C
Normal file
78
src/surfMesh/surfaceFormats/nas/NASsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,78 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "NASsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
// .bdf (Bulk Data Format)
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
NASsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
bdf
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
NASsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
bdf
|
||||
);
|
||||
|
||||
// .nas (Nastran)
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
NASsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
nas
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
NASsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
nas
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,56 +24,19 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OBJfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "OBJsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
OBJfileFormat,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
OBJfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
OBJfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::OBJfileFormat::writeHead
|
||||
template<class Face>
|
||||
void Foam::fileFormats::OBJsurfaceFormat<Face>::writeHead
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const List<FaceType>& faceLst,
|
||||
const List<Face>& faceLst,
|
||||
const List<surfGroup>& patchLst
|
||||
)
|
||||
{
|
||||
@ -111,34 +74,58 @@ void Foam::fileFormats::OBJfileFormat::writeHead
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::OBJfileFormat::OBJfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::OBJsurfaceFormat<Face>::OBJsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::OBJfileFormat::OBJfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::OBJsurfaceFormat<Face>::OBJsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
IFstream is(fName);
|
||||
ThisType::read(fName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
// triangulation required?
|
||||
bool mustTriangulate = false;
|
||||
{
|
||||
Face f;
|
||||
if (f.max_size() == 3)
|
||||
{
|
||||
mustTriangulate = true;
|
||||
}
|
||||
}
|
||||
|
||||
IFstream is(fName);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::OBJfileFormat::OBJfileFormat(const fileName&)"
|
||||
"fileFormats::OBJsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << fName
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
DynamicList<point> pointLst;
|
||||
DynamicList<FaceType> faceLst;
|
||||
DynamicList<Face> faceLst;
|
||||
DynamicList<label> regionLst;
|
||||
HashTable<label> groupToPatch;
|
||||
|
||||
@ -148,13 +135,13 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string line = getLineNoComment(is);
|
||||
string line = ParentType::getLineNoComment(is);
|
||||
|
||||
// handle continuations
|
||||
if (line[line.size()-1] == '\\')
|
||||
{
|
||||
line.substr(0, line.size()-1);
|
||||
line += getLineNoComment(is);
|
||||
line += ParentType::getLineNoComment(is);
|
||||
}
|
||||
|
||||
// Read first word
|
||||
@ -240,9 +227,9 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
|
||||
}
|
||||
dynVertices.shrink();
|
||||
|
||||
FaceType f(SubList<label>(dynVertices, dynVertices.size()));
|
||||
UList<label>& f = static_cast<UList<label>&>(dynVertices);
|
||||
|
||||
if (triangulate && f.size() > 3)
|
||||
if (mustTriangulate)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
@ -262,30 +249,30 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
|
||||
}
|
||||
else
|
||||
{
|
||||
faceLst.append(f);
|
||||
faceLst.append(Face(f));
|
||||
regionLst.append(groupID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// transfer to normal lists
|
||||
points().transfer(pointLst);
|
||||
faces().transfer(faceLst);
|
||||
regions().transfer(regionLst);
|
||||
ParentType::points().transfer(pointLst);
|
||||
ParentType::faces().transfer(faceLst);
|
||||
ParentType::regions().transfer(regionLst);
|
||||
|
||||
setPatches(groupToPatch);
|
||||
ParentType::setPatches(groupToPatch);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::OBJfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::OBJsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<FaceType>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
|
||||
labelList faceMap;
|
||||
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
|
||||
@ -317,13 +304,14 @@ void Foam::fileFormats::OBJfileFormat::write
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::OBJfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::OBJsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<FaceType>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
writeHead(os, surf.points(), faceLst, patchLst);
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::OBJfileFormat
|
||||
Foam::fileFormats::OBJsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing Alias/Wavefront OBJ format.
|
||||
@ -31,17 +31,17 @@ Description
|
||||
Does not handle negative face indices.
|
||||
|
||||
SourceFiles
|
||||
OBJfileFormat.C
|
||||
OBJsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef OBJfileFormat_H
|
||||
#define OBJfileFormat_H
|
||||
#ifndef OBJsurfaceFormat_H
|
||||
#define OBJsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -51,27 +51,31 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class OBJfileFormat Declaration
|
||||
Class OBJsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class OBJfileFormat
|
||||
template<class Face>
|
||||
class OBJsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef OBJsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
OBJfileFormat(const OBJfileFormat&);
|
||||
OBJsurfaceFormat(const OBJsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const OBJfileFormat&);
|
||||
void operator=(const OBJsurfaceFormat<Face>&);
|
||||
|
||||
static void writeHead
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const List<FaceType>&,
|
||||
const List<Face>&,
|
||||
const List<surfGroup>&
|
||||
);
|
||||
|
||||
@ -80,46 +84,66 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
OBJfileFormat();
|
||||
OBJsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
OBJfileFormat(const fileName&, const bool triangulate=false);
|
||||
OBJsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate = false
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new OBJfileFormat(fName, triangulate)
|
||||
new OBJsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~OBJsurfaceFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName& fName, const keyedSurface& surf)
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName& fName, const meshedSurface& surf)
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
@ -140,6 +164,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "OBJsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
99
src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatRunTime.C
Normal file
99
src/surfMesh/surfaceFormats/obj/OBJsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OBJsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,56 +24,21 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OFFfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "OFFsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
OFFfileFormat,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
OFFfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
OFFfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::OFFfileFormat::writeHead
|
||||
template<class Face>
|
||||
void Foam::fileFormats::OFFsurfaceFormat<Face>::writeHead
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const List<FaceType>& faceLst,
|
||||
const List<Face>& faceLst,
|
||||
const List<surfGroup>& patchLst
|
||||
)
|
||||
{
|
||||
@ -116,39 +81,63 @@ void Foam::fileFormats::OFFfileFormat::writeHead
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::OFFfileFormat::OFFfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::OFFsurfaceFormat<Face>::OFFsurfaceFormat()
|
||||
:
|
||||
keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::OFFfileFormat::OFFfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::OFFsurfaceFormat<Face>::OFFsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
IFstream is(fName);
|
||||
ThisType::read(fName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
// triangulation required?
|
||||
bool mustTriangulate = false;
|
||||
{
|
||||
Face f;
|
||||
if (f.max_size() == 3)
|
||||
{
|
||||
mustTriangulate = true;
|
||||
}
|
||||
}
|
||||
|
||||
IFstream is(fName);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::OFFfileFormat(const fileName&)"
|
||||
"fileFormats::OFFsurfaceFormat<Face>::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << fName
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Read header
|
||||
string hdr = getLineNoComment(is);
|
||||
string hdr = ParentType::getLineNoComment(is);
|
||||
if (hdr != "OFF")
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::OFFfileFormat(const fileName&)"
|
||||
"fileFormats::OFFsurfaceFormat<Face>::read(const fileName&)"
|
||||
)
|
||||
<< "OFF file " << fName << " does not start with 'OFF'"
|
||||
<< exit(FatalError);
|
||||
@ -158,7 +147,7 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
|
||||
// get dimensions
|
||||
label nPoints, nEdges, nElems;
|
||||
|
||||
string line = getLineNoComment(is);
|
||||
string line = ParentType::getLineNoComment(is);
|
||||
{
|
||||
IStringStream lineStream(line);
|
||||
lineStream >> nPoints >> nElems >> nEdges;
|
||||
@ -169,7 +158,7 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
|
||||
forAll(pointLst, pointI)
|
||||
{
|
||||
scalar x, y, z;
|
||||
line = getLineNoComment(is);
|
||||
line = ParentType::getLineNoComment(is);
|
||||
{
|
||||
IStringStream lineStream(line);
|
||||
lineStream >> x >> y >> z;
|
||||
@ -179,25 +168,27 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
|
||||
|
||||
// Read faces - ignore optional region information
|
||||
// use a DynamicList for possible on-the-fly triangulation
|
||||
DynamicList<FaceType> faceLst(nElems);
|
||||
DynamicList<Face> faceLst(nElems);
|
||||
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
line = getLineNoComment(is);
|
||||
line = ParentType::getLineNoComment(is);
|
||||
{
|
||||
IStringStream lineStream(line);
|
||||
|
||||
label nVerts;
|
||||
lineStream >> nVerts;
|
||||
|
||||
face f(nVerts);
|
||||
List<label> verts(nVerts);
|
||||
|
||||
forAll(f, fp)
|
||||
forAll(verts, vertI)
|
||||
{
|
||||
lineStream >> f[fp];
|
||||
lineStream >> verts[vertI];
|
||||
}
|
||||
|
||||
if (triangulate && f.size() > 3)
|
||||
UList<label>& f = static_cast<UList<label>&>(verts);
|
||||
|
||||
if (mustTriangulate)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
@ -216,33 +207,32 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
|
||||
}
|
||||
else
|
||||
{
|
||||
faceLst.append(f);
|
||||
faceLst.append(Face(f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// transfer to normal lists
|
||||
points().transfer(pointLst);
|
||||
faces().transfer(faceLst);
|
||||
ParentType::points().transfer(pointLst);
|
||||
ParentType::faces().transfer(faceLst);
|
||||
|
||||
// no region information
|
||||
regions().setSize(size());
|
||||
regions() = 0;
|
||||
ParentType::regions().setSize(ThisType::size());
|
||||
ParentType::regions() = 0;
|
||||
|
||||
setPatches(0);
|
||||
ParentType::setPatches(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
void Foam::fileFormats::OFFfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::OFFsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<FaceType>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
|
||||
labelList faceMap;
|
||||
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
|
||||
@ -256,7 +246,7 @@ void Foam::fileFormats::OFFfileFormat::write
|
||||
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceMap[faceIndex++]];
|
||||
const Face& f = faceLst[faceMap[faceIndex++]];
|
||||
|
||||
os << f.size();
|
||||
forAll(f, fp)
|
||||
@ -273,13 +263,14 @@ void Foam::fileFormats::OFFfileFormat::write
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::OFFfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::OFFsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<FaceType>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
writeHead(os, surf.points(), faceLst, patchLst);
|
||||
@ -291,7 +282,7 @@ void Foam::fileFormats::OFFfileFormat::write
|
||||
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceIndex++];
|
||||
const Face& f = faceLst[faceIndex++];
|
||||
|
||||
os << f.size();
|
||||
forAll(f, fp)
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::OFFfileFormat
|
||||
Foam::fileFormats::OFFsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing Geomview OFF polyList format.
|
||||
@ -39,17 +39,17 @@ Note
|
||||
When writing, it is set to the region number (integer).
|
||||
|
||||
SourceFiles
|
||||
OFFfileFormat.C
|
||||
OFFsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef OFFfileFormat_H
|
||||
#define OFFfileFormat_H
|
||||
#ifndef OFFsurfaceFormat_H
|
||||
#define OFFsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -59,26 +59,31 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class OFFfileFormat Declaration
|
||||
Class OFFsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class OFFfileFormat
|
||||
template<class Face>
|
||||
class OFFsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef OFFsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
OFFfileFormat(const OFFfileFormat&);
|
||||
OFFsurfaceFormat(const OFFsurfaceFormat&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const OFFfileFormat&);
|
||||
void operator=(const OFFsurfaceFormat&);
|
||||
|
||||
static void writeHead
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const List<FaceType>&,
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const List<Face>&,
|
||||
const List<surfGroup>&
|
||||
);
|
||||
|
||||
@ -87,46 +92,64 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
OFFfileFormat();
|
||||
OFFsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
OFFfileFormat(const fileName&, const bool triangulate=false);
|
||||
OFFsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=false
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new OFFfileFormat(fName,triangulate)
|
||||
new OFFsurfaceFormat(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
virtual ~OFFsurfaceFormat()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName& fName, const keyedSurface& surf)
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName& fName, const meshedSurface& surf)
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
@ -147,6 +170,11 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "OFFsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
99
src/surfMesh/surfaceFormats/off/OFFsurfaceFormatRunTime.C
Normal file
99
src/surfMesh/surfaceFormats/off/OFFsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OFFsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,47 +24,21 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "SMESHfileFormat.H"
|
||||
#include "SMESHsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
SMESHfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
smesh
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
SMESHfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
smesh
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
void Foam::fileFormats::SMESHfileFormat::writeHead
|
||||
template<class Face>
|
||||
void Foam::fileFormats::SMESHsurfaceFormat<Face>::writeHead
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const List<face>& faceLst
|
||||
const List<Face>& faceLst
|
||||
)
|
||||
{
|
||||
// Write header
|
||||
@ -88,7 +62,8 @@ void Foam::fileFormats::SMESHfileFormat::writeHead
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::SMESHfileFormat::writeTail(Ostream& os)
|
||||
template<class Face>
|
||||
void Foam::fileFormats::SMESHsurfaceFormat<Face>::writeTail(Ostream& os)
|
||||
{
|
||||
os << "# </faces>" << nl
|
||||
<< nl
|
||||
@ -100,21 +75,22 @@ void Foam::fileFormats::SMESHfileFormat::writeTail(Ostream& os)
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::SMESHfileFormat::SMESHfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::SMESHsurfaceFormat<Face>::SMESHsurfaceFormat()
|
||||
:
|
||||
keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void
|
||||
Foam::fileFormats::SMESHfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
|
||||
writeHead(os, surf.points(), faceLst);
|
||||
|
||||
@ -126,7 +102,7 @@ Foam::fileFormats::SMESHfileFormat::write
|
||||
{
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceMap[faceIndex++]];
|
||||
const Face& f = faceLst[faceMap[faceIndex++]];
|
||||
|
||||
os << f.size();
|
||||
forAll(f, fp)
|
||||
@ -141,14 +117,14 @@ Foam::fileFormats::SMESHfileFormat::write
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Foam::fileFormats::SMESHfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
writeHead(os, surf.points(), faceLst);
|
||||
@ -172,5 +148,4 @@ Foam::fileFormats::SMESHfileFormat::write
|
||||
writeTail(os);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::SMESHfileFormat
|
||||
Foam::fileFormats::SMESHsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of writing tetgen SMESH format.
|
||||
@ -35,18 +35,18 @@ See Also
|
||||
http://tetgen.berlios.de/fformats.smesh.html
|
||||
|
||||
SourceFiles
|
||||
SMESHfileFormat.C
|
||||
SMESHsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef SMESHfileFormat_H
|
||||
#define SMESHfileFormat_H
|
||||
#ifndef SMESHsurfaceFormat_H
|
||||
#define SMESHsurfaceFormat_H
|
||||
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "Ostream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -56,24 +56,27 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class SMESHfileFormat Declaration
|
||||
Class SMESHsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class SMESHfileFormat
|
||||
template<class Face>
|
||||
class SMESHsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
// Private data
|
||||
//- Private typedefs for convenience
|
||||
typedef SMESHsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
SMESHfileFormat(const SMESHfileFormat&);
|
||||
SMESHsurfaceFormat(const SMESHsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const SMESHfileFormat&);
|
||||
void operator=(const SMESHsurfaceFormat<Face>&);
|
||||
|
||||
static void writeHead(Ostream&, const pointField&, const List<face>&);
|
||||
static void writeHead(Ostream&, const pointField&, const List<Face>&);
|
||||
static void writeTail(Ostream&);
|
||||
|
||||
public:
|
||||
@ -81,33 +84,52 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
SMESHfileFormat();
|
||||
SMESHsurfaceFormat();
|
||||
|
||||
// Selectors
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~SMESHsurfaceFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName& fName, const keyedSurface& surf)
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName& fName, const meshedSurface& surf)
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
|
||||
//- Write object
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
@ -124,6 +146,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "SMESHsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "SMESHsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
smesh
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
smesh
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
smesh
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
smesh
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,47 +24,12 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STARCDfileFormat.H"
|
||||
#include "STARCDsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "OSspecific.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
STARCDfileFormat,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
STARCDfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
STARCDfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//! @cond localscope
|
||||
const int starcdShellShape = 3;
|
||||
@ -74,7 +39,8 @@ const int starcdShellType = 4;
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileFormats::STARCDfileFormat::readHeader
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::STARCDsurfaceFormat<Face>::readHeader
|
||||
(
|
||||
IFstream& is,
|
||||
const word& signature
|
||||
@ -84,7 +50,7 @@ bool Foam::fileFormats::STARCDfileFormat::readHeader
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STARCDfileFormat::readHeader()"
|
||||
"fileFormats::STARCDsurfaceFormat::readHeader(...)"
|
||||
)
|
||||
<< "cannot read " << signature << " " << is.name()
|
||||
<< abort(FatalError);
|
||||
@ -112,7 +78,8 @@ bool Foam::fileFormats::STARCDfileFormat::readHeader
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDfileFormat::writeHeader
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const char* filetype
|
||||
@ -131,7 +98,8 @@ void Foam::fileFormats::STARCDfileFormat::writeHeader
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDfileFormat::writePoints
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STARCDsurfaceFormat<Face>::writePoints
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst
|
||||
@ -157,10 +125,11 @@ void Foam::fileFormats::STARCDfileFormat::writePoints
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::fileFormats::STARCDfileFormat::writeShell
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
|
||||
(
|
||||
Ostream& os,
|
||||
const face& f,
|
||||
const Face& f,
|
||||
const label cellId,
|
||||
const label cellTableId
|
||||
)
|
||||
@ -192,9 +161,10 @@ inline void Foam::fileFormats::STARCDfileFormat::writeShell
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::STARCDfileFormat::STARCDfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
@ -211,14 +181,39 @@ Body:
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulation
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
ThisType::read(fName);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
// triangulation required?
|
||||
bool mustTriangulate = false;
|
||||
{
|
||||
Face f;
|
||||
if (f.max_size() == 3)
|
||||
{
|
||||
mustTriangulate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fileName baseName = fName.lessExt();
|
||||
autoPtr<IFstream> isPtr;
|
||||
|
||||
@ -236,7 +231,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STARCDfileFormat::STARCDfileFormat(const fileName&)"
|
||||
"fileFormats::STARCDsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << (baseName + ".vrt")
|
||||
<< exit(FatalError);
|
||||
@ -257,7 +252,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
}
|
||||
|
||||
// transfer to normal lists
|
||||
points().transfer(pointLst);
|
||||
ParentType::points().transfer(pointLst);
|
||||
|
||||
// Build inverse mapping (index to point)
|
||||
pointId.shrink();
|
||||
@ -269,7 +264,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
pointId.clear();
|
||||
|
||||
|
||||
DynamicList<face> faceLst;
|
||||
DynamicList<Face> faceLst;
|
||||
DynamicList<label> regionLst;
|
||||
|
||||
// From face cellTableId to patchId
|
||||
@ -286,7 +281,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STARCDfileFormat::STARCDfileFormat(const fileName&)"
|
||||
"fileFormats::STARCDsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << (baseName + ".cel")
|
||||
<< exit(FatalError);
|
||||
@ -342,20 +337,27 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
starLabels[i] = mapToFoamPointId[starLabels[i]];
|
||||
}
|
||||
|
||||
if (triangulation && nLabels > 3)
|
||||
if (mustTriangulate && nLabels > 3)
|
||||
{
|
||||
face f
|
||||
(
|
||||
SubList<label>(starLabels, nLabels)
|
||||
);
|
||||
|
||||
faceList triFaces(f.nTriangles(points()));
|
||||
faceList triFaces(f.nTriangles(ParentType::points()));
|
||||
label nTri = 0;
|
||||
f.triangles(points(), nTri, triFaces);
|
||||
f.triangles(ParentType::points(), nTri, triFaces);
|
||||
|
||||
forAll(triFaces, faceI)
|
||||
{
|
||||
faceLst.append(triFaces[faceI]);
|
||||
// a triangle, but not yet a triFace
|
||||
faceLst.append
|
||||
(
|
||||
triFace
|
||||
(
|
||||
static_cast<UList<label>&>(triFaces[faceI])
|
||||
)
|
||||
);
|
||||
regionLst.append(patchI);
|
||||
}
|
||||
}
|
||||
@ -363,7 +365,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
{
|
||||
faceLst.append
|
||||
(
|
||||
face(SubList<label>(starLabels, nLabels))
|
||||
Face(SubList<label>(starLabels, nLabels))
|
||||
);
|
||||
regionLst.append(patchI);
|
||||
}
|
||||
@ -384,21 +386,23 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
|
||||
}
|
||||
|
||||
// transfer to normal lists
|
||||
faces().transfer(faceLst);
|
||||
regions().transfer(regionLst);
|
||||
ParentType::faces().transfer(faceLst);
|
||||
ParentType::regions().transfer(regionLst);
|
||||
|
||||
setPatches(regionNames);
|
||||
ParentType::setPatches(regionNames);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::STARCDfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
|
||||
(
|
||||
const fileName& fName,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
|
||||
fileName baseName = fName.lessExt();
|
||||
autoPtr<OFstream> osPtr;
|
||||
@ -421,7 +425,7 @@ void Foam::fileFormats::STARCDfileFormat::write
|
||||
|
||||
forAll(patch, patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceMap[faceIndex++]];
|
||||
const Face& f = faceLst[faceMap[faceIndex++]];
|
||||
|
||||
writeShell(osPtr(), f, faceIndex, patchI + 1);
|
||||
}
|
||||
@ -429,13 +433,14 @@ void Foam::fileFormats::STARCDfileFormat::write
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
|
||||
(
|
||||
const fileName& fName,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
|
||||
@ -456,7 +461,7 @@ void Foam::fileFormats::STARCDfileFormat::write
|
||||
|
||||
forAll(patch, patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceIndex++];
|
||||
const Face& f = faceLst[faceIndex++];
|
||||
writeShell(osPtr(), f, faceIndex, patchI + 1);
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::STARCDfileFormat
|
||||
Foam::fileFormats::STARCDsurfaceFormat
|
||||
|
||||
Description
|
||||
Read/write the surface shells from pro-STAR vrt/cel files.
|
||||
@ -35,19 +35,18 @@ See Also
|
||||
Foam::meshReaders::STARCD
|
||||
|
||||
SourceFiles
|
||||
STARCDfileFormat.C
|
||||
STARCDsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef STARCDfileFormat_H
|
||||
#define STARCDfileFormat_H
|
||||
#ifndef STARCDsurfaceFormat_H
|
||||
#define STARCDsurfaceFormat_H
|
||||
|
||||
#include "STLtriangle.H"
|
||||
#include "IFstream.H"
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -57,22 +56,25 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class STARCDfileFormat Declaration
|
||||
Class STARCDsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class STARCDfileFormat
|
||||
template<class Face>
|
||||
class STARCDsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
// Private data
|
||||
//- Private typedefs for convenience
|
||||
typedef STARCDsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDfileFormat(const STARCDfileFormat&);
|
||||
STARCDsurfaceFormat(const STARCDsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDfileFormat&);
|
||||
void operator=(const STARCDsurfaceFormat<Face>&);
|
||||
|
||||
|
||||
static bool readHeader(IFstream&, const word&);
|
||||
@ -84,7 +86,7 @@ class STARCDfileFormat
|
||||
static inline void writeShell
|
||||
(
|
||||
Ostream&,
|
||||
const face&,
|
||||
const Face&,
|
||||
const label cellId,
|
||||
const label cellTableId
|
||||
);
|
||||
@ -94,42 +96,45 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
STARCDfileFormat();
|
||||
STARCDsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
STARCDfileFormat(const fileName&, const bool triangulate=true);
|
||||
STARCDsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=true
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new STARCDfileFormat(fName, triangulate)
|
||||
new STARCDsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
virtual ~STARCDsurfaceFormat()
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void write(const fileName&, const MeshedSurface<Face>&);
|
||||
|
||||
//- Write to Ostream as one large file - not really useful
|
||||
virtual void write(Ostream&) const
|
||||
{
|
||||
notImplemented("fileFormats::STARCDfileFormat::write(Ostream&)");
|
||||
notImplemented("fileFormats::STARCDsurfaceFormat::write(Ostream&)");
|
||||
}
|
||||
|
||||
};
|
||||
@ -142,6 +147,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "STARCDsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STARCDsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
inp
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
386
src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C
Normal file
386
src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C
Normal file
@ -0,0 +1,386 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STLsurfaceFormat.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const Face& f,
|
||||
const vector& norm
|
||||
)
|
||||
{
|
||||
// simple triangulation about f[0].
|
||||
// better triangulation should have been done before
|
||||
const point& p0 = pointLst[f[0]];
|
||||
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
|
||||
{
|
||||
label fp2 = (fp1 + 1) % f.size();
|
||||
|
||||
const point& p1 = pointLst[f[fp1]];
|
||||
const point& p2 = pointLst[f[fp2]];
|
||||
|
||||
// write STL triangle
|
||||
os << " facet normal "
|
||||
<< norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl
|
||||
<< " outer loop\n"
|
||||
<< " vertex "
|
||||
<< p0.x() << ' ' << p0.y() << ' ' << p0.z() << nl
|
||||
<< " vertex "
|
||||
<< p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl
|
||||
<< " vertex "
|
||||
<< p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl
|
||||
<< " endloop\n"
|
||||
<< " endfacet" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
|
||||
(
|
||||
ostream& os,
|
||||
const pointField& pointLst,
|
||||
const Face& f,
|
||||
const vector& norm,
|
||||
const label patchI
|
||||
)
|
||||
{
|
||||
// simple triangulation about f[0].
|
||||
// better triangulation should have been done before
|
||||
const point& p0 = pointLst[f[0]];
|
||||
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
|
||||
{
|
||||
label fp2 = (fp1 + 1) % f.size();
|
||||
|
||||
STLtriangle stlTri
|
||||
(
|
||||
norm,
|
||||
p0,
|
||||
pointLst[f[fp1]],
|
||||
pointLst[f[fp2]],
|
||||
patchI
|
||||
);
|
||||
|
||||
stlTri.write(os);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write sorted:
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::writeASCII
|
||||
(
|
||||
Ostream& os,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
|
||||
labelList faceMap;
|
||||
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
// Print all faces belonging to this region
|
||||
const surfGroup& patch = patchLst[patchI];
|
||||
|
||||
os << "solid " << patch.name() << endl;
|
||||
forAll(patch, patchFaceI)
|
||||
{
|
||||
const label faceI = faceMap[faceIndex++];
|
||||
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
|
||||
}
|
||||
|
||||
os << "endsolid " << patch.name() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// write sorted:
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::writeASCII
|
||||
(
|
||||
Ostream& os,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
|
||||
// force triangulation, but just do the cheapest form possible
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
// Print all faces belonging to this region
|
||||
const surfGroup& patch = patchLst[patchI];
|
||||
|
||||
os << "solid " << patch.name() << endl;
|
||||
|
||||
forAll(patch, patchFaceI)
|
||||
{
|
||||
const label faceI = faceIndex++;
|
||||
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
|
||||
}
|
||||
|
||||
os << "endsolid " << patch.name() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write unsorted:
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY
|
||||
(
|
||||
ostream& os,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<label>& regionLst = surf.regions();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
|
||||
// Write the STL header
|
||||
STLsurfaceFormatCore::writeHeaderBINARY(os);
|
||||
|
||||
// force triangulation, but just do the cheapest form possible
|
||||
unsigned int nTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
nTris += faceLst[faceI].size() - 2;
|
||||
}
|
||||
|
||||
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
// always write unsorted
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
writeShell
|
||||
(
|
||||
os,
|
||||
pointLst,
|
||||
faceLst[faceI],
|
||||
normLst[faceI],
|
||||
regionLst[faceI]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY
|
||||
(
|
||||
ostream& os,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const vectorField& normLst = surf.faceNormals();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
// Write the STL header
|
||||
STLsurfaceFormatCore::writeHeaderBINARY(os);
|
||||
|
||||
// force triangulation, but just do the cheapest form possible
|
||||
unsigned int nTris = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
nTris += faceLst[faceI].size() - 2;
|
||||
}
|
||||
|
||||
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(patchLst, patchI)
|
||||
{
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
writeShell
|
||||
(
|
||||
os,
|
||||
pointLst,
|
||||
faceLst[faceIndex],
|
||||
normLst[faceIndex],
|
||||
patchI
|
||||
);
|
||||
|
||||
++faceIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
Foam::fileFormats::STLsurfaceFormat<Face>::STLsurfaceFormat()
|
||||
:
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::fileFormats::STLsurfaceFormat<Face>::STLsurfaceFormat
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
ParentType()
|
||||
{
|
||||
ThisType::read(fName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::STLsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
// read in the values
|
||||
STLsurfaceFormatCore reader(fName);
|
||||
|
||||
pointField& pointLst = ParentType::points();
|
||||
List<Face>& faceLst = ParentType::faces();
|
||||
List<label>& regionLst = ParentType::regions();
|
||||
|
||||
// transfer
|
||||
pointLst.transfer(reader.points());
|
||||
regionLst.transfer(reader.regions());
|
||||
|
||||
// assemble the faces:
|
||||
faceLst.setSize(regionLst.size());
|
||||
|
||||
label ptI = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
fTri[0] = ptI++;
|
||||
fTri[1] = ptI++;
|
||||
fTri[2] = ptI++;
|
||||
|
||||
faceLst[faceI] = fTri;
|
||||
}
|
||||
|
||||
if (reader.binary())
|
||||
{
|
||||
ParentType::setPatches(reader.maxRegionId());
|
||||
}
|
||||
else
|
||||
{
|
||||
ParentType::setPatches(reader.groupToPatch());
|
||||
}
|
||||
|
||||
ParentType::stitchFaces(SMALL);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
writeASCII(os, surf);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
writeASCII(os, surf);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const word ext = fName.ext();
|
||||
|
||||
// handle 'stlb' as binary directly
|
||||
if (ext == "stlb")
|
||||
{
|
||||
std::ofstream ofs(fName.c_str(), std::ios::binary);
|
||||
writeBINARY(ofs, surf);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeASCII(OFstream(fName)(), surf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
void Foam::fileFormats::STLsurfaceFormat<Face>::write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const word ext = fName.ext();
|
||||
|
||||
// handle 'stlb' as binary directly
|
||||
if (ext == "stlb")
|
||||
{
|
||||
std::ofstream ofs(fName.c_str(), std::ios::binary);
|
||||
writeBINARY(ofs, surf);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeASCII(OFstream(fName)(), surf);
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -23,26 +23,23 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::STLfileFormat
|
||||
Foam::fileFormats::STLsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing STL files (ASCII and binary).
|
||||
|
||||
SourceFiles
|
||||
STLfileFormat.C
|
||||
STLfileFormatASCII.L
|
||||
STLsurfaceFormat.C
|
||||
STLsurfaceFormatASCII.L
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef STLfileFormat_H
|
||||
#define STLfileFormat_H
|
||||
#ifndef STLsurfaceFormat_H
|
||||
#define STLsurfaceFormat_H
|
||||
|
||||
#include "STLtriangle.H"
|
||||
#include "IFstream.H"
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "STLsurfaceFormatCore.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -52,109 +49,125 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class STLfileFormat Declaration
|
||||
Class STLsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class STLfileFormat
|
||||
template<class Face>
|
||||
class STLsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
// Private data
|
||||
//- Private typedefs for convenience
|
||||
typedef STLsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
//- The number of bytes in the STL binary header
|
||||
static const int headerSize=80;
|
||||
// Private data
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STLfileFormat(const STLfileFormat&);
|
||||
STLsurfaceFormat(const STLsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STLfileFormat&);
|
||||
void operator=(const STLsurfaceFormat<Face>&);
|
||||
|
||||
bool detectBINARY(const fileName&);
|
||||
|
||||
bool readASCII(IFstream&, const off_t);
|
||||
bool readBINARY(IFstream&, const off_t);
|
||||
|
||||
//- write face in ASCII
|
||||
//- Write Face in ASCII
|
||||
static inline void writeShell
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const face&,
|
||||
const Face&,
|
||||
const vector& norm
|
||||
);
|
||||
|
||||
//- write face in BINARY
|
||||
//- Write Face in BINARY
|
||||
static inline void writeShell
|
||||
(
|
||||
ostream&,
|
||||
const pointField&,
|
||||
const face&,
|
||||
const Face&,
|
||||
const vector&,
|
||||
const label patchI
|
||||
);
|
||||
|
||||
|
||||
//- Write keySurface
|
||||
static void writeASCII(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void writeASCII(Ostream&, const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void writeBINARY(ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void writeBINARY(ostream&, const UnsortedMeshedSurface<Face>&);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void writeASCII(Ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void writeASCII(Ostream&, const MeshedSurface<Face>&);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void writeBINARY(ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void writeBINARY(ostream&, const MeshedSurface<Face>&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
STLfileFormat();
|
||||
STLsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
STLfileFormat(const fileName&, const bool triangulate=true);
|
||||
STLsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=true
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new STLfileFormat(fName,triangulate)
|
||||
new STLsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
virtual ~STLsurfaceFormat()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write keyedSurface
|
||||
//- Write UnsortedMeshedSurface (as ASCII)
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface (as ASCII)
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// The ASCII output is sorted by patch, the binary output is unsorted
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
static void write
|
||||
(
|
||||
const fileName&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write keyedSurface
|
||||
//- Write MeshedSurface
|
||||
// The ASCII output is sorted by patch, the binary output is unsorted
|
||||
static void write(const fileName&, const keyedSurface&);
|
||||
static void write
|
||||
(
|
||||
const fileName&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName&, const meshedSurface&);
|
||||
|
||||
//- Write object
|
||||
//- Write object (only ASCII output)
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
write(os, *this);
|
||||
@ -170,6 +183,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "STLsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
@ -32,8 +32,7 @@ License
|
||||
------ local definitions
|
||||
\* ------------------------------------------------------------------------ */
|
||||
|
||||
#include "STLfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "STLsurfaceFormatCore.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -111,7 +110,7 @@ public:
|
||||
}
|
||||
|
||||
//- region names
|
||||
const HashTable<label>& groupToPatch() const
|
||||
HashTable<label>& groupToPatch()
|
||||
{
|
||||
return groupToPatch_;
|
||||
}
|
||||
@ -360,7 +359,7 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
|
||||
yy_pop_state();
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STLfileFormat::readASCII(const fileName& STLfileName)"
|
||||
"fileFormats::STLsurfaceFormatCore::readASCII(const fileName&)"
|
||||
) << "while " << stateNames[YY_START] << " on line " << lineNo_ << nl
|
||||
<< " expected " << stateExpects[YY_START]
|
||||
<< " but found '" << startError_.c_str() << YYText() << "'"
|
||||
@ -379,45 +378,26 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
|
||||
//
|
||||
// member function
|
||||
//
|
||||
bool
|
||||
Foam::fileFormats::STLfileFormat::readASCII
|
||||
bool Foam::fileFormats::STLsurfaceFormatCore::readASCII
|
||||
(
|
||||
IFstream& ifs,
|
||||
const off_t fileSize
|
||||
)
|
||||
{
|
||||
binary_ = false;
|
||||
|
||||
// Create the lexer with the approximate number of vertices in the STL
|
||||
// from the file size
|
||||
STLASCIILexer lexer(&ifs.stdStream(), fileSize/400);
|
||||
while (lexer.lex() != 0) {}
|
||||
|
||||
// transfer to normal lists
|
||||
points().transfer(lexer.points());
|
||||
regions().transfer(lexer.facets());
|
||||
|
||||
// make our triangles directly
|
||||
List<FaceType>& faceLst = faces();
|
||||
faceLst.setSize(regions().size());
|
||||
|
||||
label ptI = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
fTri[0] = ptI++;
|
||||
fTri[1] = ptI++;
|
||||
fTri[2] = ptI++;
|
||||
|
||||
faceLst[faceI] = fTri;
|
||||
}
|
||||
|
||||
setPatches(lexer.groupToPatch());
|
||||
stitchFaces(SMALL);
|
||||
|
||||
points_.transfer(lexer.points());
|
||||
regions_.transfer(lexer.facets());
|
||||
groupToPatch_.transfer(lexer.groupToPatch());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------ *\
|
||||
------ End of STLfileFormatASCII.L
|
||||
\* ------------------------------------------------------------------------ */
|
||||
236
src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C
Normal file
236
src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.C
Normal file
@ -0,0 +1,236 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STLsurfaceFormatCore.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
#undef DEBUG_STLBINARY
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
// check binary by getting the header and number of facets
|
||||
// this seems to work better than the old token-based method
|
||||
// - some programs (eg, pro-STAR) have 'solid' as the first word in
|
||||
// the binary header.
|
||||
// - using wordToken can cause an abort if non-word (binary) content
|
||||
// is detected ... this is not exactly what we want.
|
||||
int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
off_t fileSize = Foam::size(fName);
|
||||
|
||||
IFstream ifs(fName, IOstream::BINARY);
|
||||
istream& is = ifs.stdStream();
|
||||
|
||||
// Read the STL header
|
||||
char header[headerSize];
|
||||
is.read(header, headerSize);
|
||||
|
||||
// Check that stream is OK, if not this may be an ASCII file
|
||||
if (!is.good())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read the number of triangles in the STl file
|
||||
// (note: read as int so we can check whether >2^31)
|
||||
int nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
// Check that stream is OK and number of triangles is positive,
|
||||
// if not this may be an ASCII file
|
||||
//
|
||||
// Also compare the file size with that expected from the number of tris
|
||||
// If the comparison is not sensible then it may be an ASCII file
|
||||
if
|
||||
(
|
||||
!is
|
||||
|| nTris < 0
|
||||
|| nTris < (fileSize - headerSize)/50
|
||||
|| nTris > (fileSize - headerSize)/25
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// looks like it might be BINARY, return number of triangles
|
||||
return nTris;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
|
||||
(
|
||||
IFstream& ifs,
|
||||
const off_t fileSize
|
||||
)
|
||||
{
|
||||
binary_ = true;
|
||||
istream& is = ifs.stdStream();
|
||||
|
||||
// Read the STL header
|
||||
char header[headerSize];
|
||||
is.read(header, headerSize);
|
||||
|
||||
// Check that stream is OK, if not this may be an ASCII file
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STLsurfaceFormatCore::readBINARY(IFstream&)"
|
||||
)
|
||||
<< "problem reading header, perhaps file is not binary "
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Read the number of triangles in the STl file
|
||||
// (note: read as int so we can check whether >2^31)
|
||||
int nTris;
|
||||
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
// Check that stream is OK and number of triangles is positive,
|
||||
// if not this maybe an ASCII file
|
||||
//
|
||||
// Also compare the file size with that expected from the number of tris
|
||||
// If the comparison is not sensible then it may be an ASCII file
|
||||
if
|
||||
(
|
||||
!is
|
||||
|| nTris < 0
|
||||
|| nTris < (fileSize - headerSize)/50
|
||||
|| nTris > (fileSize - headerSize)/25
|
||||
)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::STLsurfaceFormatCore::readBINARY(IFstream&)"
|
||||
)
|
||||
<< "problem reading number of triangles, perhaps file is not binary"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_STLBINARY
|
||||
Info<< "# " << nTris << " facets" << endl;
|
||||
label prevRegion = -1;
|
||||
#endif
|
||||
|
||||
points_.setSize(3*nTris);
|
||||
regions_.setSize(nTris);
|
||||
|
||||
label ptI = 0;
|
||||
forAll(regions_, faceI)
|
||||
{
|
||||
// Read an STL triangle
|
||||
STLtriangle stlTri(is);
|
||||
|
||||
// transcript the vertices of the STL triangle -> points
|
||||
points_[ptI++] = stlTri.a();
|
||||
points_[ptI++] = stlTri.b();
|
||||
points_[ptI++] = stlTri.c();
|
||||
|
||||
// interprete colour as a region
|
||||
regions_[faceI] = stlTri.region();
|
||||
if (maxRegionId_ < stlTri.region())
|
||||
{
|
||||
maxRegionId_ = stlTri.region();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_STLBINARY
|
||||
if (prevRegion != stlTri.region())
|
||||
{
|
||||
if (prevRegion != -1)
|
||||
{
|
||||
Info<< "endsolid region" << prevRegion << nl;
|
||||
}
|
||||
prevRegion = stlTri.region();
|
||||
|
||||
Info<< "solid region" << prevRegion << nl;
|
||||
}
|
||||
|
||||
Info<< " facet normal " << stlTri.normal() << nl;
|
||||
Info<< " outer loop" << nl;
|
||||
Info<< " vertex " << stlTri.a() << nl;
|
||||
Info<< " vertex " << stlTri.b() << nl;
|
||||
Info<< " vertex " << stlTri.c() << nl;
|
||||
Info<< " outer loop" << nl;
|
||||
Info<< " endfacet" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::STLsurfaceFormatCore::STLsurfaceFormatCore
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
binary_(false),
|
||||
points_(0),
|
||||
regions_(0),
|
||||
maxRegionId_(0),
|
||||
groupToPatch_(0)
|
||||
{
|
||||
off_t fileSize = Foam::size(fName);
|
||||
|
||||
// auto-detect ascii/binary
|
||||
if (detectBINARY(fName))
|
||||
{
|
||||
readBINARY(IFstream(fName, IOstream::BINARY)(), fileSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
readASCII(IFstream(fName)(), fileSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::STLsurfaceFormatCore::~STLsurfaceFormatCore()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::STLsurfaceFormatCore::writeHeaderBINARY(ostream& os)
|
||||
{
|
||||
// Write the STL header, avoid possible trailing junk
|
||||
string header("STL binary file", headerSize);
|
||||
for (label i = header.size(); i < headerSize; ++i)
|
||||
{
|
||||
header[i] = 0;
|
||||
}
|
||||
os.write(header.c_str(), headerSize);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
174
src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H
Normal file
174
src/surfMesh/surfaceFormats/stl/STLsurfaceFormatCore.H
Normal file
@ -0,0 +1,174 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::STLsurfaceFormatCore
|
||||
|
||||
Description
|
||||
Internal class used by the STLsurfaceFormat
|
||||
|
||||
SourceFiles
|
||||
STLsurfaceFormatCore.C
|
||||
STLsurfaceFormatASCII.L
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef STLsurfaceFormatCore_H
|
||||
#define STLsurfaceFormatCore_H
|
||||
|
||||
#include "STLtriangle.H"
|
||||
#include "triFace.H"
|
||||
#include "IFstream.H"
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class STLsurfaceFormatCore Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class STLsurfaceFormatCore
|
||||
{
|
||||
// Private Data
|
||||
|
||||
bool binary_;
|
||||
|
||||
//- The points supporting the facets
|
||||
pointField points_;
|
||||
|
||||
//- The regions associated with the faces
|
||||
List<label> regions_;
|
||||
|
||||
label maxRegionId_;
|
||||
|
||||
HashTable<label> groupToPatch_;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STLsurfaceFormatCore(const STLsurfaceFormatCore&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STLsurfaceFormatCore&);
|
||||
|
||||
//- Determine the file type
|
||||
static int detectBINARY(const fileName&);
|
||||
|
||||
//- Read ASCII, set groupToPatch
|
||||
bool readASCII(IFstream&, const off_t);
|
||||
|
||||
//- Read BINARY, set maxRegionId
|
||||
bool readBINARY(IFstream&, const off_t);
|
||||
|
||||
public:
|
||||
|
||||
// Static Data
|
||||
|
||||
//- The number of bytes in the STL binary header
|
||||
static const int headerSize = 80;
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Write "STL binary file" to stream
|
||||
static void writeHeaderBINARY(ostream&);
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Read from file, filling in the information
|
||||
STLsurfaceFormatCore
|
||||
(
|
||||
const fileName&
|
||||
);
|
||||
|
||||
// Destructor
|
||||
|
||||
~STLsurfaceFormatCore();
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- File was detected to be STL binary
|
||||
bool binary() const
|
||||
{
|
||||
return binary_;
|
||||
}
|
||||
|
||||
//- The number of facets is the number of regions
|
||||
label size() const
|
||||
{
|
||||
return regions_.size();
|
||||
}
|
||||
|
||||
//- Flush all values
|
||||
void clear()
|
||||
{
|
||||
points_.clear();
|
||||
regions_.clear();
|
||||
groupToPatch_.clear();
|
||||
}
|
||||
|
||||
//- Return full access to the faces
|
||||
pointField& points()
|
||||
{
|
||||
return points_;
|
||||
}
|
||||
|
||||
//- Return full access to the regions
|
||||
List<label>& regions()
|
||||
{
|
||||
return regions_;
|
||||
}
|
||||
|
||||
//- The max regionId when reading binary files
|
||||
label maxRegionId() const
|
||||
{
|
||||
return maxRegionId_;
|
||||
}
|
||||
|
||||
//- The group/patch information when reading ASCII files
|
||||
const HashTable<label>& groupToPatch() const
|
||||
{
|
||||
return groupToPatch_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
154
src/surfMesh/surfaceFormats/stl/STLsurfaceFormatRunTime.C
Normal file
154
src/surfMesh/surfaceFormats/stl/STLsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,154 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STLsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
260
src/surfMesh/surfaceFormats/surfaceFormatsCore.C
Normal file
260
src/surfMesh/surfaceFormats/surfaceFormatsCore.C
Normal file
@ -0,0 +1,260 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "surfaceFormatsCore.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "Time.H"
|
||||
#include "SortableList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// File extension for 'native' raw format
|
||||
Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs");
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
//- Check if file extension corresponds to 'native' surface format
|
||||
bool
|
||||
Foam::fileFormats::surfaceFormatsCore::isNative(const word& ext)
|
||||
{
|
||||
return (ext == nativeExt);
|
||||
}
|
||||
|
||||
|
||||
Foam::string
|
||||
Foam::fileFormats::surfaceFormatsCore::getLineNoComment
|
||||
(
|
||||
IFstream& is
|
||||
)
|
||||
{
|
||||
string line;
|
||||
do
|
||||
{
|
||||
is.getLine(line);
|
||||
}
|
||||
while ((line.size() == 0 || line[0] == '#') && is.good());
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName
|
||||
Foam::fileFormats::surfaceFormatsCore::triSurfInstance
|
||||
(
|
||||
const Time& d,
|
||||
const word& subdirName
|
||||
)
|
||||
{
|
||||
fileName foamName(d.caseName() + ".ofs");
|
||||
|
||||
// Search back through the time directories list to find the time
|
||||
// closest to and lower than current time
|
||||
|
||||
instantList ts = d.times();
|
||||
label i;
|
||||
|
||||
for (i=ts.size()-1; i>=0; i--)
|
||||
{
|
||||
if (ts[i].value() <= d.timeOutputValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Noting that the current directory has already been searched
|
||||
// for mesh data, start searching from the previously stored time directory
|
||||
|
||||
if (i>=0)
|
||||
{
|
||||
for (label j=i; j>=0; j--)
|
||||
{
|
||||
if (file(d.path()/ts[j].name()/subdirName/foamName))
|
||||
{
|
||||
return ts[j].name();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "constant";
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName
|
||||
Foam::fileFormats::surfaceFormatsCore::triSurfName
|
||||
(
|
||||
const Time& d,
|
||||
const word& subdirName
|
||||
)
|
||||
{
|
||||
fileName foamName(d.caseName() + ".ofs");
|
||||
|
||||
// Search back through the time directories list to find the time
|
||||
// closest to and lower than current time
|
||||
|
||||
instantList ts = d.times();
|
||||
label i;
|
||||
|
||||
for (i=ts.size()-1; i>=0; i--)
|
||||
{
|
||||
if (ts[i].value() <= d.timeOutputValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Noting that the current directory has already been searched
|
||||
// for mesh data, start searching from the previously stored time directory
|
||||
|
||||
if (i>=0)
|
||||
{
|
||||
for (label j=i; j>=0; j--)
|
||||
{
|
||||
fileName testName(d.path()/ts[j].name()/subdirName/foamName);
|
||||
|
||||
if (file(testName))
|
||||
{
|
||||
return testName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return d.path()/"constant"/subdirName/foamName;
|
||||
}
|
||||
|
||||
|
||||
// Returns patch info.
|
||||
// Sets faceMap to the indexing according to patch numbers.
|
||||
// Patch numbers start at 0.
|
||||
Foam::surfGroupList
|
||||
Foam::fileFormats::surfaceFormatsCore::sortedPatchRegions
|
||||
(
|
||||
const UList<label>& regionLst,
|
||||
const Map<word>& patchNames,
|
||||
labelList& faceMap
|
||||
)
|
||||
{
|
||||
// determine sort order according to region numbers
|
||||
|
||||
// std::sort() really seems to mix up the order.
|
||||
// and std::stable_sort() might take too long / too much memory
|
||||
|
||||
// Assuming that we have relatively fewer regions compared to the
|
||||
// number of items, just do it ourselves
|
||||
|
||||
// step 1: get region sizes and store (regionId => patchI)
|
||||
Map<label> regionLookup;
|
||||
forAll(regionLst, faceI)
|
||||
{
|
||||
const label regId = regionLst[faceI];
|
||||
|
||||
Map<label>::iterator iter = regionLookup.find(regId);
|
||||
if (iter == regionLookup.end())
|
||||
{
|
||||
regionLookup.insert(regId, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
iter()++;
|
||||
}
|
||||
}
|
||||
|
||||
// step 2: assign start/size (and name) to the newPatches
|
||||
// re-use the lookup to map (regionId => patchI)
|
||||
surfGroupList patchLst(regionLookup.size());
|
||||
label patchStart = 0;
|
||||
label patchI = 0;
|
||||
forAllIter(Map<label>, regionLookup, iter)
|
||||
{
|
||||
label regId = iter.key();
|
||||
|
||||
word patchName;
|
||||
Map<word>::const_iterator iter2 = patchNames.find(regId);
|
||||
if (iter2 == patchNames.end())
|
||||
{
|
||||
patchName = word("patch") + ::Foam::name(patchI);
|
||||
}
|
||||
else
|
||||
{
|
||||
patchName = iter2();
|
||||
}
|
||||
|
||||
patchLst[patchI] = surfGroup
|
||||
(
|
||||
patchName,
|
||||
0, // initialize with zero size
|
||||
patchStart,
|
||||
patchI
|
||||
);
|
||||
|
||||
// increment the start for the next patch
|
||||
// and save the (regionId => patchI) mapping
|
||||
patchStart += iter();
|
||||
iter() = patchI++;
|
||||
}
|
||||
|
||||
|
||||
// step 3: build the re-ordering
|
||||
faceMap.setSize(regionLst.size());
|
||||
|
||||
forAll(regionLst, faceI)
|
||||
{
|
||||
label patchI = regionLookup[regionLst[faceI]];
|
||||
|
||||
faceMap[faceI] = patchLst[patchI].start() + patchLst[patchI].size()++;
|
||||
}
|
||||
|
||||
// with reordered faces registered in faceMap
|
||||
return patchLst;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::surfaceFormatsCore::~surfaceFormatsCore()
|
||||
{}
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// ************************************************************************* //
|
||||
127
src/surfMesh/surfaceFormats/surfaceFormatsCore.H
Normal file
127
src/surfMesh/surfaceFormats/surfaceFormatsCore.H
Normal file
@ -0,0 +1,127 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::surfaceFormatsCore
|
||||
|
||||
Description
|
||||
A collection of helper functions for reading/writing surface formats.
|
||||
|
||||
SourceFiles
|
||||
surfaceFormatsCore.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef surfaceFormatsCore_H
|
||||
#define surfaceFormatsCore_H
|
||||
|
||||
#include "surfPatchIdentifierList.H"
|
||||
#include "surfGroupList.H"
|
||||
#include "labelList.H"
|
||||
#include "Map.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
class IFstream;
|
||||
class Time;
|
||||
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class surfaceFormatsCore Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class surfaceFormatsCore
|
||||
{
|
||||
public:
|
||||
|
||||
// Static Data
|
||||
|
||||
//- The file extension corresponding to 'native' surface format
|
||||
static word nativeExt;
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Check if file extension corresponds to 'native' surface format
|
||||
static bool isNative(const word&);
|
||||
|
||||
//- Read non-comment line
|
||||
static string getLineNoComment(IFstream&);
|
||||
|
||||
//- Name of UnsortedMeshedSurface directory to use.
|
||||
static fileName triSurfInstance(const Time&, const word& subdirName);
|
||||
|
||||
//- Name of UnsortedMeshedSurface directory to use.
|
||||
static fileName triSurfName(const Time&, const word& subdirName);
|
||||
|
||||
//- Determine the sort order from the region list.
|
||||
// Returns patch list and sets faceMap to indices within faceLst
|
||||
static surfGroupList sortedPatchRegions
|
||||
(
|
||||
const UList<label>& regionLst,
|
||||
const Map<word>& patchNames,
|
||||
labelList& faceMap
|
||||
);
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
surfaceFormatsCore();
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~surfaceFormatsCore();
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
// Edit
|
||||
|
||||
// Read
|
||||
|
||||
// Write
|
||||
|
||||
// Member operators
|
||||
|
||||
// Ostream Operator
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fileFormats
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,57 +24,22 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "TRIfileFormat.H"
|
||||
#include "triFace.H"
|
||||
#include "TRIsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IOmanip.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToRunTimeSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
TRIfileFormat,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
TRIfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
TRIfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
inline void Foam::fileFormats::TRIfileFormat::writeShell
|
||||
template<class Face>
|
||||
inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const face& f,
|
||||
const Face& f,
|
||||
const label patchI
|
||||
)
|
||||
{
|
||||
@ -99,27 +64,41 @@ inline void Foam::fileFormats::TRIfileFormat::writeShell
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::TRIfileFormat::TRIfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
Foam::fileFormats::TRIfileFormat::TRIfileFormat
|
||||
template<class Face>
|
||||
Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate
|
||||
const fileName& fName
|
||||
)
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{
|
||||
IFstream is(fName);
|
||||
read(fName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Face>
|
||||
bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
ParentType::clear();
|
||||
|
||||
IFstream is(fName);
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"fileFormats::TRIfileFormat(const fileName&)"
|
||||
"fileFormats::TRIsurfaceFormat::read(const fileName&)"
|
||||
)
|
||||
<< "Cannot read file " << fName
|
||||
<< exit(FatalError);
|
||||
@ -137,13 +116,13 @@ Foam::fileFormats::TRIfileFormat::TRIfileFormat
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
string line = getLineNoComment(is);
|
||||
string line = ParentType::getLineNoComment(is);
|
||||
|
||||
// handle continuations ?
|
||||
// if (line[line.size()-1] == '\\')
|
||||
// {
|
||||
// line.substr(0, line.size()-1);
|
||||
// line += getLineNoComment(is);
|
||||
// line += ParentType::getLineNoComment(is);
|
||||
// }
|
||||
|
||||
IStringStream lineStream(line);
|
||||
@ -211,12 +190,12 @@ Foam::fileFormats::TRIfileFormat::TRIfileFormat
|
||||
}
|
||||
|
||||
// transfer to normal list
|
||||
points().transfer(pointLst);
|
||||
regions().transfer(regionLst);
|
||||
ParentType::points().transfer(pointLst);
|
||||
ParentType::regions().transfer(regionLst);
|
||||
|
||||
// make our triangles directly
|
||||
List<FaceType>& faceLst = faces();
|
||||
faceLst.setSize(regions().size());
|
||||
List<Face>& faceLst = ParentType::faces();
|
||||
faceLst.setSize(ParentType::regions().size());
|
||||
|
||||
label ptI = 0;
|
||||
forAll(faceLst, faceI)
|
||||
@ -230,21 +209,21 @@ Foam::fileFormats::TRIfileFormat::TRIfileFormat
|
||||
faceLst[faceI] = fTri;
|
||||
}
|
||||
|
||||
setPatches(groupToPatch);
|
||||
stitchFaces(SMALL);
|
||||
ParentType::setPatches(groupToPatch);
|
||||
ParentType::stitchFaces(SMALL);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::TRIfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::TRIsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
|
||||
labelList faceMap;
|
||||
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
|
||||
@ -254,21 +233,22 @@ void Foam::fileFormats::TRIfileFormat::write
|
||||
{
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceMap[faceIndex++]];
|
||||
const Face& f = faceLst[faceMap[faceIndex++]];
|
||||
writeShell(os, pointLst, f, patchI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::TRIfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::TRIsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const pointField& pointLst = surf.points();
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
label faceIndex = 0;
|
||||
@ -276,7 +256,7 @@ void Foam::fileFormats::TRIfileFormat::write
|
||||
{
|
||||
forAll(patchLst[patchI], patchFaceI)
|
||||
{
|
||||
const face& f = faceLst[faceIndex++];
|
||||
const Face& f = faceLst[faceIndex++];
|
||||
writeShell(os, pointLst, f, patchI);
|
||||
}
|
||||
}
|
||||
@ -23,23 +23,23 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::TRIfileFormat
|
||||
Foam::fileFormats::TRIsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of reading/writing .tri format.
|
||||
|
||||
SourceFiles
|
||||
TRIfileFormat.C
|
||||
TRIsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TRIfileFormat_H
|
||||
#define TRIfileFormat_H
|
||||
#ifndef TRIsurfaceFormat_H
|
||||
#define TRIsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -49,27 +49,31 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class TRIfileFormat Declaration
|
||||
Class TRIsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class TRIfileFormat
|
||||
template<class Face>
|
||||
class TRIsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef TRIsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
TRIfileFormat(const TRIfileFormat&);
|
||||
TRIsurfaceFormat(const TRIsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const TRIfileFormat&);
|
||||
void operator=(const TRIsurfaceFormat<Face>&);
|
||||
|
||||
static inline void writeShell
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const face&,
|
||||
const Face&,
|
||||
const label patchI
|
||||
);
|
||||
|
||||
@ -78,46 +82,64 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
TRIfileFormat();
|
||||
TRIsurfaceFormat();
|
||||
|
||||
//- Construct from file name
|
||||
TRIfileFormat(const fileName&, const bool triangulate=true);
|
||||
TRIsurfaceFormat(const fileName&);
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
static autoPtr<keyedSurface> New
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName,
|
||||
const bool triangulate=true
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<keyedSurface>
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
(
|
||||
new TRIfileFormat(fName, triangulate)
|
||||
new TRIsurfaceFormat<Face>(fName)
|
||||
);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
virtual ~TRIsurfaceFormat()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName& fName, const keyedSurface& surf)
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName& fName, const meshedSurface& surf)
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
@ -138,6 +160,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "TRIsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
99
src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatRunTime.C
Normal file
99
src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "TRIsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
tri
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -24,48 +24,20 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "VTKfileFormat.H"
|
||||
#include "VTKsurfaceFormat.H"
|
||||
#include "clock.H"
|
||||
#include "IFstream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
keyedSurface,
|
||||
VTKfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
|
||||
addNamedToMemberFunctionSelectionTable
|
||||
(
|
||||
meshedSurface,
|
||||
VTKfileFormat,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::VTKfileFormat::writeHead
|
||||
template<class Face>
|
||||
void Foam::fileFormats::VTKsurfaceFormat<Face>::writeHead
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst,
|
||||
const List<face>& faceLst
|
||||
const List<Face>& faceLst
|
||||
)
|
||||
{
|
||||
// Write header
|
||||
@ -96,7 +68,8 @@ void Foam::fileFormats::VTKfileFormat::writeHead
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::VTKfileFormat::writeTail
|
||||
template<class Face>
|
||||
void Foam::fileFormats::VTKsurfaceFormat<Face>::writeTail
|
||||
(
|
||||
Ostream& os,
|
||||
const List<surfGroup>& patchLst
|
||||
@ -139,21 +112,23 @@ void Foam::fileFormats::VTKfileFormat::writeTail
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::VTKfileFormat::VTKfileFormat()
|
||||
template<class Face>
|
||||
Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
|
||||
:
|
||||
Foam::keyedSurface()
|
||||
ParentType()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::VTKfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const keyedSurface& surf
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
|
||||
writeHead(os, surf.points(), faceLst);
|
||||
|
||||
@ -181,13 +156,14 @@ void Foam::fileFormats::VTKfileFormat::write
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::VTKfileFormat::write
|
||||
template<class Face>
|
||||
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
|
||||
(
|
||||
Ostream& os,
|
||||
const meshedSurface& surf
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
const List<face>& faceLst = surf.faces();
|
||||
const List<Face>& faceLst = surf.faces();
|
||||
const List<surfGroup>& patchLst = surf.patches();
|
||||
|
||||
writeHead(os, surf.points(), faceLst);
|
||||
@ -23,23 +23,23 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::fileFormats::VTKfileFormat
|
||||
Foam::fileFormats::VTKsurfaceFormat
|
||||
|
||||
Description
|
||||
Provide a means of writing VTK legacy format.
|
||||
|
||||
SourceFiles
|
||||
VTKfileFormat.C
|
||||
VTKsurfaceFormat.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef VTKfileFormat_H
|
||||
#define VTKfileFormat_H
|
||||
#ifndef VTKsurfaceFormat_H
|
||||
#define VTKsurfaceFormat_H
|
||||
|
||||
#include "Ostream.H"
|
||||
#include "OFstream.H"
|
||||
#include "keyedSurface.H"
|
||||
#include "meshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -49,23 +49,27 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class VTKfileFormat Declaration
|
||||
Class VTKsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class VTKfileFormat
|
||||
template<class Face>
|
||||
class VTKsurfaceFormat
|
||||
:
|
||||
public keyedSurface
|
||||
public UnsortedMeshedSurface<Face>
|
||||
{
|
||||
//- Private typedefs for convenience
|
||||
typedef VTKsurfaceFormat<Face> ThisType;
|
||||
typedef UnsortedMeshedSurface<Face> ParentType;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
VTKfileFormat(const VTKfileFormat&);
|
||||
VTKsurfaceFormat(const VTKsurfaceFormat<Face>&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const VTKfileFormat&);
|
||||
void operator=(const VTKsurfaceFormat<Face>&);
|
||||
|
||||
static void writeHead(Ostream&, const pointField&, const List<face>&);
|
||||
static void writeHead(Ostream&, const pointField&, const List<Face>&);
|
||||
static void writeTail(Ostream&, const List<surfGroup>&);
|
||||
|
||||
public:
|
||||
@ -73,30 +77,49 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
VTKfileFormat();
|
||||
VTKsurfaceFormat();
|
||||
|
||||
// Selectors
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~VTKsurfaceFormat()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(Ostream&, const keyedSurface&);
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write keyedSurface
|
||||
static void write(const fileName& fName, const keyedSurface& surf)
|
||||
//- Write UnsortedMeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const UnsortedMeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(Ostream&, const meshedSurface&);
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write meshedSurface
|
||||
static void write(const fileName& fName, const meshedSurface& surf)
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
@ -117,6 +140,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "VTKsurfaceFormat.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
81
src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatRunTime.C
Normal file
81
src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormatRunTime.C
Normal file
@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "VTKsurfaceFormat.H"
|
||||
#include "MeshedSurface.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
namespace Foam
|
||||
{
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -140,9 +140,10 @@ find -L . -type l -exec rm \{\} \;
|
||||
|
||||
#
|
||||
# create links, avoid recreating links unless necessary
|
||||
# things placed in the 'noLink' directory are skipped
|
||||
#
|
||||
find .. $findOpt \
|
||||
\( -name lnInclude -o -name Make -o -name config \) -prune \
|
||||
\( -name lnInclude -o -name Make -o -name config -o -name noLink \) -prune \
|
||||
-o \( -name '*.[CHh]' -o -name '*.[ch]xx' -o -name '*.[ch]pp' -o -name '*.type' \) \
|
||||
-a ! -name ".#*" \
|
||||
-print | \
|
||||
|
||||
Reference in New Issue
Block a user