Integrated changes for framework

Pdm fields can contain a forward declared Pdm object without the include
file
VizFwk: Added VertexColoring shader to be able to use per vertex color
used from drawableGeo::setColorArray()
This commit is contained in:
Magne Sjaastad
2014-04-11 11:06:42 +02:00
parent 4125ab3ae8
commit 486f383de7
68 changed files with 2177 additions and 88 deletions

View File

@@ -6,13 +6,13 @@ project(LibCore)
# Use our strict compile flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_STRICT_CXX_FLAGS}")
set(CEE_HEADER_FILES
cvfArray.h
cvfArray.inl
cvfArrayWrapperConst.h
cvfArrayWrapperToEdit.h
cvfAssert.h
cvfAtomicCounter.h
cvfBase.h
cvfBase64.h
cvfCharArray.h
@@ -68,6 +68,7 @@ cvfVersion.h
set(CEE_SOURCE_FILES
cvfAssert.cpp
cvfAtomicCounter.cpp
cvfBase64.cpp
cvfCharArray.cpp
cvfCodeLocation.cpp

View File

@@ -232,6 +232,7 @@
<ClInclude Include="cvfArrayWrapperConst.h" />
<ClInclude Include="cvfArrayWrapperToEdit.h" />
<ClInclude Include="cvfAssert.h" />
<ClInclude Include="cvfAtomicCounter.h" />
<ClInclude Include="cvfBase.h" />
<ClInclude Include="cvfBase64.h" />
<ClInclude Include="cvfCharArray.h" />
@@ -290,6 +291,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="cvfAssert.cpp" />
<ClCompile Include="cvfAtomicCounter.cpp" />
<ClCompile Include="cvfBase64.cpp" />
<ClCompile Include="cvfCharArray.cpp" />
<ClCompile Include="cvfCodeLocation.cpp" />

View File

@@ -45,6 +45,7 @@
<ClInclude Include="cvfArrayWrapperConst.h" />
<ClInclude Include="cvfArrayWrapperToEdit.h" />
<ClInclude Include="cvfProgramOptions.h" />
<ClInclude Include="cvfAtomicCounter.h" />
</ItemGroup>
<ItemGroup>
<None Include="cvfArray.inl" />
@@ -90,5 +91,6 @@
<ClCompile Include="cvfLogDestinationConsole.cpp" />
<ClCompile Include="cvfLogDestinationFile.cpp" />
<ClCompile Include="cvfProgramOptions.cpp" />
<ClCompile Include="cvfAtomicCounter.cpp" />
</ItemGroup>
</Project>
</Project>

View File

@@ -151,3 +151,4 @@ inline const ArrayWrapperConst< const ElmType*, ElmType > wrapArrayConst( ElmTy
}
}

View File

@@ -130,3 +130,4 @@ inline ArrayWrapperToEdit< ElmType*, ElmType > wrapArrayToEdit(ElmType* array, s
}
}

View File

@@ -113,9 +113,11 @@ Assert::FailAction AssertHandlerConsole::handleAssert(const char* fileName, int
// Does the job on both Windows and Linux (creates a console on Windows if one doesn't exist)
reportToConsole(fileName, lineNumber, expr, msg);
#ifdef WIN32
if (::IsDebuggerPresent())
{
#ifdef _MSC_VER
#if (_MSC_VER >= 1600)
if (::IsDebuggerPresent())
#endif
{
__debugbreak();
}
#endif

View File

@@ -0,0 +1,193 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2014 Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cvfAtomicCounter.h"
// Some older GCC version do not support atomics, we have seen this for RHEL5
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
namespace cvf {
#ifdef WIN32
#pragma warning (push)
#pragma warning (disable: 4668)
#include <windows.h>
#pragma warning (pop)
AtomicCounter::AtomicCounter(int initialValue)
: m_counter(initialValue)
{
}
AtomicCounter::~AtomicCounter()
{
}
AtomicCounter::operator int () const
{
return m_counter;
}
int AtomicCounter::operator ++ () // prefix
{
return InterlockedIncrement(&m_counter);
}
int AtomicCounter::operator ++ (int) // postfix
{
int result = InterlockedIncrement(&m_counter);
return --result;
}
int AtomicCounter::operator -- () // prefix
{
return InterlockedDecrement(&m_counter);
}
int AtomicCounter::operator -- (int) // postfix
{
int result = InterlockedDecrement(&m_counter);
return ++result;
}
#elif defined(CVF_IOS) || defined(CVF_OSX)
AtomicCounter::AtomicCounter(int initialValue)
: m_counter(initialValue)
{
}
AtomicCounter::AtomicCounter(const AtomicCounter& counter)
: m_counter(counter.value())
{
}
AtomicCounter::~AtomicCounter()
{
}
AtomicCounter::operator int () const
{
return m_counter;
}
int AtomicCounter::operator ++ () // prefix
{
return OSAtomicIncrement32(&m_counter);
}
int AtomicCounter::operator ++ (int) // postfix
{
int result = OSAtomicIncrement32(&m_counter);
return --result;
}
int AtomicCounter::operator -- () // prefix
{
return OSAtomicDecrement32(&m_counter);
}
int AtomicCounter::operator -- (int) // postfix
{
int result = OSAtomicDecrement32(&m_counter);
return ++result;
}
#elif defined(CVF_HAVE_GCC_ATOMICS)
AtomicCounter::AtomicCounter(int initialValue)
: m_counter(initialValue)
{
}
AtomicCounter::~AtomicCounter()
{
}
AtomicCounter::operator int () const
{
return m_counter;
}
int AtomicCounter::operator ++ () // prefix
{
return __sync_add_and_fetch(&m_counter, 1);
}
int AtomicCounter::operator ++ (int) // postfix
{
return __sync_fetch_and_add(&m_counter, 1);
}
int AtomicCounter::operator -- () // prefix
{
return __sync_sub_and_fetch(&m_counter, 1);
}
int AtomicCounter::operator -- (int) // postfix
{
return __sync_fetch_and_sub(&m_counter, 1);
}
#endif
} // namespace cvf
#endif // CVF_ATOMICS_COMPILED

View File

@@ -0,0 +1,96 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2014 Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cvfBase.h"
#ifdef WIN32
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
#elif defined(CVF_IOS) || defined(CVF_OSX)
#include <libkern/OSAtomic.h>
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
#elif defined __GNUC__
#if (CVF_GCC_VER >= 40200) && (defined(__x86_64__) || defined(__i386__))
#define CVF_HAVE_GCC_ATOMICS
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
#elif (CVF_GCC_VER >= 40300)
#define CVF_HAVE_GCC_ATOMICS
#define CVF_ATOMIC_COUNTER_CLASS_EXISTS
#endif
#endif
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
namespace cvf {
// Inspired by Poco
class AtomicCounter
{
public:
explicit AtomicCounter(int initialValue);
~AtomicCounter();
operator int () const;
int operator ++ (); // prefix
int operator ++ (int); // postfix
int operator -- (); // prefix
int operator -- (int); // postfix
private:
CVF_DISABLE_COPY_AND_ASSIGN(AtomicCounter);
#ifdef WIN32
typedef volatile long ImplType;
#elif defined(CVF_IOS) || defined(CVF_OSX)
typedef int32_t ImplType;
#else
typedef int ImplType;
#endif
ImplType m_counter;
};
} // namespace cvf
#endif

View File

@@ -44,7 +44,7 @@
// Global include file with definitions useful for all library files
// Disable some annoying warnings so we can compile with warning level Wall
#ifdef WIN32
#ifdef _MSC_VER
// 4512 'class' : assignment operator could not be generated : Due to problems with classes with reference member variables (e.g. VertexCompactor)
// 4514 unreferenced inline/local function has been removed
// 4625 copy constructor could not be generated because a base class copy constructor is inaccessible
@@ -54,13 +54,26 @@
// 4711 function 'func_name' selected for automatic inline expansion
// 4738 storing 32-bit float result in memory, possible loss of performance
// 4820 'bytes' bytes padding added after construct 'member_name'
#pragma warning (disable: 4512 4514 4625 4626 4640 4710 4711 4738 4820)
#if (_MSC_VER >= 1600)
// VS2010 and newer
// 4986 'operator new[]': exception specification does not match previous declaration
#pragma warning (disable: 4512 4514 4625 4626 4640 4710 4711 4738 4820 4986)
#pragma warning (disable: 4986)
#endif
#endif
// Makes it easier to check on the current GCC version
#ifdef __GNUC__
// 40302 means version 4.3.2.
# define CVF_GCC_VER (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
#endif
// Helper macro to disable (ignore) compiler warnings on GCC
// The needed pragma is only available in GCC for versions 4.2.x and above
#if defined __GNUC__ && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 402)
#if defined(__GNUC__) && (CVF_GCC_VER >= 40200)
#define CVF_DO_PRAGMA(x) _Pragma(#x)
#define CVF_GCC_DIAGNOSTIC_IGNORE(OPTION_STRING) CVF_DO_PRAGMA(GCC diagnostic ignored OPTION_STRING)
#else

View File

@@ -41,6 +41,15 @@
#include <set>
#include "cvfAtomicCounter.h"
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS) && defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
#error Two mutually exclusive defines detected : CVF_ATOMIC_COUNTER_CLASS_EXISTS && CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS
#endif
#if !defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS) && !defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
#error No support for atomics. Define CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS to be able to compile
#endif
namespace cvf {
@@ -65,7 +74,13 @@ public:
static void dumpActiveObjectInstances();
private:
#if defined(CVF_ATOMIC_COUNTER_CLASS_EXISTS)
mutable AtomicCounter m_refCount;
#elif defined(CVF_WORKAROUND_TO_COMPILE_ON_SYSTEMS_WITHOUT_ATOMICS)
mutable int m_refCount;
#endif
CVF_DISABLE_COPY_AND_ASSIGN(Object);
};

View File

@@ -91,9 +91,7 @@ inline int Object::release() const
CVF_TIGHT_ASSERT(m_refCount > 0);
m_refCount--;
if (m_refCount == 0)
if (--m_refCount == 0)
{
delete this;
return 0;

View File

@@ -205,7 +205,7 @@ bool Plane::setFromPointAndNormal(const Vec3d& point, const Vec3d& normal)
/// \param p2 Second point on the plane
/// \param p3 Third point on the plane
///
/// \return true if successfully set. false if points are on the same line.
/// \return true if successfully set. false if points are on the same line.
///
/// The three points must be different from each other and cannot be on the same line in space
//--------------------------------------------------------------------------------------------------
@@ -322,7 +322,7 @@ double Plane::distanceToOrigin() const
/// \param vector Vector to be projected
/// \param projectedVector Projected vector to be returned by pointer
///
/// \return true if successfully projected.
/// \return true if successfully projected.
/// false if the given \a vector is parallel with the plane's normal
//--------------------------------------------------------------------------------------------------
bool Plane::projectVector(const Vec3d& vector, Vec3d* projectedVector) const
@@ -378,7 +378,7 @@ Vec3d Plane::projectPoint(const Vec3d& point) const
/// \param point Point on line
/// \param direction Normalized direction of line
///
/// \return true if success. false if direction is zero -> no point of intersection exists
/// \return true if success. false if direction is zero -> no point of intersection exists
//--------------------------------------------------------------------------------------------------
bool Plane::intersect(const Plane& other, Vec3d* point, Vec3d* direction) const
{
@@ -474,6 +474,125 @@ bool Plane::intersect(const Vec3d& a, const Vec3d& b, Vec3d* intersection) const
return false;
}
//--------------------------------------------------------------------------------------------------
/// Clip a triangle against this plane
///
/// Clip the triangle given by parameters a, b and c against this plane. The vertices of the
/// resulting clipped polygon (triangle or quad) will be returned in \a clippedPolygon. Since the
/// clipped polygon may be a quad, the \a clippedPolygon array must have room for at least 4 elements.
///
/// \return The number of resulting vertices that are populated in \a clippedPolygon. Will be 0, 3 or 4.
//--------------------------------------------------------------------------------------------------
size_t Plane::clipTriangle(const Vec3d& a, const Vec3d& b, const Vec3d& c, Vec3d clippedPolygon[4]) const
{
// Except for the trivial cases where all vertices are in front
// or behind plane, these are the permutations
//
// Single vertex on positive side of plane
// => return a triangle
//
// +\ /\c /\c /+ /\c .
// \ / \ / \ / + / \ + .
// \ \ / \/ ---/----\--- .
// / \ \ / /\ / \ .
// a/___\____\b a/_____/__\b a/________\b .
// +\ /+
//
// Two vertices vertex on positive side of plane
// => return a quad
//
// /\c \+ /\c /\c +/ .
// / \ \ / \ / \ / .
// ___/____\___ \ \ / \/ .
// + / \ + / \ \ / /\ .
// a/________\b a/___\____\b a/_____/__\b .
// \+ +/
bool onPosSide[3];
onPosSide[0] = distanceSquared(a) >= 0 ? true : false;
onPosSide[1] = distanceSquared(b) >= 0 ? true : false;
onPosSide[2] = distanceSquared(c) >= 0 ? true : false;
const int numPositiveVertices = (onPosSide[0] ? 1 : 0) + (onPosSide[1] ? 1 : 0) + (onPosSide[2] ? 1 : 0);
// The entire triangle is on the negative side
// Clip everything
if (numPositiveVertices == 0)
{
return 0;
}
// All triangle vertices are on the positive side
// Return the same triangle
if (numPositiveVertices == 3)
{
clippedPolygon[0] = a;
clippedPolygon[1] = b;
clippedPolygon[2] = c;
return 3;
}
// Handle case where a single vertex is on the positive side
// Will result in the return of a single clipped triangle
if (numPositiveVertices == 1)
{
if (onPosSide[0])
{
clippedPolygon[0] = a;
intersect(a, b, &clippedPolygon[1]);
intersect(a, c, &clippedPolygon[2]);
}
else if (onPosSide[1])
{
clippedPolygon[0] = b;
intersect(b, c, &clippedPolygon[1]);
intersect(b, a, &clippedPolygon[2]);
}
else
{
CVF_ASSERT(onPosSide[2]);
clippedPolygon[0] = c;
intersect(c, a, &clippedPolygon[1]);
intersect(c, b, &clippedPolygon[2]);
}
return 3;
}
else
{
CVF_ASSERT(numPositiveVertices == 2);
if (onPosSide[0] && onPosSide[1])
{
// a & b are on positive side
clippedPolygon[0] = a;
clippedPolygon[1] = b;
intersect(b, c, &clippedPolygon[2]);
intersect(a, c, &clippedPolygon[3]);
}
else if (onPosSide[1] && onPosSide[2])
{
// b & c are on positive side
clippedPolygon[0] = b;
clippedPolygon[1] = c;
intersect(c, a, &clippedPolygon[2]);
intersect(b, a, &clippedPolygon[3]);
}
else
{
// c && a are on positive side
CVF_ASSERT(onPosSide[2] && onPosSide[0]);
clippedPolygon[0] = c;
clippedPolygon[1] = a;
intersect(a, b, &clippedPolygon[2]);
intersect(c, b, &clippedPolygon[3]);
}
return 4;
}
}
//--------------------------------------------------------------------------------------------------
/// Classify where the point is located relative to the plane
///

View File

@@ -91,7 +91,8 @@ public:
bool intersect(const Plane& other, Vec3d* point, Vec3d* direction = NULL) const;
bool intersect(const Vec3d& a, const Vec3d& b, Vec3d* intersection) const;
size_t clipTriangle(const Vec3d& ta, const Vec3d& tb, const Vec3d& tc, Vec3d clippedPolygon[4]) const;
Side side(const Vec3d& point) const;
Side side(const Vec3dArray& points) const;

View File

@@ -108,6 +108,8 @@ public:
inline S lengthSquared() const;
bool setLength(S newLength);
const Vector2 perpendicularVector() const;
public:
static const Vector2 X_AXIS; ///< X axis vector <1, 0>
static const Vector2 Y_AXIS; ///< Y axis vector <0, 1>

View File

@@ -394,6 +394,27 @@ bool Vector2<S>::setLength(S newLength)
}
//--------------------------------------------------------------------------------------------------
/// Return a unit length perpendicular vector
///
/// Returns the vector (y,-x), normalized. This can be thought of as the 'right' vector.
//--------------------------------------------------------------------------------------------------
template<typename S>
const Vector2<S> Vector2<S>::perpendicularVector() const
{
S len = length();
if (len > 0.0)
{
S oneOverLen = (static_cast<S>(1.0)/len);
return Vector2<S>(m_v[1]*oneOverLen, -m_v[0]*oneOverLen);
}
else
{
return Vector2<S>::ZERO;
}
}
//--------------------------------------------------------------------------------------------------
/// Normalize the vector (make sure the length is 1.0).
///