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

@@ -14,6 +14,7 @@ set(CEE_LIBS LibCore)
set(CEE_SOURCE_FILES
cvfArray-Test.cpp
cvfArrayWrapper-Test.cpp
cvfAtomicCounter-Test.cpp
cvfBase-Test.cpp
cvfBase64-Test.cpp
cvfCharArray-Test.cpp

View File

@@ -251,6 +251,7 @@
<ClCompile Include="..\..\ThirdParty\gtest\gtest-all.cpp" />
<ClCompile Include="cvfArray-Test.cpp" />
<ClCompile Include="cvfArrayWrapper-Test.cpp" />
<ClCompile Include="cvfAtomicCounter-Test.cpp" />
<ClCompile Include="cvfBase-Test.cpp" />
<ClCompile Include="cvfBase64-Test.cpp" />
<ClCompile Include="cvfCharArray-Test.cpp" />

View File

@@ -34,6 +34,7 @@
<ClCompile Include="cvfCodeLocation-Test.cpp" />
<ClCompile Include="cvfArrayWrapper-Test.cpp" />
<ClCompile Include="cvfProgramOptions-Test.cpp" />
<ClCompile Include="cvfAtomicCounter-Test.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />
@@ -41,4 +42,4 @@
<ItemGroup>
<CustomBuild Include="TriggerTBBCopy.txt" />
</ItemGroup>
</Project>
</Project>

View File

@@ -123,10 +123,10 @@ TEST(ArrayWrapperTest, AllSpecializations)
siztCvfArray[0] = 0;
siztCvfArray[1] = 1;
cvf::Array<uint> uintCvfArray(2);
cvf::Array<cvf::uint> uintCvfArray(2);
uintCvfArray[0] = 0;
uintCvfArray[1] = 1;
const cvf::Array<uint>& cuintCvfArray = uintCvfArray;
const cvf::Array<cvf::uint>& cuintCvfArray = uintCvfArray;
size_t siztBarePtrArray[2] = {0, 1};
@@ -187,3 +187,4 @@ TEST(ArrayWrapperTest, AllSpecializations)
EXPECT_EQ(0.0, doubleBarePtr[1]);
EXPECT_EQ(1.0, doubleBarePtr[0]);
}

View File

@@ -0,0 +1,141 @@
//##################################################################################################
//
// 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"
#ifdef CVF_ATOMIC_COUNTER_CLASS_EXISTS
#include "cvfDebugTimer.h"
#include "cvfObject.h"
#include "cvfCollection.h"
#include "gtest/gtest.h"
using namespace cvf;
class MyObj : public Object
{
public:
MyObj() { num_ = 0; }
MyObj(int num) { num_ = num; }
int num() const { return num_; }
void num(int num) { num_ = num; }
bool operator<(const MyObj& rhs)
{
return num_ < rhs.num_;
}
private:
int num_;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(DISABLED_ObjectConstructionBenchmark, TestBasicObjectConstruction)
{
int objectCount = 1000000;
int iterationCount = 5;
String sNumber(objectCount);
String refCountTxt = String("TestBasicObjectConstruction : ") + sNumber;
DebugTimer tim(refCountTxt.toAscii().ptr());
for (int iteration = 0; iteration < iterationCount; iteration++)
{
for (int i = 0; i < objectCount; i++)
{
MyObj* r2 = new MyObj();
r2->addRef();
r2->release();
}
tim.reportLapTimeMS();
}
}
class ObjectReferencingSharedObject : public Object
{
public:
ObjectReferencingSharedObject() { }
cvf::ref<MyObj> m_sharedObject;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(DISABLED_ObjectConstructionBenchmark, TestReferenceOtherObject)
{
int objectCount = 1000000;
int iterationCount = 5;
String sNumber(objectCount);
String refCountTxt = String("TestReferenceOtherObjectClass : ") + sNumber;
DebugTimer tim(refCountTxt.toAscii().ptr());
for (int iteration = 0; iteration < iterationCount; iteration++)
{
cvf::ref<MyObj> sharedObj = new MyObj();
std::vector< cvf::ref<ObjectReferencingSharedObject> > col;
col.resize(objectCount);
for (int i = 0; i < objectCount; i++)
{
cvf::ref<ObjectReferencingSharedObject> newObj = new ObjectReferencingSharedObject();
newObj->m_sharedObject = sharedObj.p();
col[i] = newObj;
}
String sNumber(sharedObj->refCount());
String refCountTxt = String("Shared object reference count : ") + sNumber;
tim.reportLapTimeMS(refCountTxt.toAscii().ptr());
}
}
#endif //#ifdef CVF_ATOMIC_COUNTER_CLASS_EXISTS

View File

@@ -365,6 +365,38 @@ TEST(Vector2Test, SetLength)
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(Vector2Test, perpendicularVector)
{
{
const Vec2d v(0, 1);
const Vec2d perp = v.perpendicularVector();
EXPECT_DOUBLE_EQ(1, perp.x());
EXPECT_DOUBLE_EQ(0, perp.y());
}
{
const Vec2d v(1, 0);
const Vec2d perp = v.perpendicularVector();
EXPECT_DOUBLE_EQ(0, perp.x());
EXPECT_DOUBLE_EQ(-1, perp.y());
}
{
const Vec2d v(0, -2);
const Vec2d perp = v.perpendicularVector();
EXPECT_DOUBLE_EQ(-1, perp.x());
EXPECT_DOUBLE_EQ(0, perp.y());
}
{
const Vec2d v(-3, 0);
const Vec2d perp = v.perpendicularVector();
EXPECT_DOUBLE_EQ(0, perp.x());
EXPECT_DOUBLE_EQ(1, perp.y());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -26,6 +26,7 @@ cvfGeometryUtils-Test.cpp
cvfMeshEdgeExtractor-Test.cpp
cvfOutlineEdgeExtractor-Test.cpp
cvfPatchGenerator-Test.cpp
cvfPrimitiveTests-Test.cpp
cvfRay-Test.cpp
cvfTriangleMeshEdgeExtractor-Test.cpp
cvfTriangleVertexSplitter-Test.cpp

View File

@@ -262,6 +262,7 @@
<ClCompile Include="cvfMeshEdgeExtractor-Test.cpp" />
<ClCompile Include="cvfOutlineEdgeExtractor-Test.cpp" />
<ClCompile Include="cvfPatchGenerator-Test.cpp" />
<ClCompile Include="cvfPrimitiveTests-Test.cpp" />
<ClCompile Include="cvfRay-Test.cpp" />
<ClCompile Include="cvfTriangleMeshEdgeExtractor-Test.cpp" />
<ClCompile Include="cvfTriangleVertexSplitter-Test.cpp" />

View File

@@ -21,6 +21,7 @@
<ClCompile Include="cvfVertexCompactor-Test.cpp" />
<ClCompile Include="cvfTriangleMeshEdgeExtractor-Test.cpp" />
<ClCompile Include="cvfBoundingBoxTree-Test.cpp" />
<ClCompile Include="cvfPrimitiveTests-Test.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />

View File

@@ -0,0 +1,90 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron 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 "cvfBase.h"
#include "cvfPrimitiveTests.h"
#include "gtest/gtest.h"
using namespace cvf;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(PrimitiveTestsTest, intersectLines)
{
{
Vec2d p1(0, 0); Vec2d p2(2, 0);
Vec2d p3(1, -1); Vec2d p4(1, 1);
Vec2d isect(0, 0);
EXPECT_TRUE(PrimitiveTests::intersectLines(p1, p2, p3, p4, &isect));
EXPECT_DOUBLE_EQ(1, isect.x());
EXPECT_DOUBLE_EQ(0, isect.y());
}
{
Vec2d p1(0, 0); Vec2d p2(2, 0);
Vec2d p3(1, 2); Vec2d p4(1, 1);
Vec2d isect(0, 0);
EXPECT_TRUE(PrimitiveTests::intersectLines(p1, p2, p3, p4, &isect));
EXPECT_DOUBLE_EQ(1, isect.x());
EXPECT_DOUBLE_EQ(0, isect.y());
}
// Incident
{
Vec2d p1(1, 0); Vec2d p2(3, 0);
Vec2d p3(2, 0); Vec2d p4(4, 0);
Vec2d isect(0, 0);
EXPECT_TRUE(PrimitiveTests::intersectLines(p1, p2, p3, p4, &isect));
EXPECT_DOUBLE_EQ(2, isect.x());
EXPECT_DOUBLE_EQ(0, isect.y());
}
// Parallell
{
Vec2d p1(0, 0); Vec2d p2(2, 0);
Vec2d p3(0, 2); Vec2d p4(2, 2);
Vec2d isect(0, 0);
EXPECT_FALSE(PrimitiveTests::intersectLines(p1, p2, p3, p4, &isect));
EXPECT_DOUBLE_EQ(0, isect.x());
EXPECT_DOUBLE_EQ(0, isect.y());
}
}

View File

@@ -128,6 +128,51 @@ TEST(ModelBasicListDeathTest, IllegalIndexing)
}
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(ModelBasicListTest, shrinkPartCount)
{
ref<Part> p1 = new Part;
ref<Part> p2 = new Part;
ref<Part> p3 = new Part;
{
ref<ModelBasicList> myModel = new ModelBasicList;
myModel->addPart(p1.p());
myModel->addPart(p2.p());
myModel->addPart(p3.p());
ASSERT_EQ(3, myModel->partCount());
EXPECT_EQ(2, p1->refCount());
EXPECT_EQ(2, p2->refCount());
EXPECT_EQ(2, p3->refCount());
myModel->shrinkPartCount(3);
ASSERT_EQ(3, myModel->partCount());
EXPECT_EQ(2, p1->refCount());
EXPECT_EQ(2, p2->refCount());
EXPECT_EQ(2, p3->refCount());
myModel->shrinkPartCount(2);
ASSERT_EQ(2, myModel->partCount());
EXPECT_EQ(2, p1->refCount());
EXPECT_EQ(2, p2->refCount());
EXPECT_EQ(1, p3->refCount());
myModel->shrinkPartCount(0);
ASSERT_EQ(0, myModel->partCount());
EXPECT_EQ(1, p1->refCount());
EXPECT_EQ(1, p2->refCount());
EXPECT_EQ(1, p3->refCount());
}
EXPECT_EQ(1, p1->refCount());
EXPECT_EQ(1, p2->refCount());
EXPECT_EQ(1, p3->refCount());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -47,6 +47,16 @@
namespace snip {
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
VertexColoring::VertexColoring()
: m_useShaders(false)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -54,20 +64,37 @@ bool VertexColoring::onInitialize()
{
ref<ModelBasicList> myModel = new ModelBasicList;
// Create the effect
// Create the fixed function effect
{
m_effect = new Effect;
m_fixedFuncEffect = new Effect;
ref<RenderStateMaterial_FF> mat = new RenderStateMaterial_FF(Color3::BLUE);
mat->enableColorMaterial(true);
m_effect->setRenderState(mat.p());
m_fixedFuncEffect->setRenderState(mat.p());
ref<RenderStateLighting_FF> lighting = new RenderStateLighting_FF;
m_effect->setRenderState(lighting.p());
m_fixedFuncEffect->setRenderState(lighting.p());
}
// Create effect with shader program
{
m_shaderEffect = new Effect;
ShaderProgramGenerator gen("PerVertexColor", ShaderSourceProvider::instance());
gen.addVertexCode(ShaderSourceRepository::vs_Standard);
gen.addFragmentCode(ShaderSourceRepository::src_VaryingColorGlobalAlpha);
gen.addFragmentCode(ShaderSourceRepository::light_SimpleHeadlight);
gen.addFragmentCode(ShaderSourceRepository::fs_Standard);
m_shaderProg = gen.generate();
m_shaderProg->setDefaultUniform(new cvf::UniformFloat("u_alpha", 1.0f));
m_shaderEffect->setShaderProgram(m_shaderProg.p());
}
// "Normal" geometry
ref<Effect> effectToUse = m_useShaders ? m_shaderEffect : m_fixedFuncEffect;
// Lower left: "Normal" geometry
{
GeometryBuilderDrawableGeo builder;
GeometryUtils::createBox(Vec3f(0,0,0), 2.0, 2.0, 2.0, &builder);
@@ -76,12 +103,13 @@ bool VertexColoring::onInitialize()
ref<Part> part = new Part;
part->setDrawable(geo.p());
part->setEffect(m_effect.p());
part->setEffect(effectToUse.p());
myModel->addPart(part.p());
}
// Geometry with per vertex colors
// Lower right: Geometry with per vertex colors
// Results in one color per face of the cube
{
GeometryBuilderDrawableGeo builder;
GeometryUtils::createBox(Vec3f(3,0,0), 2.0, 2.0, 2.0, &builder);
@@ -114,12 +142,12 @@ bool VertexColoring::onInitialize()
ref<Part> part = new Part;
part->setDrawable(geo.p());
part->setEffect(m_effect.p());
part->setEffect(effectToUse.p());
myModel->addPart(part.p());
}
// Geometry with per vertex colors (using ScalarToColorMapper)
// Upper right: Geometry with per vertex colors (using ScalarToColorMapper)
{
BoxGenerator gen;
gen.setMinMax(Vec3d(2,-1,2), Vec3d(4, 1, 4));
@@ -159,12 +187,12 @@ bool VertexColoring::onInitialize()
ref<Part> part = new Part;
part->setDrawable(geo.p());
part->setEffect(m_effect.p());
part->setEffect(effectToUse.p());
myModel->addPart(part.p());
}
// Geometry without normals
// Upper left: Geometry without normals
{
GeometryBuilderDrawableGeo builder;
GeometryUtils::createBox(Vec3f(0,0,3), 2.0, 2.0, 2.0, &builder);
@@ -173,7 +201,7 @@ bool VertexColoring::onInitialize()
ref<Part> part = new Part;
part->setDrawable(geo.p());
part->setEffect(m_effect.p());
part->setEffect(effectToUse.p());
myModel->addPart(part.p());
}
@@ -233,11 +261,24 @@ void VertexColoring::onKeyPressEvent(KeyEvent* keyEvent)
Key key = keyEvent->key();
char character = keyEvent->character();
if (key == Key_S || key == Key_F)
{
m_useShaders = (key == Key_S) ? true : false;
Collection<Part> partCollection;
m_renderSequence->firstRendering()->scene()->model(0)->allParts(&partCollection);
for (size_t i = 0; i < partCollection.size(); i++)
{
ref<Part> part = partCollection[i];
part->setEffect(m_useShaders ? m_shaderEffect.p() : m_fixedFuncEffect.p());
}
}
if (key == Key_L)
{
bool lightingOn = (character == 'l') ? true : false;
RenderStateLighting_FF* rsLighting = dynamic_cast<RenderStateLighting_FF*>(m_effect->renderStateOfType(RenderState::LIGHTING_FF));
RenderStateLighting_FF* rsLighting = dynamic_cast<RenderStateLighting_FF*>(m_fixedFuncEffect->renderStateOfType(RenderState::LIGHTING_FF));
rsLighting->enable(lightingOn);
}
@@ -245,7 +286,7 @@ void VertexColoring::onKeyPressEvent(KeyEvent* keyEvent)
{
bool colorMaterialOn = (character == 'c') ? true : false;
RenderStateMaterial_FF* rsMaterial = dynamic_cast<RenderStateMaterial_FF*>(m_effect->renderStateOfType(RenderState::MATERIAL_FF));
RenderStateMaterial_FF* rsMaterial = dynamic_cast<RenderStateMaterial_FF*>(m_fixedFuncEffect->renderStateOfType(RenderState::MATERIAL_FF));
rsMaterial->enableColorMaterial(colorMaterialOn);
}
@@ -259,8 +300,10 @@ void VertexColoring::onKeyPressEvent(KeyEvent* keyEvent)
std::vector<cvf::String> VertexColoring::helpText() const
{
std::vector<String> help;
help.push_back(String("l/L - to toggle lighting on/off"));
help.push_back(String("c/C - to toggle color material on/off"));
help.push_back("s - to use a shader program for rendering");
help.push_back("f - to use fixed function pipeline for rendering");
help.push_back("l/L - to toggle lighting on/off (in fixed function)");
help.push_back("c/C - to toggle color material on/off (in fixed function)");
return help;

View File

@@ -55,6 +55,7 @@ class VertexColoring : public TestSnippet
CVFU_DECLARE_SNIPPET("Vertex Coloring");
public:
VertexColoring();
virtual bool onInitialize();
virtual void onKeyPressEvent(KeyEvent* keyEvent);
@@ -64,7 +65,10 @@ private:
void addEdgesRendering();
private:
ref<Effect> m_effect;
bool m_useShaders;
ref<ShaderProgram> m_shaderProg;
ref<Effect> m_fixedFuncEffect;
ref<Effect> m_shaderEffect;
};
}