diff --git a/Allwmake b/Allwmake index c2529d54a9..c5ba88c93b 100755 --- a/Allwmake +++ b/Allwmake @@ -96,8 +96,8 @@ echo " ${WM_PROJECT_DIR##*/}" echo " $WM_COMPILER ${WM_COMPILER_TYPE:-system} compiler" echo " ${WM_OPTIONS}, with ${WM_MPLIB} ${FOAM_MPI}" echo -echo " api = $(bin/foamEtcFile -show-api 2>/dev/null)" -echo " patch = $(bin/foamEtcFile -show-patch 2>/dev/null)" +echo " api = $(etc/openfoam -show-api 2>/dev/null)" +echo " patch = $(etc/openfoam -show-patch 2>/dev/null)" echo " bin = $(_foamCountDirEntries "$FOAM_APPBIN") entries" echo " lib = $(_foamCountDirEntries "$FOAM_LIBBIN") entries" echo diff --git a/META-INFO/api-info b/META-INFO/api-info index c1de2e582b..4f4725e226 100644 --- a/META-INFO/api-info +++ b/META-INFO/api-info @@ -1,2 +1,2 @@ api=2002 -patch=200403 +patch=200417 diff --git a/applications/utilities/surface/surfaceBooleanFeatures/CGAL3DKernel.H b/applications/utilities/surface/surfaceBooleanFeatures/CGAL3DKernel.H index d3851dbd76..b3aa5dc32a 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/CGAL3DKernel.H +++ b/applications/utilities/surface/surfaceBooleanFeatures/CGAL3DKernel.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +28,7 @@ Typedefs CGAL3DKernel Description + A typedef for selecting inexact (faster) or exact (slower) 3D model. \*---------------------------------------------------------------------------*/ @@ -38,13 +40,13 @@ Description #ifdef CGAL_INEXACT // Fast kernel using a double as the storage type - #include "CGAL/Exact_predicates_inexact_constructions_kernel.h" + #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; #else // Very robust but expensive kernel - #include "CGAL/Exact_predicates_exact_constructions_kernel.h" + #include typedef CGAL::Exact_predicates_exact_constructions_kernel K; #endif diff --git a/applications/utilities/surface/surfaceBooleanFeatures/CGALIndexedPolyhedron.H b/applications/utilities/surface/surfaceBooleanFeatures/CGALIndexedPolyhedron.H index 2cb79393d6..3ed79edb25 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/CGALIndexedPolyhedron.H +++ b/applications/utilities/surface/surfaceBooleanFeatures/CGALIndexedPolyhedron.H @@ -65,6 +65,7 @@ struct IndexedFace Foam::label index; Foam::label region; }; + struct My_items : public CGAL::Polyhedron_items_3 diff --git a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/Make/options b/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/Make/options index 8ed525de9f..144ee830b9 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/Make/options +++ b/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/Make/options @@ -20,4 +20,5 @@ EXE_INC = \ LIB_LIBS = \ -L$(CGAL_ARCH_PATH)/lib \ -L$(CGAL_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \ + -lsurfMesh \ -lmeshTools diff --git a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.C b/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.C index 5ca1bab640..771e8f808a 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.C +++ b/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,14 +28,50 @@ License #include "PolyhedronReader.H" +// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // + +template +void Foam::PolyhedronReader::Build_triangle::operator()(HDS& hds) +{ + // Postcondition: hds is a valid polyhedral surface. + CGAL::Polyhedron_incremental_builder_3 B(hds, true); + + B.begin_surface(s_.nPoints(), s_.size()); + + typedef typename HDS::Vertex Vertex; + typedef typename Vertex::Point Point; + + for (const auto& pt : s_.points()) + { + B.add_vertex(Point(pt.x(), pt.y(), pt.z())); + } + + for (const auto& f : s_) + { + B.begin_facet(); + + for (const label verti : f) + { + B.add_vertex_to_facet(verti); + } + + B.end_facet(); + } + + B.end_surface(); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::PolyhedronReader::PolyhedronReader(const triSurface& s, Polyhedron& p) { Build_triangle triangle(s); p.delegate(triangle); + // Populate index and region Foam::label nTris = 0; + for ( Facet_iterator fi = p.facets_begin(); @@ -42,8 +79,10 @@ Foam::PolyhedronReader::PolyhedronReader(const triSurface& s, Polyhedron& p) ++fi ) { - fi->index = nTris++; - fi->region = s[fi->index].region(); + fi->index = nTris; + fi->region = s[nTris].region(); + + ++nTris; } } diff --git a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.H b/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.H index 2968fb34c6..1c0a6b5ca2 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.H +++ b/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReader.H @@ -61,28 +61,21 @@ class PolyhedronReader public: - Build_triangle(const triSurface& s); + Build_triangle(const triSurface& s) + : + s_(s) + {} void operator()(HDS& hds); }; - // Private Member Functions - - //- No copy construct - PolyhedronReader(const PolyhedronReader&) = delete; - - //- No copy assignment - void operator=(const PolyhedronReader&) = delete; - - public: // Constructors //- Populate polyhedron from surface PolyhedronReader(const triSurface& s, Polyhedron& p); - }; @@ -92,12 +85,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "PolyhedronReaderTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReaderTemplates.C b/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReaderTemplates.C deleted file mode 100644 index ac5e90ed3c..0000000000 --- a/applications/utilities/surface/surfaceBooleanFeatures/PolyhedronReader/PolyhedronReaderTemplates.C +++ /dev/null @@ -1,74 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | www.openfoam.com - \\/ M anipulation | -------------------------------------------------------------------------------- - Copyright (C) 2015 OpenFOAM Foundation -------------------------------------------------------------------------------- -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 3 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, see . - -\*---------------------------------------------------------------------------*/ - -#include "PolyhedronReader.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::PolyhedronReader::Build_triangle::Build_triangle -( - const triSurface& s -) -: - s_(s) -{} - - -// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // - -template -void Foam::PolyhedronReader::Build_triangle::operator()(HDS& hds) -{ - // Postcondition: hds is a valid polyhedral surface. - CGAL::Polyhedron_incremental_builder_3 B(hds, true); - - B.begin_surface(s_.nPoints(), s_.size()); - - typedef typename HDS::Vertex Vertex; - typedef typename Vertex::Point Point; - - const Foam::pointField& pts = s_.points(); - forAll(pts, i) - { - const Foam::point& pt = pts[i]; - B.add_vertex(Point(pt.x(), pt.y(), pt.z())); - } - forAll(s_, i) - { - const Foam::labelledTri& t = s_[i]; - B.begin_facet(); - B.add_vertex_to_facet(t[0]); - B.add_vertex_to_facet(t[1]); - B.add_vertex_to_facet(t[2]); - B.end_facet(); - } - B.end_surface(); -} - - -// ************************************************************************* // diff --git a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C index c1278a58ec..8e6d169357 100644 --- a/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C +++ b/applications/utilities/surface/surfaceBooleanFeatures/surfaceBooleanFeatures.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -102,8 +102,10 @@ typedef CGAL::AABB_face_graph_triangle_primitive typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; -typedef boost::optional::Type> -Segment_intersection; +typedef boost::optional +< + Tree::Intersection_and_primitive_id::Type +> Segment_intersection; #endif // NO_CGAL @@ -633,17 +635,14 @@ labelPair edgeIntersectionsCGAL segments.clear(); tree.all_intersections(segment_query, std::back_inserter(segments)); - for - ( - std::vector::const_iterator iter = - segments.begin(), - end = segments.end(); - iter != end; - ++iter - ) + + for (const Segment_intersection& intersect : segments) { // Get intersection object - if (const Point* ptPtr = boost::get(&((*iter)->first))) + if + ( + const Point* ptPtr = boost::get(&(intersect->first)) + ) { point pt ( @@ -652,7 +651,12 @@ labelPair edgeIntersectionsCGAL CGAL::to_double(ptPtr->z()) ); - Polyhedron::Face_handle f = (*iter)->second; + #if defined (CGAL_VERSION_NR) && (CGAL_VERSION_NR < 1041400000) + Polyhedron::Face_handle f = (intersect->second); + #else + // 1.14 and later + Polyhedron::Face_handle f = (intersect->second).first; + #endif intersections[edgeI].append ( @@ -665,18 +669,24 @@ labelPair edgeIntersectionsCGAL ); // Intersection on edge interior classifications[edgeI].append(-1); - nPoints++; + ++nPoints; } else if ( - const Segment* sPtr = boost::get(&((*iter)->first)) + const Segment* sPtr = boost::get(&(intersect->first)) ) { + #if defined (CGAL_VERSION_NR) && (CGAL_VERSION_NR < 1041400000) + Polyhedron::Face_handle f = (intersect->second); + #else + // 1.14 and later + Polyhedron::Face_handle f = (intersect->second).first; + #endif + //std::cout // << "intersection object is a segment:" << sPtr->source() // << " " << sPtr->target() << std::endl; - Polyhedron::Face_handle f = (*iter)->second; //std::cout<< "triangle:" << f->index // << " region:" << f->region << std::endl; @@ -706,7 +716,7 @@ labelPair edgeIntersectionsCGAL ); // Intersection aligned with face. Tbd: enums classifications[edgeI].append(2); - nSegments++; + ++nSegments; } } } diff --git a/applications/utilities/surface/surfaceCoarsen/Make/files b/applications/utilities/surface/surfaceCoarsen/Make/files index f2a1e0725f..6940e9b467 100644 --- a/applications/utilities/surface/surfaceCoarsen/Make/files +++ b/applications/utilities/surface/surfaceCoarsen/Make/files @@ -1,5 +1,5 @@ -bunnylod/progmesh.C -bunnylod/vector.C +bunnylod/progmesh.cxx +bunnylod/vector.cxx surfaceCoarsen.C EXE = $(FOAM_APPBIN)/surfaceCoarsen diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/README b/applications/utilities/surface/surfaceCoarsen/bunnylod/README index 96c8188b9b..ccefb14ea3 100644 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/README +++ b/applications/utilities/surface/surfaceCoarsen/bunnylod/README @@ -7,3 +7,14 @@ The PC executable bunnylod.exe should run on a standard PC. Just run it and enjoy. Mouse dragging spins the rabbit. + +------------------------------------------------------------------- +Changes + +2020-04-16 OpenCFD Ltd + - remove MSWindows components (code and makefiles) + - use cxx, hxx extensions to reduce possible confusion with other + "list" and "vector" classes + - use C++ versions for C headers + +------------------------------------------------------------------- diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnygut.C b/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnygut.C deleted file mode 100644 index 3e78b37861..0000000000 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnygut.C +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Polygon Reduction Demo by Stan Melax (c) 1998 - * Permission to use any of this code wherever you want is granted.. - * Although, please do acknowledge authorship if appropriate. - * - * This module initializes the bunny model data and calls - * the polygon reduction routine. At each frame the RenderModel() - * routine is called to draw the model. This module also - * animates the parameters (such as number of vertices to - * use) to show the model at various levels of detail. - */ - -#include -#include -#include -#include -#include -#include -#include -#pragma warning(disable : 4244) - -#include "vector.h" -#include "font.h" -#include "progmesh.h" -#include "rabdata.h" - -extern float DeltaT; // change in time since last frame -int render_num; // number of vertices to draw with -float lodbase=0.5f; // the fraction of vertices used to morph toward -float morph=1.0f; // where to render between 2 levels of detail -List vert; // global list of vertices -List tri; // global list of triangles -List collapse_map; // to which neighbor each vertex collapses -int renderpolycount=0; // polygons rendered in the current frame -Vector model_position; // position of bunny -Quaternion model_orientation; // orientation of bunny - -// Note that the use of the Map() function and the collapse_map -// list isn't part of the polygon reduction algorithm. -// We just set up this system here in this module -// so that we could retrieve the model at any desired vertex count. -// Therefore if this part of the program confuses you, then -// dont worry about it. It might help to look over the progmesh.cpp -// module first. - -// Map() -// -// When the model is rendered using a maximum of mx vertices -// then it is vertices 0 through mx-1 that are used. -// We are able to do this because the vertex list -// gets sorted according to the collapse order. -// The Map() routine takes a vertex number 'a' and the -// maximum number of vertices 'mx' and returns the -// appropriate vertex in the range 0 to mx-1. -// When 'a' is greater than 'mx' the Map() routine -// follows the chain of edge collapses until a vertex -// within the limit is reached. -// An example to make this clear: assume there is -// a triangle with vertices 1, 3 and 12. But when -// rendering the model we limit ourselves to 10 vertices. -// In that case we find out how vertex 12 was removed -// by the polygon reduction algorithm. i.e. which -// edge was collapsed. Lets say that vertex 12 was collapsed -// to vertex number 7. This number would have been stored -// in the collapse_map array (i.e. collapse_map[12]==7). -// Since vertex 7 is in range (less than max of 10) we -// will want to render the triangle 1,3,7. -// Pretend now that we want to limit ourselves to 5 vertices. -// and vertex 7 was collapsed to vertex 3 -// (i.e. collapse_map[7]==3). Then triangle 1,3,12 would now be -// triangle 1,3,3. i.e. this polygon was removed by the -// progressive mesh polygon reduction algorithm by the time -// it had gotten down to 5 vertices. -// No need to draw a one dimensional polygon. :-) -int Map(int a,int mx) { - if(mx<=0) return 0; - while(a>=mx) { - a=collapse_map[a]; - } - return a; -} - -void DrawModelTriangles() { - assert(collapse_map.num); - renderpolycount=0; - int i=0; - for(i=0;i &permutation) { - // rearrange the vertex list - List temp_list; - int i; - assert(permutation.num==vert.num); - for(i=0;i permutation; - GetRabbitData(); - ProgressiveMesh(vert,tri,collapse_map,permutation); - PermuteVertices(permutation); - model_position = Vector(0,0,-3); - Quaternion yaw(Vector(0,1,0),-3.14f/4); // 45 degrees - Quaternion pitch(Vector(1,0,0),3.14f/12); // 15 degrees - model_orientation = pitch*yaw; -} - -void StatusDraw() { - // Draw a slider type widget looking thing - // to show portion of vertices being used - float b = (float)render_num/(float)vert.num; - float a = b*(lodbase ); - glDisable(GL_LIGHTING); - glMatrixMode( GL_PROJECTION ); - glPushMatrix(); - glLoadIdentity(); - glOrtho(-0.15,15,-0.1,1.1,-0.1,100); - glMatrixMode( GL_MODELVIEW ); - - glPushMatrix(); - glLoadIdentity(); - glBegin(GL_POLYGON); - glColor3f(1,0,0); - glVertex2f(0,0); - glVertex2f(1,0); - glVertex2f(1,a); - glVertex2f(0,a); - glEnd(); - glBegin(GL_POLYGON); - glColor3f(1,0,0); - glVertex2f(0,a); - glVertex2f(morph,a); - glVertex2f(morph,b); - glVertex2f(0,b); - glEnd(); - glBegin(GL_POLYGON); - glColor3f(0,0,1); - glVertex2f(morph,a); - glVertex2f(1,a); - glVertex2f(1,b); - glVertex2f(morph,b); - glEnd(); - glBegin(GL_POLYGON); - glColor3f(0,0,1); - glVertex2f(0,b); - glVertex2f(1,b); - glVertex2f(1,1); - glVertex2f(0,1); - glEnd(); - glPopMatrix(); - glMatrixMode( GL_PROJECTION ); - glPopMatrix(); - glMatrixMode( GL_MODELVIEW ); -} - -/* - * The following is just a quick hack to animate - * the object through various polygon reduced versions. - */ -struct keyframethings { - float t; // timestamp - float n; // portion of vertices used to start - float dn; // rate of change in "n" - float m; // morph value - float dm; // rate of change in "m" -} keys[]={ - {0 ,1 ,0 ,1, 0}, - {2 ,1 ,-1,1, 0}, - {10,0 ,1 ,1, 0}, - {18,1 ,0 ,1, 0}, - {20,1 ,0 ,1,-1}, - {24,0.5 ,0 ,1, 0}, - {26,0.5 ,0 ,1,-1}, - {30,0.25,0 ,1, 0}, - {32,0.25,0 ,1,-1}, - {36,0.125,0,1, 0}, - {38,0.25,0 ,0, 1}, - {42,0.5 ,0 ,0, 1}, - {46,1 ,0 ,0, 1}, - {50,1 ,0 ,1, 0}, -}; -void AnimateParameters() { - static float time=0; // global time - used for animation - time+=DeltaT; - if(time>=50) time=0; // repeat cycle every so many seconds - int k=0; - while(time>keys[k+1].t) { - k++; - } - float interp = (time-keys[k].t)/(keys[k+1].t-keys[k].t); - render_num = vert.num*(keys[k].n + interp*keys[k].dn); - morph = keys[k].m + interp*keys[k].dm; - morph = (morph>1.0f) ? 1.0f : morph; // clamp value - if(render_num>vert.num) render_num=vert.num; - if(render_num<0 ) render_num=0; -} - -void RenderModel() { - AnimateParameters(); - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glColor3f(1,1,1); - glPushMatrix(); - glTranslatef(model_position.x,model_position.y,model_position.z); - // Rotate by quaternion: model_orientation - Vector axis=model_orientation.axis(); - float angle=model_orientation.angle()*180.0f/3.14f; - glRotatef(angle,axis.x,axis.y,axis.z); - DrawModelTriangles(); - StatusDraw(); - glPopMatrix(); - - char buf[256]; - sprintf(buf,"Polys: %d Vertices: %d ",renderpolycount,render_num); - if(morph<1.0) { - sprintf(buf+strlen(buf),"<-> %d morph: %4.2f ", - (int)(lodbase *render_num),morph); - } - PostString(buf,0,-2,5); -} diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnylod.dsp b/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnylod.dsp deleted file mode 100644 index 0109cfe725..0000000000 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnylod.dsp +++ /dev/null @@ -1,114 +0,0 @@ -# Microsoft Developer Studio Project File - Name="bunnylod" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=bunnylod - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "bunnylod.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "bunnylod.mak" CFG="bunnylod - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "bunnylod - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "bunnylod - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "bunnylod - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib opengl32.lib glu32.lib winmm.lib /nologo /subsystem:windows /machine:I386 - -!ELSEIF "$(CFG)" == "bunnylod - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib opengl32.lib glu32.lib winmm.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "bunnylod - Win32 Release" -# Name "bunnylod - Win32 Debug" -# Begin Source File - -SOURCE=.\bunnygut.cpp -# End Source File -# Begin Source File - -SOURCE=.\font.cpp -# End Source File -# Begin Source File - -SOURCE=.\progmesh.cpp -# End Source File -# Begin Source File - -SOURCE=.\rabdata.cpp -# End Source File -# Begin Source File - -SOURCE=.\vector.cpp -# End Source File -# Begin Source File - -SOURCE=.\winmain.cpp -# End Source File -# End Target -# End Project diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnylod.dsw b/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnylod.dsw deleted file mode 100644 index 8abda09402..0000000000 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/bunnylod.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 5.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "bunnylod"=.\bunnylod.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/font.h b/applications/utilities/surface/surfaceCoarsen/bunnylod/font.h deleted file mode 100644 index 196f5de7f6..0000000000 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/font.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef FONT_H -#define FONT_H - -void PrintString(char *s,int x=0,int y=-1); -void PostString(char *_s,int _x,int _y,float _life=5.0); -void RenderStrings(); - -#endif diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/list.h b/applications/utilities/surface/surfaceCoarsen/bunnylod/list.hxx similarity index 98% rename from applications/utilities/surface/surfaceCoarsen/bunnylod/list.h rename to applications/utilities/surface/surfaceCoarsen/bunnylod/list.hxx index b7394b1cc3..a62609c6bc 100644 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/list.h +++ b/applications/utilities/surface/surfaceCoarsen/bunnylod/list.hxx @@ -1,13 +1,16 @@ /* + * -*- C++ -*- + * * A generic template list class. * Fairly typical of the list example you would * find in any c++ book. */ + #ifndef GENERIC_LIST_H #define GENERIC_LIST_H -#include -#include +#include +#include template class List { public: @@ -123,8 +126,4 @@ void List::Remove(Type t){ } } - - - - #endif diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.C b/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.cxx similarity index 98% rename from applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.C rename to applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.cxx index 4925650491..82ea6f3f40 100644 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.C +++ b/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.cxx @@ -1,4 +1,6 @@ /* + * -*- C++ -*- + * * Progressive Mesh type Polygon Reduction Algorithm * by Stan Melax (c) 1998 * Permission to use any of this code wherever you want is granted.. @@ -7,15 +9,14 @@ * See the header file progmesh.h for a description of this module */ -#include -#include -#include -#include -//#include +#include +#include +#include +#include -#include "vector.h" -#include "list.h" -#include "progmesh.h" +#include "vector.hxx" +#include "list.hxx" +#include "progmesh.hxx" #define min(x,y) (((x) <= (y)) ? (x) : (y)) #define max(x,y) (((x) >= (y)) ? (x) : (y)) diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.h b/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.hxx similarity index 94% rename from applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.h rename to applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.hxx index 6383474733..e6af82e41d 100644 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.h +++ b/applications/utilities/surface/surfaceCoarsen/bunnylod/progmesh.hxx @@ -1,4 +1,6 @@ /* + * -*- C++ -*- + * * Progressive Mesh type Polygon Reduction Algorithm * by Stan Melax (c) 1998 * @@ -18,8 +20,8 @@ #ifndef PROGRESSIVE_MESH_H #define PROGRESSIVE_MESH_H -#include "vector.h" -#include "list.h" +#include "vector.hxx" +#include "list.hxx" class tridata { public: diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.C b/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.cxx similarity index 97% rename from applications/utilities/surface/surfaceCoarsen/bunnylod/vector.C rename to applications/utilities/surface/surfaceCoarsen/bunnylod/vector.cxx index 9bdecbbd32..feaeaa955b 100644 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.C +++ b/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.cxx @@ -1,8 +1,8 @@ -#include -#include -#include +#include +#include +#include -#include "vector.h" +#include "vector.hxx" float sqr(float a) {return a*a;} diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.h b/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.hxx similarity index 97% rename from applications/utilities/surface/surfaceCoarsen/bunnylod/vector.h rename to applications/utilities/surface/surfaceCoarsen/bunnylod/vector.hxx index 26dd9bbe71..85f6bffd1c 100644 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.h +++ b/applications/utilities/surface/surfaceCoarsen/bunnylod/vector.hxx @@ -1,3 +1,4 @@ +// -*- C++ -*- // // This module contains a bunch of well understood functions // I apologise if the conventions used here are slightly @@ -7,8 +8,8 @@ #ifndef GENERIC_VECTOR_H #define GENERIC_VECTOR_H -#include -#include +#include +#include class Vector { diff --git a/applications/utilities/surface/surfaceCoarsen/bunnylod/winmain.C b/applications/utilities/surface/surfaceCoarsen/bunnylod/winmain.C deleted file mode 100644 index fd19db0a04..0000000000 --- a/applications/utilities/surface/surfaceCoarsen/bunnylod/winmain.C +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Polygon Reduction Demo by Stan Melax (c) 1998 - * Permission to use any of this code wherever you want is granted.. - * Although, please do acknowledge authorship if appropriate. - * - * This module contains the window setup code, mouse input, timing - * routines, and that sort of stuff. The interesting modules - * to see are bunnygut.cpp and progmesh.cpp. - * - * The windows 95 specific code for this application was taken from - * an example of processing mouse events in an OpenGL program using - * the Win32 API from the www.opengl.org web site. - * - * Under Project->Settings, Link Options, General Category - * Add: - * Opengl32.lib glu32.lib winmm.lib - * to the Object/Library Modules - * - * You will need have OpenGL libs and include files to compile this - * Go to the www.opengl.org web site if you need help with this. - */ - - -#include /* must include this before GL/gl.h */ -#include /* OpenGL header file */ -#include /* OpenGL utilities header file */ -#include -#include -#include -#include - -#include "vector.h" -#include "font.h" - -// Functions and Variables from bunny module -extern void InitModel(); -extern void RenderModel(); -extern Vector model_position; // position of bunny -extern Quaternion model_orientation; // orientation of bunny - -// Global Variables -float DeltaT = 0.1f; -float FPS; -int Width = 512; -int Height = 512; -int MouseX = 0; -int MouseY = 0; -Vector MouseVector; // 3D direction mouse points -Vector OldMouseVector; -int MouseState=0; // true iff left button down -float ViewAngle=45.0f; - -HDC hDC; /* device context */ -HPALETTE hPalette = 0; /* custom palette (if needed) */ - - -void CalcFPSDeltaT(){ - static int timeinit=0; - static int start,start2,current,last; - static int frame=0, frame2=0; - if(!timeinit){ - frame=0; - start=timeGetTime(); - timeinit=1; - } - frame++; - frame2++; - current=timeGetTime(); // found in winmm.lib - double dif=(double)(current-start)/CLOCKS_PER_SEC; - double rv = (dif)? (double)frame/(double)dif:-1.0; - if(dif>2.0 && frame >10) { - start = start2; - frame = frame2; - start2 = timeGetTime(); - frame2 = 0; - } - DeltaT = (float)(current-last)/CLOCKS_PER_SEC; - if(current==last) { - DeltaT = 0.1f/CLOCKS_PER_SEC; // it just cant be 0 - } - // if(DeltaT>1.0) DeltaT=1.0; - FPS = (float)rv; - last = current; -} - - -void ComputeMouseVector(){ - OldMouseVector=MouseVector; - float spread = (float)tan(ViewAngle/2*3.14/180); - float y = spread * ((Height-MouseY)-Height/2.0f) /(Height/2.0f); - float x = spread * (MouseX-Width/2.0f) /(Height/2.0f); - Vector v(x ,y,-1); - // v=UserOrientation *v; - v=normalize(v); - MouseVector = v; -} - -Quaternion VirtualTrackBall(Vector cop,Vector cor,Vector dir1,Vector dir2) { - // Implement track ball functionality to spin stuf on the screen - // cop center of projection - // cor center of rotation - // dir1 old mouse direction - // dir2 new mouse direction - // pretend there is a sphere around cor. Then find the points - // where dir1 and dir2 intersect that sphere. Find the - // rotation that takes the first point to the second. - float m; - // compute plane - Vector nrml = cor - cop; - // since trackball proportional to distance from cop - float fudgefactor = 1.0f/(magnitude(nrml) * 0.25f); - nrml = normalize(nrml); - float dist = -(nrml^cor); - Vector u= planelineintersection(nrml,dist,cop,cop+dir1); - u=u-cor; - u=u*fudgefactor; - m= magnitude(u); - if(m>1) {u=u*1.0f/m;} - else { - u=u - (nrml * (float)sqrt(1-m*m)); - } - Vector v= planelineintersection(nrml,dist,cop,cop+dir2); - v=v-cor; - v=v*fudgefactor; - m= magnitude(v); - if(m>1) {v=v*1.0f/m;} - else { - v=v - (nrml * (float)sqrt(1-m*m)); - } - Vector axis = u*v; - float angle; - m=magnitude(axis); - if(m>1)m=1; // avoid potential floating point error - Quaternion q(Vector(1.0f,0.0f,0.0f),0.0f); - if(m>0 && (angle=(float)asin(m))>3.14/180) { - axis = normalize(axis); - q=Quaternion(axis,angle); - } - return q; -} - -void SpinIt(){ - // Change the orientation of the bunny according to mouse drag - Quaternion q=VirtualTrackBall(Vector(0,0,0),model_position, - OldMouseVector,MouseVector); - model_orientation=q*model_orientation; -} - -void Reshape(int width, int height){ - // called initially and when the window changes size - Width=width; - Height=height; - glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(ViewAngle, (float)width/height, 0.1, 50.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - -void PrintStats(){ - char buf[1024];buf[0]='\0'; - sprintf(buf,"FPS: %5.2f ",FPS); - PostString(buf,0,-1,0); -} - -void Display(){ - // main drawing routine - called every frame - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glPushMatrix(); - glLoadIdentity(); - // camera at default (zero) position and orientation - RenderModel(); - PrintStats(); - glLoadIdentity(); - RenderStrings(); - glPopMatrix(); - glFlush(); - SwapBuffers(hDC); /* nop if singlebuffered */ -} - - -LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - static PAINTSTRUCT ps; - static GLboolean left = GL_FALSE; /* left button currently down? */ - static GLboolean right = GL_FALSE; /* right button currently down? */ - static int omx, omy, mx, my; - - switch(uMsg) { - case WM_PAINT: - BeginPaint(hWnd, &ps); - EndPaint(hWnd, &ps); - return 0; - case WM_SIZE: - Reshape(LOWORD(lParam), HIWORD(lParam)); - PostMessage(hWnd, WM_PAINT, 0, 0); - return 0; - case WM_CHAR: - switch (wParam) { - case 27: /* ESC key */ - PostQuitMessage(0); - break; - } - return 0; - - case WM_LBUTTONDOWN: - /* if we don't set the capture we won't get mouse move - messages when the mouse moves outside the window. */ - SetCapture(hWnd); - MouseX = LOWORD(lParam); - MouseY = HIWORD(lParam); - ComputeMouseVector(); - MouseState = 1; - return 0; - - case WM_LBUTTONUP: - MouseX = LOWORD(lParam); - MouseY = HIWORD(lParam); - if(MouseX & 1 << 15) MouseX -= (1 << 16); - if(MouseY & 1 << 15) MouseY -= (1 << 16); - ComputeMouseVector(); - if(MouseState) SpinIt(); - MouseState=0; - /* remember to release the capture when we are finished. */ - ReleaseCapture(); - return 0; - - case WM_MOUSEMOVE: - MouseX = LOWORD(lParam); - MouseY = HIWORD(lParam); - /* Win32 is pretty braindead about the x, y position that - it returns when the mouse is off the left or top edge - of the window (due to them being unsigned). therefore, - roll the Win32's 0..2^16 pointer co-ord range to the - more amenable (and useful) 0..+/-2^15. */ - if(MouseX & 1 << 15) MouseX -= (1 << 16); - if(MouseY & 1 << 15) MouseY -= (1 << 16); - ComputeMouseVector(); - if(MouseState) SpinIt(); - return 0; - - case WM_PALETTECHANGED: - if (hWnd == (HWND)wParam) break; - /* fall through to WM_QUERYNEWPALETTE */ - case WM_QUERYNEWPALETTE: - if (hPalette) { - UnrealizeObject(hPalette); - SelectPalette(hDC, hPalette, FALSE); - RealizePalette(hDC); - return TRUE; - } - return FALSE; - - case WM_CLOSE: - PostQuitMessage(0); - return 0; - } - return DefWindowProc(hWnd, uMsg, wParam, lParam); -} - -HWND CreateOpenGLWindow(char* title) -{ - // make a double-buffered, rgba, opengl window - int n, pf; - HWND hWnd; - WNDCLASS wc; - LOGPALETTE* lpPal; - PIXELFORMATDESCRIPTOR pfd; - static HINSTANCE hInstance = 0; - - /* only register the window class once - use hInstance as a flag. */ - if (!hInstance) { - hInstance = GetModuleHandle(nullptr); - wc.style = CS_OWNDC; - wc.lpfnWndProc = (WNDPROC)WindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO); - wc.hCursor = LoadCursor(nullptr, IDC_ARROW); - wc.hbrBackground = nullptr; - wc.lpszMenuName = nullptr; - wc.lpszClassName = "OpenGL"; - - if (!RegisterClass(&wc)) { - MessageBox(nullptr, "RegisterClass() failed: " - "Cannot register window class.", - "Error", MB_OK); - return nullptr; - } - } - - hWnd = CreateWindow("OpenGL", title, WS_OVERLAPPEDWINDOW | - WS_CLIPSIBLINGS | WS_CLIPCHILDREN, - 0,0,Width,Height, nullptr, nullptr, hInstance, nullptr); - - if (hWnd == nullptr) { - MessageBox(nullptr, - "CreateWindow() failed: Cannot create a window.", - "Error", MB_OK); - return nullptr; - } - - hDC = GetDC(hWnd); - - /* there is no guarantee that the contents of the stack that become - the pfd are zeroed, therefore _make sure_ to clear these bits. */ - memset(&pfd, 0, sizeof(pfd)); - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW - | PFD_SUPPORT_OPENGL - | PFD_DOUBLEBUFFER; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cDepthBits = 32; - pfd.cColorBits = 32; - - pf = ChoosePixelFormat(hDC, &pfd); - if (pf == 0) { - MessageBox(nullptr, "ChoosePixelFormat() failed: " - "Cannot find a suitable pixel format.", - "Error", MB_OK); - return 0; - } - - if (SetPixelFormat(hDC, pf, &pfd) == FALSE) { - MessageBox(nullptr, "SetPixelFormat() failed: " - "Cannot set format specified.", "Error", MB_OK); - return 0; - } - - DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - - if (pfd.dwFlags & PFD_NEED_PALETTE || - pfd.iPixelType == PFD_TYPE_COLORINDEX) { - - n = 1 << pfd.cColorBits; - if (n > 256) n = 256; - - lpPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + - sizeof(PALETTEENTRY) * n); - memset(lpPal, 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * n); - lpPal->palVersion = 0x300; - lpPal->palNumEntries = n; - - GetSystemPaletteEntries(hDC, 0, n, &lpPal->palPalEntry[0]); - - /* if the pixel type is RGBA, then we want to make an RGB ramp, - otherwise (color index) set individual colors. */ - if (pfd.iPixelType == PFD_TYPE_RGBA) { - int redMask = (1 << pfd.cRedBits) - 1; - int greenMask = (1 << pfd.cGreenBits) - 1; - int blueMask = (1 << pfd.cBlueBits) - 1; - int i; - - /* fill in the entries with an RGB color ramp. */ - for (i = 0; i < n; ++i) { - lpPal->palPalEntry[i].peRed = - (((i >> pfd.cRedShift) & redMask) * 255) - /redMask; - lpPal->palPalEntry[i].peGreen = - (((i >> pfd.cGreenShift) & greenMask) * 255) - /greenMask; - lpPal->palPalEntry[i].peBlue = - (((i >> pfd.cBlueShift) & blueMask) * 255) - /blueMask; - lpPal->palPalEntry[i].peFlags = 0; - } - } else { - lpPal->palPalEntry[0].peRed = 0; - lpPal->palPalEntry[0].peGreen = 0; - lpPal->palPalEntry[0].peBlue = 0; - lpPal->palPalEntry[0].peFlags = PC_NOCOLLAPSE; - lpPal->palPalEntry[1].peRed = 255; - lpPal->palPalEntry[1].peGreen = 0; - lpPal->palPalEntry[1].peBlue = 0; - lpPal->palPalEntry[1].peFlags = PC_NOCOLLAPSE; - lpPal->palPalEntry[2].peRed = 0; - lpPal->palPalEntry[2].peGreen = 255; - lpPal->palPalEntry[2].peBlue = 0; - lpPal->palPalEntry[2].peFlags = PC_NOCOLLAPSE; - lpPal->palPalEntry[3].peRed = 0; - lpPal->palPalEntry[3].peGreen = 0; - lpPal->palPalEntry[3].peBlue = 255; - lpPal->palPalEntry[3].peFlags = PC_NOCOLLAPSE; - } - - hPalette = CreatePalette(lpPal); - if (hPalette) { - SelectPalette(hDC, hPalette, FALSE); - RealizePalette(hDC); - } - - free(lpPal); - } - - ReleaseDC(hDC, hWnd); - return hWnd; -} - -int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst, - LPSTR lpszCmdLine, int nCmdShow) -{ - HGLRC hRC; /* opengl context */ - HWND hWnd; /* window */ - MSG msg; /* message */ - - // InitModel() initializes some data structures and - // does the progressive mesh polygon reduction algorithm - // on the model. - CalcFPSDeltaT(); // to time the algorithm - InitModel(); - CalcFPSDeltaT(); - - hWnd = CreateOpenGLWindow("bunnylod by Stan Melax"); - if (hWnd == nullptr) exit(1); - - hDC = GetDC(hWnd); - hRC = wglCreateContext(hDC); - wglMakeCurrent(hDC, hRC); - ShowWindow(hWnd, nCmdShow); - glEnable(GL_DEPTH_TEST); - - PostString("Demo by Stan Melax (c)1998",5,-5,20); - PostString("Model by Viewpoint Datalabs (c)1996",5,-4,20); - char buf[128]; - PostString("Mesh Reduction Algorithm (non-optimized)",1,0,5); - sprintf(buf,"was executed in %5.3f seconds",DeltaT); - PostString(buf,2,1,6); - - while (1) { - while(PeekMessage(&msg, hWnd, 0, 0, PM_NOREMOVE)) { - if(GetMessage(&msg, hWnd, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } else { - // This 'goto' was in the sample code - goto quit; - } - } - CalcFPSDeltaT(); - Display(); - } - - quit: - wglMakeCurrent(nullptr, nullptr); - ReleaseDC(hDC, hWnd); - wglDeleteContext(hRC); - DestroyWindow(hWnd); - if (hPalette) DeleteObject(hPalette); - return msg.wParam; -} diff --git a/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C b/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C index 8938ae6dc3..71edd76366 100644 --- a/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C +++ b/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C @@ -50,7 +50,7 @@ Description #include "triFaceList.H" // From bunnylod -#include "progmesh.h" +#include "progmesh.hxx" using namespace Foam; diff --git a/bin/tools/create-mpi-config b/bin/tools/create-mpi-config new file mode 100755 index 0000000000..561923f59d --- /dev/null +++ b/bin/tools/create-mpi-config @@ -0,0 +1,272 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | www.openfoam.com +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# Copyright (C) 2020 OpenCFD Ltd. +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +# +# Script +# bin/tools/create-mpi-config +# +# Description +# Define hard-coded packaging settings for MPI flavours, +# primarily for system openmpi. +# This eliminates a runtime dependency on mpicc, for example. +# +# Instead of querying/parsing 'mpicc --showme:link' each time, +# it is done once during packaging. +# +# Environment +# FOAM_MPI, MPI_ARCH_PATH, DEB_TARGET_MULTIARCH +# +# Possible Dependencies +# - dpkg-architecture +# - mpicc +# +# Notes +# Run from top-level directory when creating config files +# +#------------------------------------------------------------------------------ +printHelp() { + exec 1>&2 + while [ "$#" -ge 1 ]; do echo "$1"; shift; done + cat<&2 + echo + echo "Error encountered:" + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + echo + echo "See '${0##*/} -help' for usage" + echo + exit 1 +} + + +#------------------------------------------------------------------------------ +# Options +unset optDryRun +useMpicc=true + +# Get installation directory for system openmpi +# - from "mpicc --showme:link" +# - manual fallback +# +# The mpicc content looks like this: +# ---- +# -pthread -L/usr/lib64/mpi/gcc/openmpi/lib64 -lmpi +# ---- + +query_system_openmpi() +{ + unset arch_path + + if [ "$useMpicc" = true ] + then + arch_path=$(mpicc --showme:link 2>/dev/null | sed -e 's#^.*-L\([^ ]*\).*#\1#') + arch_path="${arch_path%/*}" + + if [ -n "$arch_path" ] + then + echo "$arch_path" + return 0 # Clean exit + fi + + echo "No mpicc found. Attempt manually" 1>&2 + fi + + + # Manual discovery + if [ -z "$DEB_TARGET_MULTIARCH" ] + then + DEB_TARGET_MULTIARCH=$(dpkg-architecture -qDEB_TARGET_MULTIARCH 2>/dev/null || true) + fi + + # Include is under /usr/lib... (eg, debian, openSUSE) + for testdir in \ + /usr/lib/"${DEB_TARGET_MULTIARCH:+${DEB_TARGET_MULTIARCH}/}"openmpi/include \ + /usr/lib64/mpi/gcc/openmpi/include \ + ; + do + if [ -e "$testdir/mpi.h" ] + then + echo "${testdir%/*}" + return 0 # Clean exit + fi + done + + # Include is under /usr/include (eg, RedHat) + for testdir in \ + /usr/include/openmpi-"$(uname -m)" \ + /usr/include/openmpi \ + ; + do + if [ -e "$testdir/mpi.h" ] + then + echo "/usr" + return 0 # Clean exit + fi + done + + # Failed (should not happen) + # - report '/usr', but with error code 2 + echo "/usr" + return 2 +} + + +# Generate etc/config.{csh,sh}/MPI-TYPE files +# based on the values for FOAM_MPI and MPI_ARCH_PATH + +create_files() +{ + [ -n "$FOAM_MPI" ] || die "FOAM_MPI not set" + + if [ -d "$MPI_ARCH_PATH" ] + then + echo "Define $FOAM_MPI with $MPI_ARCH_PATH" 1>&2 + + case "$FOAM_MPI" in + (openmpi-system) + configDir="etc/config.sh" + if [ "$optDryRun" = true ] + then + cat << CONTENT 1>&2 +dry-run: $configDir/$FOAM_MPI +# +# Packaging configured value for $FOAM_MPI +export MPI_ARCH_PATH="$MPI_ARCH_PATH" + +CONTENT + elif [ -d "$configDir" ] + then + echo "Write $configDir/$FOAM_MPI" 1>&2 + cat << CONTENT > "$configDir/$FOAM_MPI" +# $configDir/$FOAM_MPI +# +# Packaging configured value for $FOAM_MPI + +export MPI_ARCH_PATH="$MPI_ARCH_PATH" +#---- +CONTENT + else + echo "Cannot write $configDir/$FOAM_MPI - no directory" 1>&2 + fi + + configDir="etc/config.csh" + if [ "$optDryRun" = true ] + then + cat << CONTENT 1>&2 +dry-run: $configDir/$FOAM_MPI +# +# Packaging configured value for $FOAM_MPI +setenv MPI_ARCH_PATH "$MPI_ARCH_PATH" + +CONTENT + elif [ -d "$configDir" ] + then + echo "Write $configDir/$FOAM_MPI" 1>&2 + cat << CONTENT > "$configDir/$FOAM_MPI" +# $configDir/$FOAM_MPI +# +# Packaging configured value for $FOAM_MPI + +setenv MPI_ARCH_PATH "$MPI_ARCH_PATH" +#---- +CONTENT + else + echo "Cannot write $configDir/$FOAM_MPI - no directory" 1>&2 + fi + ;; + esac + else + echo "Warning: $FOAM_MPI with bad MPI_ARCH_PATH: $MPI_ARCH_PATH" 1>&2 + # TBD - remove old/bad entries? + # + # for file in "etc/config.sh/$FOAM_MPI" "etc/config.csh/$FOAM_MPI" + # do + # [ -f "$file" ] && rm -f "$file" + # done + fi +} + + +#------------------------------------------------------------------------------ + +# Parse options +while [ "$#" -gt 0 ] +do + case "$1" in + -h | -help* | --help*) + printHelp + ;; + '') + # Discard empty arguments + ;; + + -dry-run) + optDryRun=true + ;; + + -no-mpicc) + unset useMpicc + ;; + + -query-openmpi | -query-system-openmpi) + query_system_openmpi + exit $? + ;; + + -write-openmpi | -write-system-openmpi) + if MPI_ARCH_PATH=$(query_system_openmpi) + then + FOAM_MPI="openmpi-system" + create_files + else + die "Failed query for system openmpi" + fi + ;; + + -write) + create_files + ;; + + *) + echo "Ignore unknown option/argument: '$1'" 1>&2 + ;; + esac + shift +done + +exit 0 # A clean exit, if we get this far + +# ----------------------------------------------------------------------------- diff --git a/bin/tools/openfoam.in b/bin/tools/openfoam.in index 39b1fe76fb..d712512d0c 100644 --- a/bin/tools/openfoam.in +++ b/bin/tools/openfoam.in @@ -1,4 +1,5 @@ #!/bin/sh +exec "@PROJECT_DIR@"/etc/openfoam "$@" #------------------------------------------------------------------------------ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox @@ -11,16 +12,8 @@ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # -# Script -# openfoam [options] [args] -# # Description -# Forwarding to the OpenFOAM etc/openfoam bash session script. +# Forwarding to OpenFOAM etc/openfoam bash session script. +# Uses a hard-code directory path (eg, generated with autoconfig). # #------------------------------------------------------------------------------ -# Hard-coded directory path (eg, autoconfig) -projectDir="@PROJECT_DIR@" - -exec "$projectDir"/etc/openfoam "$@" - -#------------------------------------------------------------------------------ diff --git a/doc/modules/README b/doc/modules/README new file mode 100644 index 0000000000..0d4c403061 --- /dev/null +++ b/doc/modules/README @@ -0,0 +1 @@ +Modules-related documents when collated for an installation package. diff --git a/etc/openfoam b/etc/openfoam index 7bbe622fe3..6db02bc688 100755 --- a/etc/openfoam +++ b/etc/openfoam @@ -35,7 +35,7 @@ # etc/openfoam -DWM_COMPILER=Clang # #------------------------------------------------------------------------------ -# Auto-detect from location +# Auto-detect from location. Do not call from within the etc/directory itself! projectDir="$(\cd "$(dirname "${0%/*}")" && \pwd -L)" #------------------------------------------------------------------------------ @@ -56,6 +56,7 @@ options: -show-api | -version Print META-INFO api value and exit -show-patch Print META-INFO patch value and exit -show-prefix Print project directory and exit + -test-tutorial Forward arguments to tutorials/AutoTest -verbose Set FOAM_VERBOSE=true (interactive only) -help Print the usage @@ -93,6 +94,7 @@ getApiInfo() # No inheritance of FOAM_SETTINGS unset FOAM_SETTINGS unset _foamEtcDir _foamSettings _foamScriptCommand +unset optTestTut # Parse options while [ "$#" -gt 0 ] @@ -114,6 +116,10 @@ do exit $? ;; + -test-tutorial) # Run tutorials/AutoTest + optTestTut=true + ;; + -c) # Shell command _foamScriptCommand="$2" [ -n "$_foamScriptCommand" ] || { @@ -196,7 +202,7 @@ fi unset interactive -if [ "$#" -eq 0 ] && [ -z "$_foamScriptCommand" ] +if [ "$#" -eq 0 ] && [ -z "$_foamScriptCommand" ] && [ -z "$optTestTut" ] then # Interactive shell, chain off via a file interactive=true @@ -263,6 +269,15 @@ then fi +if [ -n "$optTestTut" ] +then + + sourceBashrc + exec "$WM_PROJECT_DIR/tutorials/AutoTest" "$@" + exit $? # Safety +fi + + # An application or a shell script # It may actually be a script with a '#!/project-path/bin/openfoam', diff --git a/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C b/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C index 8725d58675..7d96cfeff6 100644 --- a/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/basic/zeroGradient/zeroGradientFaPatchField.C @@ -111,10 +111,7 @@ Foam::zeroGradientFaPatchField::valueInternalCoeffs const tmp& ) const { - return tmp> - ( - new Field(this->size(), Zero) - ); + return tmp>::New(this->size(), pTraits::one); } @@ -125,10 +122,7 @@ Foam::zeroGradientFaPatchField::valueBoundaryCoeffs const tmp& ) const { - return tmp> - ( - new Field(this->size(), Zero) - ); + return tmp>::New(this->size(), Zero); } @@ -136,10 +130,7 @@ template Foam::tmp> Foam::zeroGradientFaPatchField::gradientInternalCoeffs() const { - return tmp> - ( - new Field(this->size(), Zero) - ); + return tmp>::New(this->size(), Zero); } @@ -147,10 +138,7 @@ template Foam::tmp> Foam::zeroGradientFaPatchField::gradientBoundaryCoeffs() const { - return tmp> - ( - new Field(this->size(), Zero) - ); + return tmp>::New(this->size(), Zero); } diff --git a/tutorials/AutoTest b/tutorials/AutoTest new file mode 100755 index 0000000000..3a3f41b66a --- /dev/null +++ b/tutorials/AutoTest @@ -0,0 +1,199 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | www.openfoam.com +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# Copyright (C) 2020 OpenCFD Ltd. +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +# +# Script +# tutorials/AutoTest dir [.. dirN] +# +# Description +# Run foamRunTutorials with specified tutorial directories +# Creates/destroys a temporary directory for each test. +# +# Environment +# Requires an initialized OpenFOAM environment. +# +# Note +# Potentially useful for debian autopkgtest +# +#------------------------------------------------------------------------------ +# Auto-detect from location +#Unused# projectDir="$(\cd "$(dirname "${0%/*}")" && \pwd -L)" + +#------------------------------------------------------------------------------ +printHelp() { + cat<&2 + echo + echo "Error encountered:" + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + echo + echo "See '${0##*/} -help' for usage" + echo + exit 1 +} + +#------------------------------------------------------------------------------ + +unset optDebian optVerbose +optRunLimit=1 + +# Parse options +while [ "$#" -gt 0 ] +do + case "$1" in + -h*) + printHelp + ;; + + -1) + optRunLimit="${1#-}" + ;; + + -full) + unset optRunLimit + ;; + + -debian) + # Redirect stderr to stdout, if autopkgtest (tests/control) + # does NOT use "Restrictions: allow-stderr" + exec 2>&1 + ;; + + --) + break + ;; + + -*) + die "unknown option $1" + ;; + + *) + break + ;; + esac + shift +done + + +#------------------------------------------------------------------------------ +# Basic sanity checks + +[ -n "$FOAM_TUTORIALS" ] || export FOAM_TUTORIALS="$WM_PROJECT_DIR"/tutorials + +[ -d "${WM_PROJECT_DIR:?}" ] || die "No OpenFOAM environment: $WM_PROJECT_DIR" +[ -d "$FOAM_TUTORIALS" ] || die "No OpenFOAM tutorials : $FOAM_TUTORIALS" + + +#------------------------------------------------------------------------------ + +# +# Modify case controlDicts to run only one time step +# +modifyCaseControlDict() +{ + for dict in $(find . -name "controlDict*" -type f) + do + cp -f "${dict}" "${dict}.orig" + sed \ + -e 's/\(startFrom[ \t]*\)\([A-Za-z]*\);/\1 latestTime;/' \ + -e 's/\(stopAt[ \t]*\)\([A-Za-z]*\);/\1 nextWrite;/' \ + -e 's/\(writeControl[ \t]*\)\([A-Za-z]*\);/\1 timeStep;/' \ + -e 's/\(writeInterval[ \t]*\)\([-.0-9A-Za-z]*\);/\1 '"$optRunLimit"';/' \ + "${dict}.orig" > "${dict}" + done +} + + +#------------------------------------------------------------------------------ + +nTests="$#" +nPassed=0 + +for testdir in "$@" +do + testdir="${testdir#tutorials/}" + testdir="$(echo "$testdir" | sed -e 's@^//*@@; s@//*$@@;')" + suffix="$(echo "$testdir" | sed -e 's@//*@_@g')" + + if [ -n "$testdir" ] && [ -d "$FOAM_TUTORIALS/$testdir" ] + then + ( + echo "Run test: $testdir" + set -e + + TESTDIR="$(mktemp --directory --suffix=".$suffix")" + trap 'rm -rf $TESTDIR' 0 INT QUIT ABRT PIPE TERM + + cp -r "$FOAM_TUTORIALS/$testdir"/* "$TESTDIR"/ + cd "$TESTDIR" + + if [ -n "$optRunLimit" ] + then + set +e + modifyCaseControlDict + set -e + fi + + nInput="$(ls | wc -l)" + foamRunTutorials + nOutput="$(ls | wc -l)" + + if [ "$nInput" = 0 ] + then + echo "No input for $testdir" 1>&2 + exit 1 + elif [ "$nOutput" = "$nInput" ] + then + echo "Run failure for $testdir" 1>&2 + exit 1 + else + echo "run: OK" + fi + ) && nPassed=$((nPassed + 1)) + + else + echo "No tutorial: $testdir" 1>&2 + fi +done + + +if [ "$nTests" = 0 ] +then + die "No tests specified" +elif [ "$nPassed" = "$nTests" ] +then + echo "Passed all $nTests tests" +else + echo "Passed $nPassed/$nTests tests" 1>&2 + exit 1 +fi + +#------------------------------------------------------------------------------ diff --git a/tutorials/modules/README b/tutorials/modules/README new file mode 100644 index 0000000000..00e3d74590 --- /dev/null +++ b/tutorials/modules/README @@ -0,0 +1 @@ +Modules-related tutorials when collated for an installation package. diff --git a/wmake/rules/General/no-cgal b/wmake/rules/General/no-cgal new file mode 100644 index 0000000000..7ad0714e80 --- /dev/null +++ b/wmake/rules/General/no-cgal @@ -0,0 +1,6 @@ +# Empty flags for not compiling/linking with CGAL + +CGAL_INC = +CGAL_LIBS = + +#------------------------------------------------------------------------------ diff --git a/wmake/scripts/sysFunctions b/wmake/scripts/sysFunctions index 2330bf6f59..fd7aba9642 100644 --- a/wmake/scripts/sysFunctions +++ b/wmake/scripts/sysFunctions @@ -23,6 +23,7 @@ # findSystemInclude # findLibrary # findExtLib +# versionCompare # # Internal variables used # extLibraries @@ -318,6 +319,74 @@ then return 2 } + + + # Compare version tuples with syntax similar to POSIX shell, + # but respecting dot separators. + # + # arg1 OP arg2 + # OP is one of -eq, -ne, -lt, -le, -gt, or -ge. + # Returns true for a successful comparison. + # Arg1 and arg2 normally comprise positive integers, but leading content + # before a '-' is stripped. + # Missing digits are treated as '0'. + # + # Eg, + # versionCompare "software-1.2.3" -gt 1.1 && echo True + # + # Ad hoc handling of "git" version as always newest. + # "git" -gt "1.2.3" : True + # "1.2.3" -lt "git" : True + versionCompare() + { + [ "$#" -eq 3 ] || { + echo "Compare needs 3 arguments (was given $#)" 1>&2 + return 2 + } + + local arg1="${1#*-}" # Strip leading prefix- + local op="${2}" + local arg2="${3#*-}" # Strip leading prefix- + local result='' # Empty represents 'equal' + + arg1="${arg1:-0}." + arg2="${arg2:-0}." + + if [ "$arg1" = "$arg2" ]; then unset arg1 arg2 # Identical + elif [ "${arg1#git}" != "$arg1" ]; then result='more' # (git > arg2) + elif [ "${arg2#git}" != "$arg2" ]; then result='less' # (arg1 < git) + fi + + while [ -z "$result" ] && [ -n "${arg1}${arg2}" ] + do + local digits1="${arg1%%.*}" + local digits2="${arg2%%.*}" + + arg1="${arg1#*.}" + arg2="${arg2#*.}" + + : "${digits1:=0}" + : "${digits2:=0}" + + # Other handling of non-integer values? + if [ "$digits1" -lt "$digits2" ]; then result='less' + elif [ "$digits1" -gt "$digits2" ]; then result='more' + fi + done + + case "$op" in + (-eq | eq) [ -z "$result" ] ;; + (-ne | ne) [ -n "$result" ] ;; + (-lt | lt) [ 'less' = "$result" ] ;; + (-gt | gt) [ 'more' = "$result" ] ;; + (-le | le) [ 'less' = "${result:-less}" ] ;; + (-ge | ge) [ 'more' = "${result:-more}" ] ;; + (*) + echo "Unknown operator: '$op'" 1>&2 + return 2 + ;; + esac + } fi