mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Integrated visualization modules to changelist 20202
p4#: 20204
This commit is contained in:
parent
e88f62abcf
commit
56e61ea468
@ -34,6 +34,8 @@ cvfMatrix4.inl
|
||||
cvfObject.h
|
||||
cvfObject.inl
|
||||
cvfPlane.h
|
||||
cvfPropertySet.h
|
||||
cvfPropertySetCollection.h
|
||||
cvfQuat.h
|
||||
cvfQuat.inl
|
||||
cvfRect.h
|
||||
@ -44,6 +46,7 @@ cvfTBBControl.h
|
||||
cvfTimer.h
|
||||
cvfTrace.h
|
||||
cvfValueArray.h
|
||||
cvfVariant.h
|
||||
cvfVector2.h
|
||||
cvfVector2.inl
|
||||
cvfVector3.h
|
||||
@ -64,11 +67,14 @@ cvfLogger.cpp
|
||||
cvfMath.cpp
|
||||
cvfObject.cpp
|
||||
cvfPlane.cpp
|
||||
cvfPropertySet.cpp
|
||||
cvfPropertySetCollection.cpp
|
||||
cvfString.cpp
|
||||
cvfSystem.cpp
|
||||
cvfTimer.cpp
|
||||
cvfTBBControl.cpp
|
||||
cvfTrace.cpp
|
||||
cvfVariant.cpp
|
||||
cvfVector2.cpp
|
||||
cvfVector3.cpp
|
||||
cvfVector4.cpp
|
||||
|
@ -95,7 +95,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
|
||||
__debugbreak();
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
|
||||
// Shouldn't really matter since we always abort
|
||||
return Assert::CONTINUE;
|
||||
|
@ -388,6 +388,7 @@ Color3ub::Color3ub(ColorIdent colorIdent)
|
||||
case SKY_BLUE: set(135, 206, 235); break;
|
||||
case VIOLET: set(238, 130, 238); break;
|
||||
case YELLOW_GREEN: set(154, 205, 50); break;
|
||||
case CEETRON: set( 81, 134, 148); break;
|
||||
|
||||
default: CVF_FAIL_MSG("Unknown ColorIdent");
|
||||
}
|
||||
|
@ -73,7 +73,9 @@ public:
|
||||
SEA_GREEN, ///< Sea green (46, 139, 87)
|
||||
SKY_BLUE, ///< Sky blue (135, 206, 235)
|
||||
VIOLET, ///< Violet (238, 130, 238)
|
||||
YELLOW_GREEN ///< Yellow green (154, 205, 50)
|
||||
YELLOW_GREEN, ///< Yellow green (154, 205, 50)
|
||||
|
||||
CEETRON ///< Ceetron Color (81, 134, 148)
|
||||
};
|
||||
};
|
||||
|
||||
|
161
VisualizationModules/LibCore/cvfPropertySet.cpp
Normal file
161
VisualizationModules/LibCore/cvfPropertySet.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPropertySet.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::PropertySet
|
||||
/// \ingroup Core
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet::PropertySet(const String& classType)
|
||||
: m_classType(classType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet::~PropertySet()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PropertySet::operator==(const PropertySet& rhs) const
|
||||
{
|
||||
if (m_classType == rhs.m_classType)
|
||||
{
|
||||
return (m_propMap == rhs.m_propMap);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String PropertySet::classType() const
|
||||
{
|
||||
return m_classType;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PropertySet::isEmpty() const
|
||||
{
|
||||
return m_propMap.empty();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant PropertySet::value(const String& key) const
|
||||
{
|
||||
std::map<String, Variant>::const_iterator it = m_propMap.find(key);
|
||||
if (it != m_propMap.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Variant();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PropertySet::setValue(const String& key, const Variant& data)
|
||||
{
|
||||
m_propMap[key] = data;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PropertySet::contains(const String& key) const
|
||||
{
|
||||
if (m_propMap.find(key) != m_propMap.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<String> PropertySet::allKeys() const
|
||||
{
|
||||
std::vector<String> all;
|
||||
std::map<String, Variant>::const_iterator it;
|
||||
for (it = m_propMap.begin(); it != m_propMap.end(); ++it)
|
||||
{
|
||||
all.push_back(it->first);
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<Variant> PropertySet::allValues() const
|
||||
{
|
||||
std::vector<Variant> all;
|
||||
std::map<String, Variant>::const_iterator it;
|
||||
for (it = m_propMap.begin(); it != m_propMap.end(); ++it)
|
||||
{
|
||||
all.push_back(it->second);
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace gc
|
60
VisualizationModules/LibCore/cvfPropertySet.h
Normal file
60
VisualizationModules/LibCore/cvfPropertySet.h
Normal file
@ -0,0 +1,60 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfObject.h"
|
||||
#include "cvfVariant.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class PropertySet : public Object
|
||||
{
|
||||
public:
|
||||
PropertySet(const String& classType);
|
||||
~PropertySet();
|
||||
|
||||
bool operator==(const PropertySet& rhs) const;
|
||||
|
||||
String classType() const;
|
||||
bool isEmpty() const;
|
||||
|
||||
Variant value(const String& key) const;
|
||||
void setValue(const String& key, const Variant& data);
|
||||
bool contains(const String& key) const;
|
||||
|
||||
std::vector<String> allKeys() const;
|
||||
std::vector<Variant> allValues() const;
|
||||
|
||||
private:
|
||||
String m_classType;
|
||||
std::map<String, Variant> m_propMap;
|
||||
};
|
||||
|
||||
|
||||
} // namespace cvf
|
157
VisualizationModules/LibCore/cvfPropertySetCollection.cpp
Normal file
157
VisualizationModules/LibCore/cvfPropertySetCollection.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfPropertySetCollection.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::PropertySetCollection
|
||||
/// \ingroup Core
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySetCollection::PropertySetCollection()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySetCollection::~PropertySetCollection()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t PropertySetCollection::count() const
|
||||
{
|
||||
return m_propertySets.size();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet* PropertySetCollection::propertySet(size_t index)
|
||||
{
|
||||
CVF_ASSERT(index < m_propertySets.size());
|
||||
return m_propertySets.at(index);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const PropertySet* PropertySetCollection::propertySet(size_t index) const
|
||||
{
|
||||
CVF_ASSERT(index < m_propertySets.size());
|
||||
return m_propertySets.at(index);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PropertySetCollection::addPropertySet(PropertySet* propertySet)
|
||||
{
|
||||
CVF_ASSERT(propertySet);
|
||||
m_propertySets.push_back(propertySet);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t PropertySetCollection::countOfType(const String& classType) const
|
||||
{
|
||||
size_t classCount = 0;
|
||||
const size_t totNumSets = m_propertySets.size();
|
||||
for (size_t i = 0; i < totNumSets; i++)
|
||||
{
|
||||
const PropertySet* ps = m_propertySets.at(i);
|
||||
if (ps->classType() == classType)
|
||||
{
|
||||
classCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return classCount;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet* PropertySetCollection::propertySetOfType(const String& classType, size_t index)
|
||||
{
|
||||
size_t classCount = 0;
|
||||
const size_t totNumSets = m_propertySets.size();
|
||||
for (size_t i = 0; i < totNumSets; i++)
|
||||
{
|
||||
PropertySet* ps = m_propertySets.at(i);
|
||||
if (ps->classType() == classType)
|
||||
{
|
||||
if (classCount == index)
|
||||
{
|
||||
return ps;
|
||||
}
|
||||
|
||||
classCount++;
|
||||
}
|
||||
}
|
||||
|
||||
CVF_FAIL_MSG("Specified index is of of range");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PropertySet* PropertySetCollection::firstPropertySetOfType(const String& classType)
|
||||
{
|
||||
const size_t totNumSets = m_propertySets.size();
|
||||
for (size_t i = 0; i < totNumSets; i++)
|
||||
{
|
||||
PropertySet* ps = m_propertySets.at(i);
|
||||
if (ps->classType() == classType)
|
||||
{
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
} // namespace gc
|
56
VisualizationModules/LibCore/cvfPropertySetCollection.h
Normal file
56
VisualizationModules/LibCore/cvfPropertySetCollection.h
Normal file
@ -0,0 +1,56 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfObject.h"
|
||||
#include "cvfPropertySet.h"
|
||||
#include "cvfCollection.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class PropertySetCollection : public Object
|
||||
{
|
||||
public:
|
||||
PropertySetCollection();
|
||||
~PropertySetCollection();
|
||||
|
||||
size_t count() const;
|
||||
PropertySet* propertySet(size_t index);
|
||||
const PropertySet* propertySet(size_t index) const;
|
||||
void addPropertySet(PropertySet* propertySet);
|
||||
|
||||
size_t countOfType(const String& classType) const;
|
||||
PropertySet* propertySetOfType(const String& classType, size_t index);
|
||||
PropertySet* firstPropertySetOfType(const String& classType);
|
||||
|
||||
private:
|
||||
Collection<PropertySet> m_propertySets;
|
||||
};
|
||||
|
||||
|
||||
} // namespace cvf
|
@ -23,11 +23,12 @@
|
||||
#include "cvfMath.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <limits>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
@ -682,28 +683,14 @@ String String::fromUtf8(const char* utfStr)
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// Returns a null-terminated sequence of wchar_t characters
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const wchar_t* String::ptr() const
|
||||
const wchar_t* String::c_str() const
|
||||
{
|
||||
return m_string.c_str();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
wchar_t* String::ptr()
|
||||
{
|
||||
if (m_string.size() < 1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &(m_string[0]);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert the given number to a string with the specified format
|
||||
///
|
||||
@ -738,16 +725,25 @@ String String::number(float n, char format, int precision)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double String::toDouble(bool* ok) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
double val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = (endPtr != ptr());
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
return val;
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -761,16 +757,16 @@ double String::toDouble(bool* ok) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double String::toDouble(double defaultValue) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
|
||||
if (endPtr == ptr())
|
||||
bool ok = false;
|
||||
double val = toDouble(&ok);
|
||||
if (ok)
|
||||
{
|
||||
val = defaultValue;
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@ -783,16 +779,25 @@ double String::toDouble(double defaultValue) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float String::toFloat(bool* ok) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
float val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = (endPtr != ptr());
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
return static_cast<float>(val);
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -806,16 +811,16 @@ float String::toFloat(bool* ok) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float String::toFloat(float defaultValue) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
|
||||
double val = wcstod(ptr(), &endPtr);
|
||||
|
||||
if (endPtr == ptr())
|
||||
bool ok = false;
|
||||
float val = toFloat(&ok);
|
||||
if (ok)
|
||||
{
|
||||
val = defaultValue;
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return static_cast<float>(val);
|
||||
}
|
||||
|
||||
|
||||
@ -828,16 +833,25 @@ float String::toFloat(float defaultValue) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int String::toInt(bool* ok) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
int val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
long val = wcstol(ptr(), &endPtr, 10);
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = (endPtr != ptr());
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
return static_cast<int>(val);
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -851,16 +865,121 @@ int String::toInt(bool* ok) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int String::toInt(int defaultValue) const
|
||||
{
|
||||
wchar_t* endPtr;
|
||||
|
||||
long val = wcstol(ptr(), &endPtr, 10);
|
||||
|
||||
if (endPtr == ptr())
|
||||
bool ok = false;
|
||||
int val = toInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
val = static_cast<long>(defaultValue);
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert the contents of the string to an unsigned integer value
|
||||
///
|
||||
/// \param ok If not NULL, this will be set to true if conversion is ok, or to false if not
|
||||
///
|
||||
/// \return Returns the unsigned integer value found at the start of the string. 0 if an error occurred.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint String::toUInt(bool* ok) const
|
||||
{
|
||||
// The functions in the standard library does not honor unsignedness but gladly converts a negative integer
|
||||
// to an unsigned integer, so use our int64 implementation instead
|
||||
bool convertOk = false;
|
||||
int64 val = toInt64(&convertOk);
|
||||
if (convertOk)
|
||||
{
|
||||
if (val > std::numeric_limits<uint>::max() || val < 0)
|
||||
{
|
||||
convertOk = false;
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<int>(val);
|
||||
if (ok)
|
||||
{
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
if (convertOk)
|
||||
{
|
||||
return static_cast<uint>(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Convert the contents of the string to an unsigned integer value
|
||||
///
|
||||
/// \param defaultValue The value returned if the conversion failed.
|
||||
///
|
||||
/// \return Returns the value found at the start of the string or defaultValue if the
|
||||
/// conversion was not possible.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint String::toUInt(uint defaultValue) const
|
||||
{
|
||||
bool ok = false;
|
||||
uint val = toUInt(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int64 String::toInt64(bool* ok) const
|
||||
{
|
||||
int64 val = 0;
|
||||
std::wstringstream stream(m_string);
|
||||
stream >> val;
|
||||
|
||||
bool convertOk = !stream.fail();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
*ok = convertOk;
|
||||
}
|
||||
|
||||
if (convertOk)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int64 String::toInt64(int64 defaultValue) const
|
||||
{
|
||||
bool ok = false;
|
||||
int64 val = toInt64(&ok);
|
||||
if (ok)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1012,7 +1131,7 @@ struct ArgInfo
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static ArgInfo findSmallestArgs(const String &s)
|
||||
{
|
||||
const wchar_t* strBegin = s.ptr();
|
||||
const wchar_t* strBegin = s.c_str();
|
||||
const wchar_t* strEnd = strBegin + s.size();
|
||||
|
||||
ArgInfo argInfo;
|
||||
@ -1083,17 +1202,16 @@ static ArgInfo findSmallestArgs(const String &s)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static String replaceArgs(const String &s, const ArgInfo& info, int fieldWidth, const String& arg, const wchar_t& fillChar)
|
||||
{
|
||||
const wchar_t* strBegin = s.ptr();
|
||||
const wchar_t* strBegin = s.c_str();
|
||||
const wchar_t* strEnd = strBegin + s.size();
|
||||
|
||||
unsigned int absFieldWidth = static_cast<unsigned int>(Math::abs(fieldWidth));
|
||||
size_t resultLength = s.size() - info.totalArgLength + info.smallestArgCount*CVF_MAX(absFieldWidth, arg.size());
|
||||
|
||||
String result;
|
||||
result.resize(resultLength);
|
||||
|
||||
wchar_t* resultBuffer = result.ptr();
|
||||
wchar_t* rc = resultBuffer;
|
||||
std::wstring resultString;
|
||||
resultString.resize(resultLength);
|
||||
wchar_t* resultBuffer = &resultString[0];
|
||||
wchar_t* rc = resultBuffer;
|
||||
const wchar_t* c = strBegin;
|
||||
int repl_cnt = 0;
|
||||
|
||||
@ -1143,7 +1261,7 @@ static String replaceArgs(const String &s, const ArgInfo& info, int fieldWidth,
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(rc, arg.ptr(), arg.size()*sizeof(wchar_t));
|
||||
memcpy(rc, arg.c_str(), arg.size()*sizeof(wchar_t));
|
||||
rc += arg.size();
|
||||
|
||||
if (fieldWidth < 0)
|
||||
@ -1168,7 +1286,7 @@ static String replaceArgs(const String &s, const ArgInfo& info, int fieldWidth,
|
||||
|
||||
CVF_ASSERT(rc == resultBuffer + resultLength);
|
||||
|
||||
return result;
|
||||
return String(resultString);
|
||||
}
|
||||
|
||||
|
||||
@ -1389,5 +1507,6 @@ void String::swap(String& other)
|
||||
m_string.swap(other.m_string);
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
|
||||
|
@ -72,6 +72,7 @@ public:
|
||||
String subString(size_t start, size_t length = npos) const;
|
||||
void replace(const String& before, const String& after);
|
||||
|
||||
const wchar_t* c_str() const;
|
||||
CharArray toAscii() const; // Useful when you need a const char* pointer.
|
||||
std::string toStdString() const;
|
||||
std::wstring toStdWString() const;
|
||||
@ -83,9 +84,6 @@ public:
|
||||
size_t size() const;
|
||||
void resize(size_t size);
|
||||
|
||||
const wchar_t* ptr() const;
|
||||
wchar_t* ptr();
|
||||
|
||||
static String number(float n, char format = 'g', int precision = -1);
|
||||
static String number(double n, char format = 'g', int precision = -1);
|
||||
|
||||
@ -95,6 +93,10 @@ public:
|
||||
float toFloat(float defaultValue) const;
|
||||
int toInt(bool* ok = NULL) const;
|
||||
int toInt(int defaultValue) const;
|
||||
uint toUInt(bool* ok = NULL) const;
|
||||
uint toUInt(uint defaultValue) const;
|
||||
int64 toInt64(bool* ok = NULL) const;
|
||||
int64 toInt64(int64 defaultValue) const;
|
||||
|
||||
String arg(const String& a, int fieldWidth = 0, const wchar_t& fillChar = ' ') const;
|
||||
String arg(char a, int fieldWidth = 0, const wchar_t& fillChar = ' ') const;
|
||||
|
@ -40,7 +40,10 @@ private:
|
||||
static void showTraceOutput(String text, bool addNewLine);
|
||||
};
|
||||
|
||||
#define CVF_TRACE_FILELINE Trace::showFileLineNumber(__FILE__, __LINE__, "");
|
||||
#define CVF_TRACE_FILELINE_MSG(message) Trace::showFileLineNumber(__FILE__, __LINE__, message);
|
||||
|
||||
}
|
||||
}// namespace cvf
|
||||
|
||||
|
||||
#define CVF_TRACE_FILELINE cvf::Trace::showFileLineNumber(__FILE__, __LINE__, "");
|
||||
#define CVF_TRACE_FILELINE_MSG(message) cvf::Trace::showFileLineNumber(__FILE__, __LINE__, message);
|
||||
|
||||
|
434
VisualizationModules/LibCore/cvfVariant.cpp
Normal file
434
VisualizationModules/LibCore/cvfVariant.cpp
Normal file
@ -0,0 +1,434 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVariant.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvf::Variant
|
||||
/// \ingroup Core
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant()
|
||||
: m_type(INVALID)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const Variant& other)
|
||||
: m_type(other.m_type),
|
||||
m_data(other.m_data),
|
||||
m_arrayData(other.m_arrayData)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::~Variant()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant& Variant::operator=(Variant rhs)
|
||||
{
|
||||
// Copy-and-swap (copy already done since parameter is passed by value)
|
||||
rhs.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Compares two variants and returns true if they are equal
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Variant::operator==(const Variant& rhs) const
|
||||
{
|
||||
if (m_type != rhs.m_type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case INVALID: return true;
|
||||
case INT: return getInt() == rhs.getInt();
|
||||
case UINT: return getUInt() == rhs.getUInt();
|
||||
case DOUBLE: return getDouble() == rhs.getDouble();
|
||||
case FLOAT: return getFloat() == rhs.getFloat();
|
||||
case BOOL: return getBool() == rhs.getBool();
|
||||
case VEC3D: return getVec3d() == rhs.getVec3d();
|
||||
case COLOR3F: return getColor3f() == rhs.getColor3f();
|
||||
case STRING: return getString() == rhs.getString();
|
||||
case ARRAY: return getArray() == rhs.getArray();
|
||||
}
|
||||
|
||||
CVF_FAIL_MSG("Unhandled variant type");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Type Variant::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Variant::isValid() const
|
||||
{
|
||||
return (m_type != INVALID);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(int val)
|
||||
: m_type(INT)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int Variant::getInt() const
|
||||
{
|
||||
CVF_ASSERT(m_type == INT);
|
||||
CVF_ASSERT(m_data.size() == sizeof(int));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const int* valPtr = reinterpret_cast<const int*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(uint val)
|
||||
: m_type(UINT)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint Variant::getUInt() const
|
||||
{
|
||||
CVF_ASSERT(m_type == UINT);
|
||||
CVF_ASSERT(m_data.size() == sizeof(uint));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const uint* valPtr = reinterpret_cast<const uint*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(double val)
|
||||
: m_type(DOUBLE)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double Variant::getDouble() const
|
||||
{
|
||||
CVF_ASSERT(m_type == DOUBLE);
|
||||
CVF_ASSERT(m_data.size() == sizeof(double));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const double* valPtr = reinterpret_cast<const double*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(float val)
|
||||
: m_type(FLOAT)
|
||||
{
|
||||
assignData(&val, sizeof(val));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
float Variant::getFloat() const
|
||||
{
|
||||
CVF_ASSERT(m_type == FLOAT);
|
||||
CVF_ASSERT(m_data.size() == sizeof(float));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const float* valPtr = reinterpret_cast<const float*>(rawPtr);
|
||||
return *valPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(bool val)
|
||||
: m_type(BOOL)
|
||||
{
|
||||
ubyte tmpVal = val ? 1u : 0;
|
||||
assignData(&tmpVal, 1);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Variant::getBool() const
|
||||
{
|
||||
CVF_ASSERT(m_type == BOOL);
|
||||
CVF_ASSERT(m_data.size() == 1);
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
if (*rawPtr == 1u)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const Vec3d& val)
|
||||
: m_type(VEC3D)
|
||||
{
|
||||
assignData(val.ptr(), 3*sizeof(double));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Vec3d Variant::getVec3d() const
|
||||
{
|
||||
CVF_ASSERT(m_type == VEC3D);
|
||||
CVF_ASSERT(m_data.size() == 3*sizeof(double));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const double* valPtr = reinterpret_cast<const double*>(rawPtr);
|
||||
return Vec3d(valPtr[0], valPtr[1], valPtr[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Vec3d(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const Color3f& val)
|
||||
: m_type(COLOR3F)
|
||||
{
|
||||
assignData(val.ptr(), 3*sizeof(float));
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Color3f Variant::getColor3f() const
|
||||
{
|
||||
CVF_ASSERT(m_type == COLOR3F);
|
||||
CVF_ASSERT(m_data.size() == 3*sizeof(float));
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
if (rawPtr)
|
||||
{
|
||||
const float* valPtr = reinterpret_cast<const float*>(rawPtr);
|
||||
return Color3f(valPtr[0], valPtr[1], valPtr[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color3f(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const String& val)
|
||||
: m_type(STRING)
|
||||
{
|
||||
size_t strSize = val.size();
|
||||
if (strSize > 0)
|
||||
{
|
||||
assignData(val.c_str(), strSize*sizeof(wchar_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const char* val)
|
||||
: m_type(STRING)
|
||||
{
|
||||
String strVal(val);
|
||||
size_t strSize = strVal.size();
|
||||
if (strSize > 0)
|
||||
{
|
||||
assignData(strVal.c_str(), strSize*sizeof(wchar_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Variant::Variant(const std::vector<Variant>& arr)
|
||||
: m_type(ARRAY),
|
||||
m_arrayData(arr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<Variant> Variant::getArray() const
|
||||
{
|
||||
CVF_ASSERT(m_type == ARRAY);
|
||||
return m_arrayData;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String Variant::getString() const
|
||||
{
|
||||
CVF_ASSERT(m_type == STRING);
|
||||
|
||||
// Array must contain at least one wchar_t
|
||||
const ubyte* rawPtr = m_data.empty() ? 0 : &m_data.front();
|
||||
const size_t numWideCars = m_data.size()/sizeof(wchar_t);
|
||||
if (rawPtr && numWideCars > 0)
|
||||
{
|
||||
const wchar_t* valPtr = reinterpret_cast<const wchar_t*>(rawPtr);
|
||||
std::wstring tmpWideString(valPtr, numWideCars);
|
||||
return String(tmpWideString);
|
||||
}
|
||||
else
|
||||
{
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Variant::swap(Variant& other)
|
||||
{
|
||||
std::swap(m_type, other.m_type);
|
||||
m_data.swap(other.m_data);
|
||||
m_arrayData.swap(other.m_arrayData);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Variant::assignData(const void* pointerToData, size_t dataSizeInBytes)
|
||||
{
|
||||
CVF_ASSERT(m_arrayData.size() == 0);
|
||||
|
||||
m_data.assign(reinterpret_cast<const ubyte*>(pointerToData), reinterpret_cast<const ubyte*>(pointerToData) + dataSizeInBytes);
|
||||
CVF_ASSERT(m_data.size() == dataSizeInBytes);
|
||||
}
|
||||
|
||||
|
||||
} // namespace gc
|
98
VisualizationModules/LibCore/cvfVariant.h
Normal file
98
VisualizationModules/LibCore/cvfVariant.h
Normal file
@ -0,0 +1,98 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfVector3.h"
|
||||
#include "cvfColor3.h"
|
||||
#include "cvfString.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class Variant
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
INVALID,
|
||||
INT,
|
||||
UINT,
|
||||
DOUBLE,
|
||||
FLOAT,
|
||||
BOOL,
|
||||
VEC3D,
|
||||
COLOR3F,
|
||||
STRING,
|
||||
ARRAY
|
||||
};
|
||||
|
||||
public:
|
||||
Variant();
|
||||
Variant(const Variant& other);
|
||||
~Variant();
|
||||
|
||||
Variant(int val);
|
||||
Variant(uint val);
|
||||
Variant(double val);
|
||||
Variant(float val);
|
||||
Variant(bool val);
|
||||
Variant(const Vec3d& val);
|
||||
Variant(const Color3f& val);
|
||||
Variant(const String& val);
|
||||
Variant(const char* val);
|
||||
Variant(const std::vector<Variant>& arr);
|
||||
|
||||
Variant& operator=(Variant rhs);
|
||||
|
||||
bool operator==(const Variant& rhs) const;
|
||||
|
||||
Type type() const;
|
||||
bool isValid() const;
|
||||
|
||||
int getInt() const;
|
||||
uint getUInt() const;
|
||||
double getDouble() const;
|
||||
float getFloat() const;
|
||||
bool getBool() const;
|
||||
Vec3d getVec3d() const;
|
||||
Color3f getColor3f() const;
|
||||
cvf::String getString() const;
|
||||
std::vector<Variant> getArray() const;
|
||||
|
||||
void swap(Variant& other);
|
||||
|
||||
private:
|
||||
void assignData(const void* pointerToData, size_t dataSizeInBytes);
|
||||
|
||||
private:
|
||||
Type m_type; // Type of for this variant
|
||||
std::vector<ubyte> m_data; // Data payload for single values
|
||||
std::vector<Variant> m_arrayData;// Data payload when storing an array (of variants)
|
||||
};
|
||||
|
||||
} // namespace cvf
|
@ -388,7 +388,7 @@ const BoundingBox BoundingBox::getTransformed(const Mat4d& matrix) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String BoundingBox::toString() const
|
||||
String BoundingBox::debugString() const
|
||||
{
|
||||
String str = "BoundingBox:";
|
||||
str += " min: x=" + String::number(m_min.x()) + " y=" + String::number(m_min.y()) + " z=" + String::number(m_min.z());
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
void transform(const Mat4d& matrix);
|
||||
const BoundingBox getTransformed(const Mat4d& matrix) const;
|
||||
|
||||
String toString() const;
|
||||
String debugString() const;
|
||||
|
||||
private:
|
||||
Vec3d m_min;
|
||||
|
@ -245,6 +245,62 @@ void GeometryUtils::createDisc(double radius, uint numSlices, GeometryBuilder* b
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Create a disk with a hole in the middle
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void GeometryUtils::createDisc(double outerRadius, double innerRadius, uint numSlices, GeometryBuilder* builder)
|
||||
{
|
||||
CVF_ASSERT(numSlices >= 4);
|
||||
CVF_ASSERT(builder);
|
||||
|
||||
double da = 2*PI_D/numSlices;
|
||||
|
||||
Vec3fArray verts;
|
||||
verts.reserve(2*numSlices);
|
||||
|
||||
Vec3f point = Vec3f::ZERO;
|
||||
|
||||
uint i;
|
||||
for (i = 0; i < numSlices; i++)
|
||||
{
|
||||
// Precompute this one (A = i*da;)
|
||||
double sinA = Math::sin(i*da);
|
||||
double cosA = Math::cos(i*da);
|
||||
|
||||
point.x() = static_cast<float>(-sinA*innerRadius);
|
||||
point.y() = static_cast<float>( cosA*innerRadius);
|
||||
|
||||
verts.add(point);
|
||||
|
||||
point.x() = static_cast<float>(-sinA*outerRadius);
|
||||
point.y() = static_cast<float>( cosA*outerRadius);
|
||||
|
||||
verts.add(point);
|
||||
}
|
||||
|
||||
uint baseNodeIdx = builder->addVertices(verts);
|
||||
|
||||
uint conn[3] = { baseNodeIdx, 0, 0};
|
||||
|
||||
for (i = 0; i < numSlices - 1; ++i)
|
||||
{
|
||||
uint startIdx = baseNodeIdx + 2*i;
|
||||
|
||||
conn[0] = startIdx + 0;
|
||||
conn[1] = startIdx + 3;
|
||||
conn[2] = startIdx + 1;
|
||||
builder->addTriangle(conn[0], conn[1], conn[2]);
|
||||
|
||||
conn[0] = startIdx + 2;
|
||||
conn[1] = startIdx + 3;
|
||||
conn[2] = startIdx + 0;
|
||||
builder->addTriangle(conn[0], conn[1], conn[2]);
|
||||
}
|
||||
|
||||
builder->addTriangle(baseNodeIdx + 0, baseNodeIdx + 1, baseNodeIdx + numSlices*2 - 1);
|
||||
builder->addTriangle(baseNodeIdx + 0, baseNodeIdx + numSlices*2 - 1, baseNodeIdx + numSlices*2 - 2);
|
||||
}
|
||||
|
||||
|
||||
// void GeometryUtils::generatePointsOnCircle(double radius, int numPoints, Vec3fArray* generatedPoints)
|
||||
// {
|
||||
@ -851,7 +907,7 @@ void GeometryUtils::removeUnusedVertices(const UIntValueArray& vertexIndices, UI
|
||||
newToOldMapping->squeeze();
|
||||
}
|
||||
|
||||
bool GeometryUtils::project(const Mat4d& projectionMultViewMatrix, const Vec2ui& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out)
|
||||
bool GeometryUtils::project(const Mat4d& projectionMultViewMatrix, const Vec2i& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out)
|
||||
{
|
||||
CVF_ASSERT(out);
|
||||
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
static void createBox(const Vec3f& centerPos, float extentX, float extentY, float extentZ, GeometryBuilder* builder);
|
||||
|
||||
static void createDisc(double radius, uint numSlices, GeometryBuilder* builder);
|
||||
static void createDisc(double outerRadius, double innerRadius, uint numSlices, GeometryBuilder* builder);
|
||||
|
||||
static void createSphere(double radius, uint numSlices, uint numStacks, GeometryBuilder* builder);
|
||||
|
||||
@ -57,7 +58,7 @@ public:
|
||||
|
||||
static void removeUnusedVertices(const UIntValueArray& vertexIndices, UIntArray* newVertexIndices, UIntArray* newToOldMapping, uint maxVertexCount);
|
||||
|
||||
static bool project(const Mat4d& projectionMultViewMatrix, const Vec2ui& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out);
|
||||
static bool project(const Mat4d& projectionMultViewMatrix, const Vec2i& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -39,9 +39,14 @@ namespace cvf {
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Ray::Ray()
|
||||
: m_origin(Vec3d::ZERO),
|
||||
m_direction(-Vec3d::Z_AXIS),
|
||||
m_minDistance(cvf::UNDEFINED_DOUBLE),
|
||||
m_maxDistance(cvf::UNDEFINED_DOUBLE),
|
||||
m_minDistanceSquared(cvf::UNDEFINED_DOUBLE),
|
||||
m_maxDistanceSquared(cvf::UNDEFINED_DOUBLE),
|
||||
m_distanceLimitedRay(false)
|
||||
{
|
||||
m_origin = Vec3d::ZERO;
|
||||
m_direction = -Vec3d::Z_AXIS;
|
||||
}
|
||||
|
||||
|
||||
@ -52,6 +57,11 @@ Ray::Ray(const Ray& other) : Object()
|
||||
{
|
||||
m_origin = other.origin();
|
||||
m_direction = other.direction();
|
||||
m_minDistance = other.m_minDistance;
|
||||
m_maxDistance = other.m_maxDistance;
|
||||
m_minDistanceSquared = other.m_minDistanceSquared;
|
||||
m_maxDistanceSquared = other.m_maxDistanceSquared;
|
||||
m_distanceLimitedRay = other.m_distanceLimitedRay;
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +70,6 @@ Ray::Ray(const Ray& other) : Object()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Ray::~Ray()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -162,6 +171,22 @@ bool Ray::triangleIntersect(const Vec3d& v1, const Vec3d& v2, const Vec3d& v3, V
|
||||
}
|
||||
}
|
||||
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(fp);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = fp;
|
||||
@ -211,6 +236,22 @@ bool Ray::quadIntersect(const Vec3d& v1, const Vec3d& v2, const Vec3d& v3, const
|
||||
}
|
||||
}
|
||||
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(fp);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = fp;
|
||||
@ -312,6 +353,22 @@ bool Ray::boxIntersect(const BoundingBox& box, Vec3d* intersectionPoint) const
|
||||
}
|
||||
}
|
||||
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(hitPoint);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = hitPoint;
|
||||
@ -348,6 +405,22 @@ bool Ray::planeIntersect(const Plane& plane, Vec3d* intersectionPoint) const
|
||||
double t = v0/vd;
|
||||
if (t >= 0)
|
||||
{
|
||||
// Distance filtering
|
||||
if (m_distanceLimitedRay)
|
||||
{
|
||||
double distanceSquared = origin().pointDistanceSquared(m_origin + t*m_direction);
|
||||
|
||||
if (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared < m_minDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD && distanceSquared > m_maxDistanceSquared)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPoint)
|
||||
{
|
||||
*intersectionPoint = m_origin + t*m_direction;
|
||||
@ -364,15 +437,78 @@ bool Ray::planeIntersect(const Plane& plane, Vec3d* intersectionPoint) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String Ray::toString() const
|
||||
String Ray::debugString() const
|
||||
{
|
||||
String str = "Ray: ";
|
||||
str += " origin: x=" + String::number(m_origin.x()) + " y=" + String::number(m_origin.y()) + " z=" + String::number(m_origin.z());
|
||||
str += " direction: x=" + String::number(m_direction.x()) + " y=" + String::number(m_direction.y()) + " z=" + String::number(m_direction.z());
|
||||
str += " minDist: " + String::number(m_minDistance);
|
||||
str += " maxDist: " + String::number(m_maxDistance);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set the minimum distance (from the origin) that the ray will hit.
|
||||
///
|
||||
/// Useful for limiting the ray when picking on models with clipping planes.
|
||||
/// Set to tsv::UNDEFINED_DOUBLE
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Ray::setMinimumDistance(double distance)
|
||||
{
|
||||
m_minDistance = distance;
|
||||
|
||||
if (m_minDistance >= 0 && m_minDistance < cvf::UNDEFINED_DOUBLE_THRESHOLD)
|
||||
{
|
||||
m_minDistanceSquared = m_minDistance*m_minDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_minDistanceSquared = cvf::UNDEFINED_DOUBLE;
|
||||
}
|
||||
|
||||
m_distanceLimitedRay = (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD) || (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set the maximum distance (from the origin) that the ray will hit.
|
||||
///
|
||||
/// Useful for limiting the ray when picking on models with clipping planes
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Ray::setMaximumDistance(double distance)
|
||||
{
|
||||
m_maxDistance = distance;
|
||||
|
||||
if (m_maxDistance >= 0 && m_maxDistance < cvf::UNDEFINED_DOUBLE_THRESHOLD)
|
||||
{
|
||||
m_maxDistanceSquared = m_maxDistance*m_maxDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_maxDistanceSquared = cvf::UNDEFINED_DOUBLE;
|
||||
}
|
||||
|
||||
m_distanceLimitedRay = (m_minDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD) || (m_maxDistanceSquared < cvf::UNDEFINED_DOUBLE_THRESHOLD);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Minimum distance (from the origin) that the ray will hit.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double Ray::minimumDistance() const
|
||||
{
|
||||
return m_minDistance;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Maximum distance (from the origin) that the ray will hit
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double Ray::maximumDistance() const
|
||||
{
|
||||
return m_maxDistance;
|
||||
}
|
||||
|
||||
} // namespace cvf
|
||||
|
@ -47,6 +47,11 @@ public:
|
||||
void setDirection(const Vec3d& dir);
|
||||
const Vec3d& direction() const;
|
||||
|
||||
void setMinimumDistance(double distance);
|
||||
double minimumDistance() const;
|
||||
void setMaximumDistance(double distance);
|
||||
double maximumDistance() const;
|
||||
|
||||
void transform(const Mat4d& matrix);
|
||||
const Ray getTransformed(const Mat4d& matrix) const;
|
||||
|
||||
@ -55,11 +60,16 @@ public:
|
||||
bool boxIntersect(const BoundingBox& box, Vec3d* intersectionPoint = NULL) const;
|
||||
bool planeIntersect(const Plane& plane, Vec3d* intersectionPoint = NULL) const;
|
||||
|
||||
String toString() const;
|
||||
String debugString() const;
|
||||
|
||||
private:
|
||||
Vec3d m_origin; ///< Starting point of ray
|
||||
Vec3d m_direction; ///< Vector specifying ray direction
|
||||
Vec3d m_origin; ///< Starting point of ray
|
||||
Vec3d m_direction; ///< Vector specifying ray direction
|
||||
double m_minDistance; ///< Minimum distance for a hit
|
||||
double m_maxDistance; ///< Maximum distance for a hit
|
||||
double m_minDistanceSquared;
|
||||
double m_maxDistanceSquared;
|
||||
bool m_distanceLimitedRay;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -48,13 +48,13 @@ QString Utils::toQString(const cvf::String& ceeString)
|
||||
|
||||
if (sizeof(wchar_t) == 2)
|
||||
{
|
||||
const unsigned short* strPtr = reinterpret_cast<const unsigned short*>(ceeString.ptr());
|
||||
const unsigned short* strPtr = reinterpret_cast<const unsigned short*>(ceeString.c_str());
|
||||
|
||||
return QString::fromUtf16(strPtr);
|
||||
}
|
||||
else if (sizeof(wchar_t) == 4)
|
||||
{
|
||||
const unsigned int* strPtr = reinterpret_cast<const unsigned int*>(ceeString.ptr());
|
||||
const unsigned int* strPtr = reinterpret_cast<const unsigned int*>(ceeString.c_str());
|
||||
|
||||
return QString::fromUcs4(strPtr);
|
||||
}
|
||||
|
@ -489,8 +489,11 @@ double Camera::aspectRatio() const
|
||||
/// This method calls Viewport::set() and then updates the projection matrix, as this is depending
|
||||
/// on the viewport dimensions.
|
||||
/// This method is usually used as a response to a Resize message from the window system
|
||||
///
|
||||
/// The window coordinates (x,y) are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Camera::setViewport(uint x, uint y, uint width, uint height)
|
||||
void Camera::setViewport(int x, int y, uint width, uint height)
|
||||
{
|
||||
CVF_ASSERT(m_viewport.notNull());
|
||||
m_viewport->set(x, y, width, height);
|
||||
@ -528,22 +531,19 @@ const Viewport* Camera::viewport() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Create a Ray from window coordinates
|
||||
///
|
||||
/// The coordinates (winCoordX & winCoordY) are assumed to be in the window coordinate system
|
||||
/// where <0,0> if in the top left corner.
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
ref<Ray> Camera::rayFromWinCoord(int winCoordX, int winCoordY) const
|
||||
ref<Ray> Camera::rayFromWindowCoordinates(int x, int y) const
|
||||
{
|
||||
// Unproject works in OpenGL coord system with (0,0) in lower left corner, so flip the y-coordinate
|
||||
winCoordY = static_cast<int>(m_viewport->height()) - winCoordY;
|
||||
|
||||
Vec3d coord0(0, 0, 0);
|
||||
if (!unproject(Vec3d(static_cast<double>(winCoordX), static_cast<double>(winCoordY), 0), &coord0))
|
||||
if (!unproject(Vec3d(static_cast<double>(x), static_cast<double>(y), 0), &coord0))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Vec3d coord1(0, 0, 0);
|
||||
if (!unproject(Vec3d(static_cast<double>(winCoordX), static_cast<double>(winCoordY), 1), &coord1))
|
||||
if (!unproject(Vec3d(static_cast<double>(x), static_cast<double>(y), 1), &coord1))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@ -563,22 +563,19 @@ ref<Ray> Camera::rayFromWinCoord(int winCoordX, int winCoordY) const
|
||||
///
|
||||
/// The plane will be constructed so that the specified line lies in the plane, and the plane
|
||||
/// normal will be pointing left when moving along the line from start to end.
|
||||
/// The coordinates (winCoordStart & winCoordEnd) are assumed to be in the window coordinate system
|
||||
/// where <0,0> is in the top left corner.
|
||||
///
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
ref<Plane> Camera::planeFromLineWinCoord(Vec2i winCoordStart, Vec2i winCoordEnd) const
|
||||
ref<Plane> Camera::planeFromLineWindowCoordinates(Vec2i coordStart, Vec2i coordEnd) const
|
||||
{
|
||||
// Unproject works in OpenGL coord system with (0,0) in lower left corner, so flip the y-coordinates
|
||||
winCoordStart.y() = static_cast<int>(m_viewport->height()) - winCoordStart.y();
|
||||
winCoordEnd.y() = static_cast<int>(m_viewport->height()) - winCoordEnd.y();
|
||||
|
||||
Vec3d s0(0, 0, 0);
|
||||
Vec3d e0(0, 0, 0);
|
||||
Vec3d e1(0, 0, 0);
|
||||
bool unprojOk = true;
|
||||
unprojOk &= unproject(Vec3d(winCoordStart.x(), winCoordStart.y(), 0), &s0);
|
||||
unprojOk &= unproject(Vec3d(winCoordEnd.x(), winCoordEnd.y(), 0), &e0);
|
||||
unprojOk &= unproject(Vec3d(winCoordEnd.x(), winCoordEnd.y(), 1), &e1);
|
||||
unprojOk &= unproject(Vec3d(coordStart.x(), coordStart.y(), 0), &s0);
|
||||
unprojOk &= unproject(Vec3d(coordEnd.x(), coordEnd.y(), 0), &e0);
|
||||
unprojOk &= unproject(Vec3d(coordEnd.x(), coordEnd.y(), 1), &e1);
|
||||
if (!unprojOk)
|
||||
{
|
||||
return NULL;
|
||||
@ -770,7 +767,7 @@ bool Camera::unproject(const Vec3d& coord, Vec3d* out) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool Camera::project(const Vec3d& point, Vec3d* out) const
|
||||
{
|
||||
return GeometryUtils::project(m_cachedProjectionMultViewMatrix, Vec2ui(m_viewport->x(), m_viewport->y()), Vec2ui(m_viewport->width(), m_viewport->height()), point, out);
|
||||
return GeometryUtils::project(m_cachedProjectionMultViewMatrix, Vec2i(m_viewport->x(), m_viewport->y()), Vec2ui(m_viewport->width(), m_viewport->height()), point, out);
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,12 +81,12 @@ public:
|
||||
double frontPlanePixelHeight() const;
|
||||
double distanceWhereObjectProjectsToPixelExtent(double objectExtentWorld, double objectExtentPixels) const;
|
||||
|
||||
void setViewport(uint x, uint y, uint width, uint height);
|
||||
void setViewport(int x, int y, uint width, uint height);
|
||||
Viewport* viewport();
|
||||
const Viewport* viewport() const;
|
||||
|
||||
ref<Ray> rayFromWinCoord(int winCoordX, int winCoordY) const;
|
||||
ref<Plane> planeFromLineWinCoord(Vec2i winCoordStart, Vec2i winCoordEnd) const;
|
||||
ref<Ray> rayFromWindowCoordinates(int x, int y) const;
|
||||
ref<Plane> planeFromLineWindowCoordinates(Vec2i coordStart, Vec2i coordEnd) const;
|
||||
bool unproject(const Vec3d& coord, Vec3d* out) const;
|
||||
bool project(const Vec3d& point, Vec3d* out) const;
|
||||
|
||||
|
@ -44,7 +44,7 @@ MatrixState::MatrixState(const Camera& camera)
|
||||
m_modelMatrix(),
|
||||
m_modelMatrixIsSet(false),
|
||||
m_viewProjectionMatrix(m_projectionMatrix*m_viewMatrix),
|
||||
m_viewportPosition(static_cast<uint>(camera.viewport()->x()), static_cast<uint>(camera.viewport()->y())),
|
||||
m_viewportPosition(camera.viewport()->x(), camera.viewport()->y()),
|
||||
m_viewportSize(static_cast<uint>(camera.viewport()->width()), static_cast<uint>(camera.viewport()->height())),
|
||||
m_pixelHeightAtUnitDistance(0.0f),
|
||||
m_versionTick(1)
|
||||
@ -59,7 +59,7 @@ MatrixState::MatrixState(const Camera& camera)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
MatrixState::MatrixState(const Vec2ui& viewportPosition, const Vec2ui& viewportSize, const Mat4d& projectionMatrix, const Mat4d& viewMatrix)
|
||||
MatrixState::MatrixState(const Vec2i& viewportPosition, const Vec2ui& viewportSize, const Mat4d& projectionMatrix, const Mat4d& viewMatrix)
|
||||
: m_projectionMatrix(projectionMatrix),
|
||||
m_viewMatrix(viewMatrix),
|
||||
m_modelMatrix(),
|
||||
@ -295,7 +295,7 @@ float MatrixState::pixelHeightAtUnitDistance() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Vec2ui MatrixState::viewportPosition() const
|
||||
Vec2i MatrixState::viewportPosition() const
|
||||
{
|
||||
return m_viewportPosition;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class MatrixState
|
||||
{
|
||||
public:
|
||||
MatrixState(const Camera& camera);
|
||||
MatrixState(const Vec2ui& viewportPosition, const Vec2ui& viewportSize, const Mat4d& projectionMatrix, const Mat4d& viewMatrix);
|
||||
MatrixState(const Vec2i& viewportPosition, const Vec2ui& viewportSize, const Mat4d& projectionMatrix, const Mat4d& viewMatrix);
|
||||
|
||||
void setViewMatrix(const Mat4d& viewMatrix);
|
||||
|
||||
@ -56,7 +56,7 @@ public:
|
||||
Mat3f normalMatrix() const;
|
||||
|
||||
float pixelHeightAtUnitDistance() const;
|
||||
Vec2ui viewportPosition() const;
|
||||
Vec2i viewportPosition() const;
|
||||
Vec2ui viewportSize() const;
|
||||
|
||||
uint versionTick() const;
|
||||
@ -71,7 +71,7 @@ private:
|
||||
bool m_modelMatrixIsSet; // Set to true when a model matrix is set, false when no model matrix is currently set
|
||||
Mat4f m_viewProjectionMatrix; // Combined view matrix and projection matrix
|
||||
|
||||
Vec2ui m_viewportPosition; // Position of the viewport
|
||||
Vec2i m_viewportPosition; // Position of the viewport
|
||||
Vec2ui m_viewportSize; // Size of the viewport
|
||||
float m_pixelHeightAtUnitDistance;// Height of a pixel at unit distance (distance of 1.0 from camera) in world system. For perspective projections this value must be multiplied by the distance to the point in question
|
||||
|
||||
|
@ -27,6 +27,14 @@
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4668)
|
||||
#include "glew/GL/wglew.h"
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
|
||||
namespace cvf {
|
||||
|
||||
|
||||
@ -46,7 +54,8 @@ namespace cvf {
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
OpenGLContextGroup::OpenGLContextGroup()
|
||||
: m_isInitialized(false),
|
||||
m_glewContextStruct(NULL)
|
||||
m_glewContextStruct(NULL),
|
||||
m_wglewContextStruct(NULL)
|
||||
{
|
||||
m_resourceManager = new OpenGLResourceManager;
|
||||
m_logger = new Logger;
|
||||
@ -116,6 +125,14 @@ bool OpenGLContextGroup::initializeContextGroup(OpenGLContext* currentContext)
|
||||
}
|
||||
|
||||
configureCapablititesFromGLEW(currentContext);
|
||||
|
||||
#ifdef WIN32
|
||||
if (!initializeWGLEW(currentContext))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
m_isInitialized = true;
|
||||
@ -138,8 +155,13 @@ void OpenGLContextGroup::uninitializeContextGroup()
|
||||
|
||||
#ifdef CVF_USE_GLEW
|
||||
delete m_glewContextStruct;
|
||||
|
||||
#ifdef WIN32
|
||||
delete m_wglewContextStruct;
|
||||
#endif
|
||||
#endif
|
||||
m_glewContextStruct = NULL;
|
||||
m_wglewContextStruct = NULL;
|
||||
|
||||
m_isInitialized = false;
|
||||
}
|
||||
@ -231,6 +253,45 @@ bool OpenGLContextGroup::initializeGLEW(OpenGLContext* currentContext)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Initializes GLEW for this context group
|
||||
///
|
||||
/// \warning The context passed in \a currentContext must be current!
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool OpenGLContextGroup::initializeWGLEW(OpenGLContext* currentContext)
|
||||
{
|
||||
CVF_ASSERT(currentContext);
|
||||
CVF_ASSERT(m_wglewContextStruct == NULL);
|
||||
|
||||
#if defined(CVF_USE_GLEW) && defined(WIN32)
|
||||
|
||||
// Since we're sometimes (when using Core OpenGL) seeing some OGL errors from GLEW, check before and after call to help find them
|
||||
CVF_CHECK_OGL(currentContext);
|
||||
|
||||
// Must allocate memory for struct first since glewInit() call below will try and retrieve it
|
||||
WGLEWContextStruct* theContextStruct = new WGLEWContextStruct;
|
||||
memset(theContextStruct, 0, sizeof(WGLEWContextStruct));
|
||||
GLenum err = wglewContextInit(theContextStruct);
|
||||
if (err != GLEW_OK)
|
||||
{
|
||||
delete theContextStruct;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_wglewContextStruct = theContextStruct;
|
||||
|
||||
CVF_CHECK_OGL(currentContext);
|
||||
|
||||
#else
|
||||
|
||||
CVF_FAIL_MSG("Not implemented");
|
||||
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Configures the capabilities of this context group by querying GLEW
|
||||
///
|
||||
@ -374,5 +435,24 @@ GLEWContextStruct* OpenGLContextGroup::glewContextStruct()
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
WGLEWContextStruct* OpenGLContextGroup::wglewContextStruct()
|
||||
{
|
||||
#if defined(CVF_USE_GLEW) && defined(WIN32)
|
||||
|
||||
CVF_TIGHT_ASSERT(this);
|
||||
CVF_TIGHT_ASSERT(m_wglewContextStruct);
|
||||
return m_wglewContextStruct;
|
||||
|
||||
#else
|
||||
|
||||
CVF_FAIL_MSG("Not implemented");
|
||||
return NULL;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvf
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "cvfLogger.h"
|
||||
|
||||
struct GLEWContextStruct;
|
||||
struct WGLEWContextStruct;
|
||||
|
||||
namespace cvf {
|
||||
|
||||
@ -53,12 +54,14 @@ public:
|
||||
|
||||
OpenGLCapabilities* capabilities();
|
||||
GLEWContextStruct* glewContextStruct();
|
||||
WGLEWContextStruct* wglewContextStruct();
|
||||
|
||||
private:
|
||||
bool initializeContextGroup(OpenGLContext* currentContext);
|
||||
void uninitializeContextGroup();
|
||||
void contextAboutToBeShutdown(OpenGLContext* contextToShutdown);
|
||||
bool initializeGLEW(OpenGLContext* currentContext);
|
||||
bool initializeWGLEW(OpenGLContext* currentContext);
|
||||
void configureCapablititesFromGLEW(OpenGLContext* currentContext);
|
||||
void addContext(OpenGLContext* contextToAdd);
|
||||
|
||||
@ -69,6 +72,7 @@ private:
|
||||
ref<Logger> m_logger;
|
||||
ref<OpenGLCapabilities> m_capabilities; // Capabilities of the contexts in this group context
|
||||
GLEWContextStruct* m_glewContextStruct; // Pointer to the GLEW context struct
|
||||
WGLEWContextStruct* m_wglewContextStruct; // Pointer to the GLEW context struct
|
||||
|
||||
friend class OpenGLContext;
|
||||
};
|
||||
@ -76,5 +80,3 @@ private:
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -140,7 +140,7 @@ void OverlayAxisCross::setSize(const Vec2ui& size)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Hardware rendering using shader programs
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayAxisCross::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayAxisCross::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
Mat4d viewMatrix = m_camera->viewMatrix();
|
||||
render(oglContext, position, size, false, viewMatrix);
|
||||
@ -150,7 +150,7 @@ void OverlayAxisCross::render(OpenGLContext* oglContext, const Vec2ui& position,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Software rendering
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayAxisCross::renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayAxisCross::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
Mat4d viewMatrix = m_camera->viewMatrix();
|
||||
render(oglContext, position, size, true, viewMatrix);
|
||||
@ -160,7 +160,7 @@ void OverlayAxisCross::renderSoftware(OpenGLContext* oglContext, const Vec2ui& p
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set up camera/viewport and render
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayAxisCross::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix)
|
||||
void OverlayAxisCross::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix)
|
||||
{
|
||||
if (size.x() <= 0 || size.y() <= 0)
|
||||
{
|
||||
|
@ -49,8 +49,8 @@ public:
|
||||
virtual Vec2ui maximumSize();
|
||||
virtual Vec2ui minimumSize();
|
||||
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
|
||||
void setSize(const Vec2ui& size);
|
||||
|
||||
@ -58,7 +58,7 @@ public:
|
||||
void setAxisLabelsColor(const Color3f& color);
|
||||
|
||||
private:
|
||||
void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix);
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix);
|
||||
void createAxisGeometry(bool software);
|
||||
void renderAxis(OpenGLContext* oglContext, const MatrixState& matrixState);
|
||||
void renderAxisImmediateMode(OpenGLContext* oglContext, const MatrixState& matrixState);
|
||||
|
@ -198,7 +198,7 @@ String OverlayColorLegend::title() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Hardware rendering using shader programs
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayColorLegend::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayColorLegend::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, false);
|
||||
}
|
||||
@ -207,7 +207,7 @@ void OverlayColorLegend::render(OpenGLContext* oglContext, const Vec2ui& positio
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Software rendering using software
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayColorLegend::renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayColorLegend::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, true);
|
||||
}
|
||||
@ -216,21 +216,21 @@ void OverlayColorLegend::renderSoftware(OpenGLContext* oglContext, const Vec2ui&
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool OverlayColorLegend::pick(uint oglXCoord, uint oglYCoord, const Vec2ui& position, const Vec2ui& size)
|
||||
bool OverlayColorLegend::pick(int x, int y, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
Rectui oglRect(position, size.x(), size.y());
|
||||
Recti oglRect(position, static_cast<int>(size.x()), static_cast<int>(size.y()));
|
||||
|
||||
OverlayColorLegendLayoutInfo layoutInViewPortCoords(oglRect.min(), Vec2ui(oglRect.width(), oglRect.height()));
|
||||
OverlayColorLegendLayoutInfo layoutInViewPortCoords(oglRect.min(), Vec2ui(static_cast<uint>(oglRect.width()), static_cast<uint>(oglRect.height())));
|
||||
layoutInfo(&layoutInViewPortCoords);
|
||||
|
||||
Vec2ui legendBarOrigin = oglRect.min();
|
||||
Vec2i legendBarOrigin = oglRect.min();
|
||||
legendBarOrigin.x() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().x());
|
||||
legendBarOrigin.y() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().y());
|
||||
|
||||
Rectui legendBarRect = Rectui(legendBarOrigin, static_cast<uint>(layoutInViewPortCoords.legendRect.width()), static_cast<uint>(layoutInViewPortCoords.legendRect.height()));
|
||||
Recti legendBarRect = Recti(legendBarOrigin, static_cast<int>(layoutInViewPortCoords.legendRect.width()), static_cast<int>(layoutInViewPortCoords.legendRect.height()));
|
||||
|
||||
if ((oglXCoord > legendBarRect.min().x()) && (oglXCoord < legendBarRect.max().x()) &&
|
||||
(oglYCoord > legendBarRect.min().y()) && (oglYCoord < legendBarRect.max().y()))
|
||||
if ((x > legendBarRect.min().x()) && (x < legendBarRect.max().x()) &&
|
||||
(y > legendBarRect.min().y()) && (y < legendBarRect.max().y()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -242,7 +242,7 @@ bool OverlayColorLegend::pick(uint oglXCoord, uint oglYCoord, const Vec2ui& posi
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set up camera/viewport and render
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayColorLegend::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software)
|
||||
void OverlayColorLegend::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software)
|
||||
{
|
||||
if (size.x() <= 0 || size.y() <= 0)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ class TextDrawer;
|
||||
//==================================================================================================
|
||||
struct OverlayColorLegendLayoutInfo
|
||||
{
|
||||
OverlayColorLegendLayoutInfo(const Vec2ui& pos, const Vec2ui& setSize)
|
||||
OverlayColorLegendLayoutInfo(const Vec2i& pos, const Vec2ui& setSize)
|
||||
{
|
||||
position = pos;
|
||||
size = setSize;
|
||||
@ -56,7 +56,7 @@ struct OverlayColorLegendLayoutInfo
|
||||
|
||||
ref<DoubleArray> tickPixelPos;
|
||||
|
||||
Vec2ui position;
|
||||
Vec2i position;
|
||||
Vec2ui size;
|
||||
};
|
||||
|
||||
@ -76,9 +76,9 @@ public:
|
||||
virtual Vec2ui maximumSize();
|
||||
virtual Vec2ui minimumSize();
|
||||
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual bool pick(uint oglXCoord, uint oglYCoord, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual bool pick(int x, int y, const Vec2i& position, const Vec2ui& size);
|
||||
|
||||
void configureLevels(const Color3ubArray& levelColors, const DoubleArray& tickValues);
|
||||
|
||||
@ -96,7 +96,7 @@ public:
|
||||
String title() const;
|
||||
|
||||
protected:
|
||||
void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software);
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software);
|
||||
virtual void renderLegend(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout, const MatrixState& matrixState);
|
||||
virtual void renderLegendImmediateMode(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout);
|
||||
virtual void setupTextDrawer(TextDrawer* textDrawer, OverlayColorLegendLayoutInfo* layout);
|
||||
|
@ -111,7 +111,7 @@ cvf::Vec2ui OverlayImage::minimumSize()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Render using Shaders
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayImage::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayImage::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, false);
|
||||
}
|
||||
@ -120,7 +120,7 @@ void OverlayImage::render(OpenGLContext* oglContext, const Vec2ui& position, con
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Render using Fixed Function
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayImage::renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayImage::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, true);
|
||||
}
|
||||
@ -129,7 +129,7 @@ void OverlayImage::renderSoftware(OpenGLContext* oglContext, const Vec2ui& posit
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayImage::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software)
|
||||
void OverlayImage::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software)
|
||||
{
|
||||
CVF_CALLSITE_OPENGL(oglContext);
|
||||
|
||||
@ -262,6 +262,12 @@ void OverlayImage::render(OpenGLContext* oglContext, const Vec2ui& position, con
|
||||
RenderStateBlending blend;
|
||||
blend.applyOpenGL(oglContext);
|
||||
}
|
||||
|
||||
if (!software)
|
||||
{
|
||||
glDisableVertexAttribArray(ShaderProgram::VERTEX);
|
||||
glDisableVertexAttribArray(ShaderProgram::TEX_COORD_2F_0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,8 +52,8 @@ public:
|
||||
virtual Vec2ui maximumSize();
|
||||
virtual Vec2ui minimumSize();
|
||||
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
|
||||
void setImage(TextureImage* image);
|
||||
void setPixelSize(const Vec2ui& size);
|
||||
@ -63,7 +63,7 @@ public:
|
||||
const TextureImage* image() const;
|
||||
|
||||
private:
|
||||
void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software);
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software);
|
||||
|
||||
private:
|
||||
Vec2ui m_size;
|
||||
|
@ -46,12 +46,12 @@ namespace cvf {
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Do hit test on the overlay item. Base class only does a check
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool OverlayItem::pick(uint oglXCoord, uint oglYCoord, const Vec2ui& position, const Vec2ui& size)
|
||||
bool OverlayItem::pick(int x, int y, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
Rectui oglRect(position, size.x(), size.y());
|
||||
Recti oglRect(position, static_cast<int>(size.x()), static_cast<int>(size.y()));
|
||||
|
||||
if ((oglXCoord > oglRect.min().x()) && (oglXCoord < oglRect.max().x()) &&
|
||||
(oglYCoord > oglRect.min().y()) && (oglYCoord < oglRect.max().y()))
|
||||
if ((x > oglRect.min().x()) && (x < oglRect.max().x()) &&
|
||||
(y > oglRect.min().y()) && (y < oglRect.max().y()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ public:
|
||||
virtual Vec2ui maximumSize() = 0; // In Pixels
|
||||
virtual Vec2ui minimumSize() = 0; // In Pixels
|
||||
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size) = 0;
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size) = 0;
|
||||
virtual bool pick(uint oglXCoord, uint oglYCoord, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) = 0;
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) = 0;
|
||||
virtual bool pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ void OverlayNavigationCube::setSize(const Vec2ui& size)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Hardware rendering using shader programs
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayNavigationCube::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayNavigationCube::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
Mat4d viewMatrix = m_camera->viewMatrix();
|
||||
render(oglContext, position, size, false, viewMatrix);
|
||||
@ -155,7 +155,7 @@ void OverlayNavigationCube::render(OpenGLContext* oglContext, const Vec2ui& posi
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Software rendering
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayNavigationCube::renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayNavigationCube::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
Mat4d viewMatrix = m_camera->viewMatrix();
|
||||
render(oglContext, position, size, true, viewMatrix);
|
||||
@ -165,7 +165,7 @@ void OverlayNavigationCube::renderSoftware(OpenGLContext* oglContext, const Vec2
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set up camera/viewport and render
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayNavigationCube::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix)
|
||||
void OverlayNavigationCube::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix)
|
||||
{
|
||||
if (size.x() <= 0 || size.y() <= 0)
|
||||
{
|
||||
|
@ -119,8 +119,8 @@ public:
|
||||
virtual Vec2ui maximumSize();
|
||||
virtual Vec2ui minimumSize();
|
||||
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
|
||||
void setSize(const Vec2ui& size);
|
||||
void updateHighlight(int winCoordX, int winCoordY);
|
||||
@ -130,7 +130,7 @@ public:
|
||||
void setAxisLabelsColor(const Color3f& color);
|
||||
|
||||
private:
|
||||
void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix);
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software, const Mat4d& viewMatrix);
|
||||
void createAxisGeometry(bool software);
|
||||
void renderAxis(OpenGLContext* oglContext, const MatrixState& matrixState);
|
||||
void renderAxisImmediateMode(OpenGLContext* oglContext, const MatrixState& matrixState);
|
||||
|
@ -198,7 +198,7 @@ String OverlayScalarMapperLegend::title() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Hardware rendering using shader programs
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScalarMapperLegend::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayScalarMapperLegend::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, false);
|
||||
}
|
||||
@ -207,7 +207,7 @@ void OverlayScalarMapperLegend::render(OpenGLContext* oglContext, const Vec2ui&
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Software rendering using software
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScalarMapperLegend::renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayScalarMapperLegend::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, true);
|
||||
}
|
||||
@ -216,18 +216,18 @@ void OverlayScalarMapperLegend::renderSoftware(OpenGLContext* oglContext, const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool OverlayScalarMapperLegend::pick(uint oglXCoord, uint oglYCoord, const Vec2ui& position, const Vec2ui& size)
|
||||
bool OverlayScalarMapperLegend::pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
Rectui oglRect(position, size.x(), size.y());
|
||||
Recti oglRect(position, size.x(), size.y());
|
||||
|
||||
OverlayColorLegendLayoutInfo layoutInViewPortCoords(oglRect.min(), Vec2ui(oglRect.width(), oglRect.height()));
|
||||
layoutInfo(&layoutInViewPortCoords);
|
||||
|
||||
Vec2ui legendBarOrigin = oglRect.min();
|
||||
Vec2i legendBarOrigin = oglRect.min();
|
||||
legendBarOrigin.x() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().x());
|
||||
legendBarOrigin.y() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().y());
|
||||
|
||||
Rectui legendBarRect = Rectui(legendBarOrigin, static_cast<uint>(layoutInViewPortCoords.legendRect.width()), static_cast<uint>(layoutInViewPortCoords.legendRect.height()));
|
||||
Recti legendBarRect = Recti(legendBarOrigin, static_cast<uint>(layoutInViewPortCoords.legendRect.width()), static_cast<uint>(layoutInViewPortCoords.legendRect.height()));
|
||||
|
||||
if ((oglXCoord > legendBarRect.min().x()) && (oglXCoord < legendBarRect.max().x()) &&
|
||||
(oglYCoord > legendBarRect.min().y()) && (oglYCoord < legendBarRect.max().y()))
|
||||
@ -242,7 +242,7 @@ bool OverlayScalarMapperLegend::pick(uint oglXCoord, uint oglYCoord, const Vec2u
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set up camera/viewport and render
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScalarMapperLegend::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software)
|
||||
void OverlayScalarMapperLegend::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software)
|
||||
{
|
||||
if (size.x() <= 0 || size.y() <= 0)
|
||||
{
|
||||
|
@ -50,9 +50,9 @@ public:
|
||||
virtual Vec2ui minimumSize();
|
||||
void setScalarMapper(const ScalarMapper* scalarMapper);
|
||||
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual bool pick(uint oglXCoord, uint oglYCoord, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual bool pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size);
|
||||
|
||||
|
||||
void setSizeHint(const Vec2ui& size);
|
||||
@ -77,7 +77,7 @@ protected:
|
||||
//==================================================================================================
|
||||
struct OverlayColorLegendLayoutInfo
|
||||
{
|
||||
OverlayColorLegendLayoutInfo(const Vec2ui& pos, const Vec2ui& setSize)
|
||||
OverlayColorLegendLayoutInfo(const Vec2i& pos, const Vec2ui& setSize)
|
||||
{
|
||||
position = pos;
|
||||
size = setSize;
|
||||
@ -93,12 +93,12 @@ protected:
|
||||
|
||||
ref<DoubleArray> tickPixelPos;
|
||||
|
||||
Vec2ui position;
|
||||
Vec2i position;
|
||||
Vec2ui size;
|
||||
};
|
||||
|
||||
|
||||
void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software);
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software);
|
||||
virtual void renderLegend(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout, const MatrixState& matrixState);
|
||||
virtual void renderLegendImmediateMode(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout);
|
||||
virtual void setupTextDrawer(TextDrawer* textDrawer, OverlayColorLegendLayoutInfo* layout);
|
||||
|
@ -104,7 +104,7 @@ cvf::Vec2ui OverlayTextBox::minimumSize()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Render using Shaders
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayTextBox::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayTextBox::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, false);
|
||||
}
|
||||
@ -113,7 +113,7 @@ void OverlayTextBox::render(OpenGLContext* oglContext, const Vec2ui& position, c
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Render using Fixed Function
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayTextBox::renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size)
|
||||
void OverlayTextBox::renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size)
|
||||
{
|
||||
render(oglContext, position, size, true);
|
||||
}
|
||||
@ -122,7 +122,7 @@ void OverlayTextBox::renderSoftware(OpenGLContext* oglContext, const Vec2ui& pos
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayTextBox::render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software)
|
||||
void OverlayTextBox::render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software)
|
||||
{
|
||||
Mat4d ident;
|
||||
MatrixState matrixState(position, size, ident, ident);
|
||||
@ -157,7 +157,7 @@ void OverlayTextBox::render(OpenGLContext* oglContext, const Vec2ui& position, c
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayTextBox::renderBackgroundAndBorder(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software)
|
||||
void OverlayTextBox::renderBackgroundAndBorder(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software)
|
||||
{
|
||||
CVF_CALLSITE_OPENGL(oglContext);
|
||||
|
||||
|
@ -44,8 +44,8 @@ public:
|
||||
virtual Vec2ui maximumSize();
|
||||
virtual Vec2ui minimumSize();
|
||||
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size);
|
||||
virtual void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
virtual void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size);
|
||||
|
||||
void setText(const String& text);
|
||||
void setPixelSize(const Vec2ui& size);
|
||||
@ -66,8 +66,8 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
void render(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software);
|
||||
void renderBackgroundAndBorder(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software);
|
||||
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software);
|
||||
void renderBackgroundAndBorder(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software);
|
||||
|
||||
private:
|
||||
Vec2ui m_size;
|
||||
|
@ -748,12 +748,21 @@ void ShaderProgram::discoverActiveUniforms(OpenGLContext* oglContext)
|
||||
|
||||
if (numCharsInName > 0)
|
||||
{
|
||||
const char* uniformName = uniformNameBuffer.ptr();
|
||||
int location = glGetUniformLocation(m_oglRcProgram->oglId(), uniformName);
|
||||
std::string uniformName = uniformNameBuffer.ptr();
|
||||
|
||||
// Added this code to fix a bug in the Nvidia drivers that reports arrays as xxx[0], like u_ecClipPlanes reported as u_ecClipPlanes[0]
|
||||
size_t bracketPos = uniformName.find('[');
|
||||
if (bracketPos != std::string::npos)
|
||||
{
|
||||
uniformName.resize(bracketPos);
|
||||
}
|
||||
|
||||
int location = glGetUniformLocation(m_oglRcProgram->oglId(), uniformName.c_str());
|
||||
CVF_CHECK_OGL(oglContext);
|
||||
|
||||
|
||||
FixedUniform fixedUniform;
|
||||
if (ShaderProgram::mapUniformNameToFixedUniformEnum(uniformName, &fixedUniform))
|
||||
if (ShaderProgram::mapUniformNameToFixedUniformEnum(uniformName.c_str(), &fixedUniform))
|
||||
{
|
||||
m_fixedUniformsMap[fixedUniform] = location;
|
||||
m_fixedUniformsNameLocationMap[uniformName] = location;
|
||||
|
@ -125,7 +125,7 @@ void ShaderSourceProvider::addFileSearchDirectory(String directory)
|
||||
bool ShaderSourceProvider::loadFile(const String& fullFileName, CharArray* fileContents)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::ifstream file(fullFileName.ptr());
|
||||
std::ifstream file(fullFileName.c_str());
|
||||
#else
|
||||
std::ifstream file(fullFileName.toUtf8().ptr());
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ bool ShaderSourceRepositoryFile::rawShaderSource(ShaderIdent shaderIdent, CharAr
|
||||
String fullFileName = fileNameFromIdent(shaderIdent);
|
||||
|
||||
#ifdef WIN32
|
||||
std::ifstream file(fullFileName.ptr());
|
||||
std::ifstream file(fullFileName.c_str());
|
||||
#else
|
||||
std::ifstream file(fullFileName.toUtf8().ptr());
|
||||
#endif
|
||||
|
@ -1018,6 +1018,10 @@ static const char vs_Minimal_inl[] =
|
||||
" \n"
|
||||
"uniform mat4 cvfu_modelViewProjectionMatrix; \n"
|
||||
" \n"
|
||||
"#ifdef CVF_CALC_CLIP_DISTANCES_IMPL \n"
|
||||
"uniform mat4 cvfu_modelViewMatrix; \n"
|
||||
"#endif \n"
|
||||
" \n"
|
||||
"attribute vec4 cvfa_vertex; \n"
|
||||
" \n"
|
||||
"//-------------------------------------------------------------------------------------------------- \n"
|
||||
@ -1027,6 +1031,11 @@ static const char vs_Minimal_inl[] =
|
||||
"{ \n"
|
||||
" gl_Position = cvfu_modelViewProjectionMatrix*cvfa_vertex; \n"
|
||||
" \n"
|
||||
"#ifdef CVF_CALC_CLIP_DISTANCES_IMPL \n"
|
||||
" vec3 ecPosition = (cvfu_modelViewMatrix * cvfa_vertex).xyz; \n"
|
||||
" calcClipDistances(vec4(ecPosition, 1)); \n"
|
||||
"#endif \n"
|
||||
" \n"
|
||||
"#ifdef CVF_OPENGL_ES \n"
|
||||
" gl_PointSize = 1.0; \n"
|
||||
"#endif \n"
|
||||
@ -1039,6 +1048,10 @@ static const char vs_Minimal_inl[] =
|
||||
static const char vs_MinimalTexture_inl[] =
|
||||
"uniform mat4 cvfu_modelViewProjectionMatrix; \n"
|
||||
" \n"
|
||||
"#ifdef CVF_CALC_CLIP_DISTANCES_IMPL \n"
|
||||
"uniform mat4 cvfu_modelViewMatrix; \n"
|
||||
"#endif \n"
|
||||
" \n"
|
||||
"attribute vec2 cvfa_texCoord; \n"
|
||||
"attribute vec4 cvfa_vertex; \n"
|
||||
" \n"
|
||||
@ -1052,6 +1065,11 @@ static const char vs_MinimalTexture_inl[] =
|
||||
" v_texCoord = cvfa_texCoord; \n"
|
||||
" gl_Position = cvfu_modelViewProjectionMatrix * cvfa_vertex; \n"
|
||||
" \n"
|
||||
"#ifdef CVF_CALC_CLIP_DISTANCES_IMPL \n"
|
||||
" vec3 ecPosition = (cvfu_modelViewMatrix * cvfa_vertex).xyz; \n"
|
||||
" calcClipDistances(vec4(ecPosition, 1)); \n"
|
||||
"#endif \n"
|
||||
" \n"
|
||||
"#ifdef CVF_OPENGL_ES \n"
|
||||
" gl_PointSize = 1.0; \n"
|
||||
"#endif \n"
|
||||
|
@ -363,6 +363,8 @@ void TextDrawer::doRender2d(OpenGLContext* oglContext, const MatrixState& matrix
|
||||
if (softwareRendering)
|
||||
{
|
||||
#ifndef CVF_OPENGL_ES
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4fv(m_backgroundColor.ptr());
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3fv(v1);
|
||||
|
@ -56,8 +56,11 @@ Viewport::Viewport()
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Specify the position and dimensions of the viewport
|
||||
///
|
||||
/// The window coordinates (x,y) are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Viewport::set(uint x, uint y, uint width, uint height)
|
||||
void Viewport::set(int x, int y, uint width, uint height)
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
@ -84,7 +87,7 @@ void Viewport::setClearColor(Color4f color)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Get the x coordinate of the lower left corner of the viewport
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint Viewport::x() const
|
||||
int Viewport::x() const
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
@ -93,7 +96,7 @@ uint Viewport::x() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Get the y coordinate of the lower left corner of the viewport
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
uint Viewport::y() const
|
||||
int Viewport::y() const
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
@ -245,7 +248,7 @@ void Viewport::applyOpenGL(OpenGLContext* oglContext, ClearMode clearMode)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String Viewport::toString() const
|
||||
String Viewport::debugString() const
|
||||
{
|
||||
String str = "Viewport: ";
|
||||
|
||||
|
@ -52,10 +52,10 @@ public:
|
||||
public:
|
||||
Viewport();
|
||||
|
||||
void set(uint x, uint y, uint width, uint height);
|
||||
void set(int x, int y, uint width, uint height);
|
||||
|
||||
uint x() const;
|
||||
uint y() const;
|
||||
int x() const;
|
||||
int y() const;
|
||||
uint width() const;
|
||||
uint height() const;
|
||||
double aspectRatio() const;
|
||||
@ -65,16 +65,16 @@ public:
|
||||
|
||||
void applyOpenGL(OpenGLContext* oglContext, ClearMode clearMode);
|
||||
|
||||
String toString() const;
|
||||
String debugString() const;
|
||||
|
||||
private:
|
||||
cvfGLbitfield clearFlagsOpenGL(ClearMode clearMode);
|
||||
|
||||
private:
|
||||
uint m_x;
|
||||
uint m_y;
|
||||
uint m_width;
|
||||
uint m_height;
|
||||
int m_x;
|
||||
int m_y;
|
||||
uint m_width;
|
||||
uint m_height;
|
||||
|
||||
Color4f m_clearColor;
|
||||
double m_clearDepth;
|
||||
|
@ -1,6 +1,10 @@
|
||||
|
||||
uniform mat4 cvfu_modelViewProjectionMatrix;
|
||||
|
||||
#ifdef CVF_CALC_CLIP_DISTANCES_IMPL
|
||||
uniform mat4 cvfu_modelViewMatrix;
|
||||
#endif
|
||||
|
||||
attribute vec4 cvfa_vertex;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -10,6 +14,11 @@ void main ()
|
||||
{
|
||||
gl_Position = cvfu_modelViewProjectionMatrix*cvfa_vertex;
|
||||
|
||||
#ifdef CVF_CALC_CLIP_DISTANCES_IMPL
|
||||
vec3 ecPosition = (cvfu_modelViewMatrix * cvfa_vertex).xyz;
|
||||
calcClipDistances(vec4(ecPosition, 1));
|
||||
#endif
|
||||
|
||||
#ifdef CVF_OPENGL_ES
|
||||
gl_PointSize = 1.0;
|
||||
#endif
|
||||
|
@ -1,5 +1,9 @@
|
||||
uniform mat4 cvfu_modelViewProjectionMatrix;
|
||||
|
||||
#ifdef CVF_CALC_CLIP_DISTANCES_IMPL
|
||||
uniform mat4 cvfu_modelViewMatrix;
|
||||
#endif
|
||||
|
||||
attribute vec2 cvfa_texCoord;
|
||||
attribute vec4 cvfa_vertex;
|
||||
|
||||
@ -13,6 +17,11 @@ void main ()
|
||||
v_texCoord = cvfa_texCoord;
|
||||
gl_Position = cvfu_modelViewProjectionMatrix * cvfa_vertex;
|
||||
|
||||
#ifdef CVF_CALC_CLIP_DISTANCES_IMPL
|
||||
vec3 ecPosition = (cvfu_modelViewMatrix * cvfa_vertex).xyz;
|
||||
calcClipDistances(vec4(ecPosition, 1));
|
||||
#endif
|
||||
|
||||
#ifdef CVF_OPENGL_ES
|
||||
gl_PointSize = 1.0;
|
||||
#endif
|
||||
|
@ -79,12 +79,13 @@ Vec3d LocatorTranslateOnPlane::position() const
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void LocatorTranslateOnPlane::start(int winCoordX, int winCoordY)
|
||||
void LocatorTranslateOnPlane::start(int x, int y)
|
||||
{
|
||||
CVF_ASSERT(m_camera.notNull());
|
||||
ref<Ray> ray = m_camera->rayFromWinCoord(winCoordX, winCoordY);
|
||||
ref<Ray> ray = m_camera->rayFromWindowCoordinates(x, y);
|
||||
|
||||
Vec3d isect(0, 0, 0);
|
||||
ray->planeIntersect(m_plane, &isect);
|
||||
@ -94,15 +95,16 @@ void LocatorTranslateOnPlane::start(int winCoordX, int winCoordY)
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool LocatorTranslateOnPlane::update(int winCoordX, int winCoordY)
|
||||
bool LocatorTranslateOnPlane::update(int x, int y)
|
||||
{
|
||||
CVF_ASSERT(m_camera.notNull());
|
||||
|
||||
Vec3d oldPos = m_pos;
|
||||
|
||||
ref<Ray> ray = m_camera->rayFromWinCoord(winCoordX, winCoordY);
|
||||
ref<Ray> ray = m_camera->rayFromWindowCoordinates(x, y);
|
||||
|
||||
Vec3d isect(0, 0, 0);
|
||||
if (ray->planeIntersect(m_plane, &isect))
|
||||
@ -139,8 +141,8 @@ LocatorPanWalkRotate::LocatorPanWalkRotate(Camera* camera)
|
||||
: m_camera(camera),
|
||||
m_operation(PAN),
|
||||
m_pos(0, 0, 0),
|
||||
m_lastWinPosX(0),
|
||||
m_lastWinPosY(0)
|
||||
m_lastPosX(0),
|
||||
m_lastPosY(0)
|
||||
{
|
||||
CVF_ASSERT(camera);
|
||||
}
|
||||
@ -183,31 +185,33 @@ Vec3d LocatorPanWalkRotate::position() const
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void LocatorPanWalkRotate::start(int winCoordX, int winCoordY)
|
||||
void LocatorPanWalkRotate::start(int x, int y)
|
||||
{
|
||||
m_lastWinPosX = winCoordX;
|
||||
m_lastWinPosY = winCoordY;
|
||||
m_lastPosX = x;
|
||||
m_lastPosY = y;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool LocatorPanWalkRotate::update(int winCoordX, int winCoordY)
|
||||
bool LocatorPanWalkRotate::update(int x, int y)
|
||||
{
|
||||
CVF_ASSERT(m_camera.notNull());
|
||||
|
||||
if (winCoordX == m_lastWinPosX && winCoordY == m_lastWinPosY) return false;
|
||||
if (x == m_lastPosX && y == m_lastPosY) return false;
|
||||
|
||||
const double vpPixSizeX = m_camera->viewport()->width();
|
||||
const double vpPixSizeY = m_camera->viewport()->height();
|
||||
if (vpPixSizeX <= 0 || vpPixSizeY <= 0) return false;
|
||||
|
||||
// Normalized movement in screen plane
|
||||
const double tx = (winCoordX - m_lastWinPosX)/vpPixSizeX;
|
||||
const double ty = (winCoordY - m_lastWinPosY)/vpPixSizeY;
|
||||
const double tx = (x - m_lastPosX)/vpPixSizeX;
|
||||
const double ty = (y - m_lastPosY)/vpPixSizeY;
|
||||
|
||||
Vec3d oldPos = m_pos;
|
||||
|
||||
@ -220,8 +224,8 @@ bool LocatorPanWalkRotate::update(int winCoordX, int winCoordY)
|
||||
updateWalk(ty);
|
||||
}
|
||||
|
||||
m_lastWinPosX = winCoordX;
|
||||
m_lastWinPosY = winCoordY;
|
||||
m_lastPosX = x;
|
||||
m_lastPosY = y;
|
||||
|
||||
if (m_pos == oldPos)
|
||||
{
|
||||
@ -261,7 +265,7 @@ void LocatorPanWalkRotate::updatePan(double tx, double ty)
|
||||
|
||||
const double nearPlane = m_camera->nearPlane();
|
||||
Vec3d vX = camRight*((tx*vpWorldSizeX)/nearPlane)*camPointDist;
|
||||
Vec3d vY = -camUp*((ty*vpWorldSizeY)/nearPlane)*camPointDist;
|
||||
Vec3d vY = camUp*((ty*vpWorldSizeY)/nearPlane)*camPointDist;
|
||||
|
||||
Vec3d translation = vX + vY;
|
||||
m_pos += translation;
|
||||
@ -270,7 +274,7 @@ void LocatorPanWalkRotate::updatePan(double tx, double ty)
|
||||
else if (projType == Camera::ORTHO)
|
||||
{
|
||||
Vec3d vX = camRight*tx*vpWorldSizeX;
|
||||
Vec3d vY = -camUp*ty*vpWorldSizeY;
|
||||
Vec3d vY = camUp*ty*vpWorldSizeY;
|
||||
|
||||
Vec3d translation = vX + vY;
|
||||
m_pos += translation;
|
||||
|
@ -37,8 +37,8 @@ public:
|
||||
Locator() {};
|
||||
|
||||
virtual Vec3d position() const = 0;
|
||||
virtual void start(int winCoordX, int winCoordY) = 0;
|
||||
virtual bool update(int winCoordX, int winCoordY) = 0;
|
||||
virtual void start(int x, int y) = 0;
|
||||
virtual bool update(int x, int y) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -56,8 +56,8 @@ public:
|
||||
|
||||
void setPosition(const Vec3d& position, const Vec3d& planeNormal);
|
||||
virtual Vec3d position() const;
|
||||
virtual void start(int winCoordX, int winCoordY);
|
||||
virtual bool update(int winCoordX, int winCoordY);
|
||||
virtual void start(int x, int y);
|
||||
virtual bool update(int x, int y);
|
||||
|
||||
public:
|
||||
ref<Camera> m_camera;
|
||||
@ -90,8 +90,8 @@ public:
|
||||
void setOperation(Operation op);
|
||||
void setPosition(const Vec3d& position);
|
||||
virtual Vec3d position() const;
|
||||
virtual void start(int winCoordX, int winCoordY);
|
||||
virtual bool update(int winCoordX, int winCoordY);
|
||||
virtual void start(int x, int y);
|
||||
virtual bool update(int x, int y);
|
||||
|
||||
private:
|
||||
void updatePan(double tx, double ty);
|
||||
@ -101,8 +101,8 @@ private:
|
||||
ref<Camera> m_camera;
|
||||
Operation m_operation; // Default operation is PAN
|
||||
Vec3d m_pos;
|
||||
int m_lastWinPosX;
|
||||
int m_lastWinPosY;
|
||||
int m_lastPosX;
|
||||
int m_lastPosY;
|
||||
};
|
||||
|
||||
|
||||
|
@ -92,15 +92,16 @@ ManipulatorTrackball::NavigationType ManipulatorTrackball::activeNavigation() co
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void ManipulatorTrackball::startNavigation(NavigationType navigationType, int winCoordX, int winCoordY)
|
||||
void ManipulatorTrackball::startNavigation(NavigationType navigationType, int x, int y)
|
||||
{
|
||||
if (m_camera.isNull()) return;
|
||||
if (m_activeNavigation == navigationType) return;
|
||||
|
||||
m_lastPosX = winCoordX;
|
||||
m_lastPosY = winCoordY;
|
||||
m_lastPosX = x;
|
||||
m_lastPosY = y;
|
||||
|
||||
// Register camera's starting position for walk
|
||||
m_walkStartCameraPos = m_camera->position();
|
||||
@ -110,25 +111,26 @@ void ManipulatorTrackball::startNavigation(NavigationType navigationType, int wi
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool ManipulatorTrackball::updateNavigation(int winCoordX, int winCoordY)
|
||||
bool ManipulatorTrackball::updateNavigation(int x, int y)
|
||||
{
|
||||
if (m_activeNavigation == PAN)
|
||||
{
|
||||
return pan(winCoordX, winCoordY);
|
||||
return pan(x, y);
|
||||
}
|
||||
else if (m_activeNavigation == WALK)
|
||||
{
|
||||
return walk(winCoordX, winCoordY);
|
||||
return walk(x, y);
|
||||
}
|
||||
else if (m_activeNavigation == ZOOM)
|
||||
{
|
||||
return zoom(winCoordX, winCoordY);
|
||||
return zoom(x, y);
|
||||
}
|
||||
else if (m_activeNavigation == ROTATE)
|
||||
{
|
||||
return rotate(winCoordX, winCoordY);
|
||||
return rotate(x, y);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -185,13 +187,13 @@ bool ManipulatorTrackball::pan(int posX, int posY)
|
||||
const double camRotPointDist = Math::abs(camDir*vDiff);
|
||||
|
||||
Vec3d vX = camRight*((tx*vpWorldSizeX)/nearPlane)*camRotPointDist;
|
||||
Vec3d vY = -camUp*((ty*vpWorldSizeY)/nearPlane)*camRotPointDist;
|
||||
Vec3d vY = camUp*((ty*vpWorldSizeY)/nearPlane)*camRotPointDist;
|
||||
translation = vX + vY;
|
||||
}
|
||||
else if (projType == Camera::ORTHO)
|
||||
{
|
||||
Vec3d vX = camRight*tx*vpWorldSizeX;
|
||||
Vec3d vY = -camUp*ty*vpWorldSizeY;
|
||||
Vec3d vY = camUp*ty*vpWorldSizeY;
|
||||
translation = vX + vY;
|
||||
}
|
||||
|
||||
@ -226,7 +228,7 @@ bool ManipulatorTrackball::walk(int posX, int posY)
|
||||
// Should be a member variable, settable as a ratio of the model bounding box/sphere
|
||||
const double minWalkTargetDistance = 1.0;
|
||||
|
||||
const double ty = (posY - m_lastPosY)/vpPixSizeY;
|
||||
const double ty = (m_lastPosY - posY)/vpPixSizeY;
|
||||
|
||||
// Determine target distance to travel along camera direction
|
||||
// This is the distance that we will move the camera in response to a full (whole viewport) movement of the mouse
|
||||
@ -261,7 +263,7 @@ bool ManipulatorTrackball::zoom(int posX, int posY)
|
||||
const double vpPixSizeY = m_camera->viewport()->height();
|
||||
if (vpPixSizeY <= 0) return false;
|
||||
|
||||
const double ty = (posY - m_lastPosY)/vpPixSizeY;
|
||||
const double ty = (m_lastPosY - posY)/vpPixSizeY;
|
||||
|
||||
const double frustumHeight = m_camera->frontPlaneFrustumHeight();
|
||||
|
||||
@ -312,17 +314,21 @@ bool ManipulatorTrackball::rotate(int posX, int posY)
|
||||
const double vpPixSizeY = m_camera->viewport()->height();
|
||||
if (vpPixSizeX <= 0 || vpPixSizeY <= 0) return false;
|
||||
|
||||
const double vpPosX = posX - static_cast<int>(m_camera->viewport()->x());
|
||||
const double vpPosY = posY - static_cast<int>(m_camera->viewport()->y());
|
||||
const double vpLastPosX = m_lastPosX - static_cast<int>(m_camera->viewport()->x());
|
||||
const double vpLastPosY = m_lastPosY - static_cast<int>(m_camera->viewport()->y());
|
||||
|
||||
// Scale the new/last positions to the range [-1.0, 1.0]
|
||||
double newPosX = 2.0*(posX/vpPixSizeX) - 1.0;
|
||||
double newPosY = 2.0*(posY/vpPixSizeY) - 1.0;
|
||||
double lastPosX = 2.0*(m_lastPosX/vpPixSizeX) - 1.0;
|
||||
double lastPosY = 2.0*(m_lastPosY/vpPixSizeY) - 1.0;
|
||||
double newPosX = 2.0*(vpPosX/vpPixSizeX) - 1.0;
|
||||
double newPosY = 2.0*(vpPosY/vpPixSizeY) - 1.0;
|
||||
double lastPosX = 2.0*(vpLastPosX/vpPixSizeX) - 1.0;
|
||||
double lastPosY = 2.0*(vpLastPosY/vpPixSizeY) - 1.0;
|
||||
|
||||
Mat4d viewMat = m_camera->viewMatrix();
|
||||
|
||||
// Compute rotation quaternion
|
||||
Quatd rotQuat = trackballRotation(lastPosX, -lastPosY, newPosX, -newPosY, viewMat, m_rotateSensitivity);
|
||||
Quatd rotQuat = trackballRotation(lastPosX, lastPosY, newPosX, newPosY, viewMat, m_rotateSensitivity);
|
||||
|
||||
// Update navigation by modifying the view matrix
|
||||
Mat4d rotMatr = rotQuat.toMatrix4();
|
||||
|
@ -54,8 +54,8 @@ public:
|
||||
void setView(const Vec3d& alongDirection, const Vec3d& upDirection);
|
||||
|
||||
NavigationType activeNavigation() const;
|
||||
void startNavigation(NavigationType navigationType, int winCoordX, int winCoordY);
|
||||
bool updateNavigation(int winCoordX, int winCoordY);
|
||||
void startNavigation(NavigationType navigationType, int x, int y);
|
||||
bool updateNavigation(int x, int y);
|
||||
void endNavigation();
|
||||
|
||||
private:
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "cvfRenderStateBlending.h"
|
||||
#include "cvfRenderStatePolygonMode.h"
|
||||
#include "cvfRenderStateLine.h"
|
||||
#include "cvfClipPlaneSet.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
@ -69,12 +70,6 @@ PartHighlighter::PartHighlighter(Model* highlightModel, Camera* mainCamera)
|
||||
m_drawFbo = new FramebufferObject;
|
||||
m_drawFbo->attachColorTexture2d(0, selectedColorTexture.p());
|
||||
|
||||
ShaderProgramGenerator spGen("DrawHighlightGeo", ShaderSourceProvider::instance());
|
||||
spGen.addVertexCode(ShaderSourceRepository::vs_Standard);
|
||||
spGen.addFragmentCode(ShaderSourceRepository::src_Color);
|
||||
spGen.addFragmentCode(ShaderSourceRepository::fs_Unlit);
|
||||
ref<ShaderProgram> shaderProg = spGen.generate();
|
||||
|
||||
// Note that we clear alpha to 0
|
||||
m_highlightCamera = new Camera;
|
||||
m_highlightCamera->viewport()->setClearColor(Color4f(Color3::GRAY, 0));
|
||||
@ -85,14 +80,7 @@ PartHighlighter::PartHighlighter(Model* highlightModel, Camera* mainCamera)
|
||||
m_drawRendering->setCamera(m_highlightCamera.p());
|
||||
m_drawRendering->setScene(new Scene);
|
||||
m_drawRendering->scene()->addModel(m_highlightModel.p());
|
||||
|
||||
{
|
||||
ref<Effect> eff = new Effect;
|
||||
eff->setShaderProgram(shaderProg.p());
|
||||
// Use magenta to detect if something isn't working as it should
|
||||
eff->setUniform(new UniformFloat("u_color", Color4f(Color3::MAGENTA)));
|
||||
m_drawRendering->setEffectOverride(eff.p());
|
||||
}
|
||||
m_drawRendering->setRenderingName("PartHighlighter : Main 'solid' rendering (m_drawRendering)");
|
||||
|
||||
// Draw geometry again using lines to increase footprint of slim details
|
||||
bool growFootprintUsingLineDrawing = true;
|
||||
@ -104,18 +92,11 @@ PartHighlighter::PartHighlighter(Model* highlightModel, Camera* mainCamera)
|
||||
m_drawRenderingLines->setScene(new Scene);
|
||||
m_drawRenderingLines->scene()->addModel(m_highlightModel.p());
|
||||
m_drawRenderingLines->setClearMode(Viewport::DO_NOT_CLEAR);
|
||||
|
||||
{
|
||||
ref<Effect> eff = new Effect;
|
||||
eff->setShaderProgram(shaderProg.p());
|
||||
eff->setRenderState(new RenderStatePolygonMode(RenderStatePolygonMode::LINE));
|
||||
eff->setRenderState(new RenderStateLine(3));
|
||||
// Use cyan to detect if something isn't working as it should
|
||||
eff->setUniform(new UniformFloat("u_color", Color4f(Color3::CYAN)));
|
||||
m_drawRenderingLines->setEffectOverride(eff.p());
|
||||
}
|
||||
m_drawRenderingLines->setRenderingName("PartHighlighter : Main 'solid' rendering (lines) (m_drawRenderingLines)");
|
||||
}
|
||||
|
||||
configureOverrideEffects(false);
|
||||
|
||||
// Setup the blur helper
|
||||
// The sigma value her should be tuned to the line width used above
|
||||
// If sigma gets larger that the line width we will get artifacts during the blur pass
|
||||
@ -141,6 +122,7 @@ PartHighlighter::PartHighlighter(Model* highlightModel, Camera* mainCamera)
|
||||
quadRenderGen.setUniform(m_highlightClrUniform.p());
|
||||
m_mixRendering = quadRenderGen.generate();
|
||||
m_mixRendering->setClearMode(Viewport::DO_NOT_CLEAR);
|
||||
m_mixRendering->setRenderingName("PartHighlighter : Mix Rendering (m_mixRendering)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,14 +187,15 @@ void PartHighlighter::removeRenderingsFromSequence(RenderSequence* renderSequenc
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PartHighlighter::resize(uint width, uint height)
|
||||
void PartHighlighter::resize(int x, int y, uint width, uint height)
|
||||
{
|
||||
m_drawFbo->resizeAttachedBuffers(width, height);
|
||||
|
||||
// Since draw and drawLines shares a camera, this call will set both
|
||||
m_drawRendering->camera()->setViewport(0, 0, width, height);
|
||||
|
||||
m_mixRendering->camera()->setViewport(0, 0, width, height);
|
||||
// Mix rendering is the only "on-screen" rendering so here we do need to set the position of the viewport
|
||||
m_mixRendering->camera()->setViewport(x, y, width, height);
|
||||
|
||||
if (m_blur.notNull())
|
||||
{
|
||||
@ -239,6 +222,78 @@ void PartHighlighter::prepareForRedraw()
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PartHighlighter::setClipPlaneSet(ClipPlaneSet* clipPlaneSet)
|
||||
{
|
||||
m_drawRendering->removeAllGlobalDynamicUniformSets();
|
||||
|
||||
if (m_drawRenderingLines.notNull())
|
||||
{
|
||||
m_drawRenderingLines->removeAllGlobalDynamicUniformSets();
|
||||
}
|
||||
|
||||
if (clipPlaneSet)
|
||||
{
|
||||
m_drawRendering->addGlobalDynamicUniformSet(clipPlaneSet);
|
||||
if (m_drawRenderingLines.notNull())
|
||||
{
|
||||
m_drawRenderingLines->addGlobalDynamicUniformSet(clipPlaneSet);
|
||||
}
|
||||
|
||||
configureOverrideEffects(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
configureOverrideEffects(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PartHighlighter::configureOverrideEffects(bool useClipping)
|
||||
{
|
||||
ShaderProgramGenerator spGen("DrawHighlightGeo", ShaderSourceProvider::instance());
|
||||
|
||||
if (useClipping)
|
||||
{
|
||||
spGen.addVertexCode(cvf::ShaderSourceRepository::calcClipDistances);
|
||||
spGen.addFragmentCode(cvf::ShaderSourceRepository::checkDiscard_ClipDistances);
|
||||
}
|
||||
|
||||
spGen.addVertexCode(ShaderSourceRepository::vs_Standard);
|
||||
spGen.addFragmentCode(ShaderSourceRepository::src_Color);
|
||||
spGen.addFragmentCode(ShaderSourceRepository::fs_Unlit);
|
||||
|
||||
ref<ShaderProgram> shaderProg = spGen.generate();
|
||||
|
||||
if (useClipping)
|
||||
{
|
||||
shaderProg->setDefaultUniform(new cvf::UniformInt( "u_clipPlaneCount", 0));
|
||||
shaderProg->setDefaultUniform(new cvf::UniformFloat("u_ecClipPlanes", cvf::Vec4f(0, 0, 1, 0)));
|
||||
}
|
||||
|
||||
ref<Effect> eff = new Effect;
|
||||
eff->setShaderProgram(shaderProg.p());
|
||||
// Use magenta to detect if something isn't working as it should
|
||||
eff->setUniform(new UniformFloat("u_color", Color4f(Color3::MAGENTA)));
|
||||
m_drawRendering->setEffectOverride(eff.p());
|
||||
|
||||
if (m_drawRenderingLines.notNull())
|
||||
{
|
||||
ref<Effect> eff = new Effect;
|
||||
eff->setShaderProgram(shaderProg.p());
|
||||
eff->setRenderState(new RenderStatePolygonMode(RenderStatePolygonMode::LINE));
|
||||
eff->setRenderState(new RenderStateLine(3));
|
||||
// Use cyan to detect if something isn't working as it should
|
||||
eff->setUniform(new UniformFloat("u_color", Color4f(Color3::CYAN)));
|
||||
m_drawRenderingLines->setEffectOverride(eff.p());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
|
@ -31,6 +31,7 @@ class Model;
|
||||
class Camera;
|
||||
class GaussianBlur;
|
||||
class UniformFloat;
|
||||
class ClipPlaneSet;
|
||||
|
||||
|
||||
|
||||
@ -48,9 +49,14 @@ public:
|
||||
|
||||
void addRenderingsToSequence(RenderSequence* renderSequence);
|
||||
void removeRenderingsFromSequence(RenderSequence* renderSequence);
|
||||
void resize(uint width, uint height);
|
||||
void resize(int x, int y, uint width, uint height);
|
||||
void prepareForRedraw();
|
||||
|
||||
void setClipPlaneSet(ClipPlaneSet* clipPlaneSet);
|
||||
|
||||
private:
|
||||
void configureOverrideEffects(bool useClipping);
|
||||
|
||||
private:
|
||||
ref<Model> m_highlightModel; // Model containing the parts that should be highlighted
|
||||
ref<Camera> m_highlightCamera; // Camera to use in the highlight rendering, need a separate camera as long as clear color is part of camera/viewport
|
||||
@ -63,7 +69,6 @@ private:
|
||||
ref<Rendering> m_mixRendering; // Rendering used in final mix pass
|
||||
ref<UniformFloat> m_highlightClrUniform; // Uniform that controls the highlight color used in the mix rendering
|
||||
ref<GaussianBlur> m_blur; // Blur helper
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -159,7 +159,10 @@ void Rendering::render(OpenGLContext* oglContext)
|
||||
}
|
||||
|
||||
// Update any transforms and bounding boxes if a transform tree is used
|
||||
m_scene->updateTransformTree(m_camera.p());
|
||||
if (m_scene.notNull())
|
||||
{
|
||||
m_scene->updateTransformTree(m_camera.p());
|
||||
}
|
||||
|
||||
// Compute visible parts
|
||||
// -------------------------------------------------------------------------
|
||||
@ -294,15 +297,15 @@ void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRe
|
||||
for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it)
|
||||
{
|
||||
OverlayItem* item = it->first;
|
||||
Rectui rect = it->second;
|
||||
Recti rect = it->second;
|
||||
|
||||
if (useSoftwareRendering)
|
||||
{
|
||||
item->renderSoftware(oglContext, rect.min(), Vec2ui(rect.width(), rect.height()));
|
||||
item->renderSoftware(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height())));
|
||||
}
|
||||
else
|
||||
{
|
||||
item->render(oglContext, rect.min(), Vec2ui(rect.width(), rect.height()));
|
||||
item->render(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -329,10 +332,11 @@ void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, OverlayItem::LayoutCorner corner, OverlayItem::LayoutDirection direction)
|
||||
{
|
||||
const uint border = 3;
|
||||
const Vec2ui vpSize = Vec2ui(m_camera->viewport()->width(), m_camera->viewport()->height());
|
||||
const int border = 3;
|
||||
const Vec2i vpSize = Vec2i(static_cast<int>(m_camera->viewport()->width()), static_cast<int>(m_camera->viewport()->height()));
|
||||
const Vec2i vpPos = Vec2i(m_camera->viewport()->x(), m_camera->viewport()->y());
|
||||
|
||||
Vec2ui cursor(0,0);
|
||||
Vec2i cursor(0,0);
|
||||
switch (corner)
|
||||
{
|
||||
case OverlayItem::TOP_LEFT: cursor.set(border, vpSize.y() - border); break;
|
||||
@ -342,11 +346,13 @@ void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, Over
|
||||
default: cursor.set(border,border);
|
||||
}
|
||||
|
||||
cursor += vpPos;
|
||||
|
||||
// Adjust based on other already placed items
|
||||
OverlayItemRectMap::iterator it;
|
||||
for (it = itemRectMap->begin(); it != itemRectMap->end(); ++it)
|
||||
{
|
||||
Rectui rect = it->second;
|
||||
Recti rect = it->second;
|
||||
|
||||
if (rect.contains(cursor) && (direction == OverlayItem::VERTICAL))
|
||||
{
|
||||
@ -371,7 +377,7 @@ void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, Over
|
||||
CVF_ASSERT(item.overlayItem.notNull());
|
||||
|
||||
// Find this position and size
|
||||
Vec2ui position = cursor;
|
||||
Vec2i position = cursor;
|
||||
Vec2ui size = item.overlayItem->sizeHint();
|
||||
if ((corner == OverlayItem::TOP_RIGHT) || (corner == OverlayItem::BOTTOM_RIGHT))
|
||||
{
|
||||
@ -384,7 +390,7 @@ void Rendering::calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, Over
|
||||
}
|
||||
|
||||
// Store the position in the map
|
||||
Rectui rect(position.x(), position.y(), size.x(), size.y());
|
||||
Recti rect(position.x(), position.y(), static_cast<int>(size.x()), static_cast<int>(size.y()));
|
||||
(*itemRectMap)[item.overlayItem.p()] = rect;
|
||||
|
||||
// Find next position, moving the cursor
|
||||
@ -505,17 +511,17 @@ RenderQueueSorter* Rendering::renderQueueSorter()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Create a new RayIntersectSpec object based on this rendering and the specified coordinates
|
||||
///
|
||||
/// The coordinates (\a winCoordX & \a winCoordY) are assumed to be in the window coordinate system
|
||||
/// where <0,0> if in the top left corner.
|
||||
/// The window coordinates are in OpenGL style coordinates, which means a right handed
|
||||
/// coordinate system with the origin in the lower left corner of the window.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
ref<RayIntersectSpec> Rendering::createRayIntersectSpec(int winCoordX, int winCoordY) const
|
||||
ref<RayIntersectSpec> Rendering::rayIntersectSpecFromWindowCoordinates(int x, int y) const
|
||||
{
|
||||
if (m_scene.isNull() || m_camera.isNull())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ref<Ray> ray = m_camera->rayFromWinCoord(winCoordX, winCoordY);
|
||||
ref<Ray> ray = m_camera->rayFromWindowCoordinates(x, y);
|
||||
if (ray.isNull())
|
||||
{
|
||||
return NULL;
|
||||
@ -670,7 +676,7 @@ void Rendering::addGlobalDynamicUniformSet(DynamicUniformSet* dynUniformSet)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Rendering::removeAllGlobalUniformSets()
|
||||
void Rendering::removeAllGlobalDynamicUniformSets()
|
||||
{
|
||||
m_globalDynamicUniformSets.clear();
|
||||
}
|
||||
@ -877,12 +883,8 @@ const OverlayItem* Rendering::overlayItem(size_t index, OverlayItem::LayoutCorne
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Get the the overlay item (if any) at the given cursor position
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
OverlayItem* Rendering::overlayItemFromWinCoord(uint winCoordX, uint winCoordY)
|
||||
OverlayItem* Rendering::overlayItemFromWindowCoordinates(int x, int y)
|
||||
{
|
||||
// Overlay items are stored OpenGL coord system with (0,0) in lower left corner, so flip the y-coordinate
|
||||
uint oglCoordX = winCoordX;
|
||||
uint oglCoordY = static_cast<int>(m_camera->viewport()->height()) - winCoordY;
|
||||
|
||||
OverlayItemRectMap itemRectMap;
|
||||
calculateOverlayItemLayout(&itemRectMap);
|
||||
|
||||
@ -890,9 +892,9 @@ OverlayItem* Rendering::overlayItemFromWinCoord(uint winCoordX, uint winCoordY)
|
||||
for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it)
|
||||
{
|
||||
OverlayItem* item = it->first;
|
||||
Rectui rect = it->second;
|
||||
Recti rect = it->second;
|
||||
|
||||
if (item->pick(oglCoordX, oglCoordY, rect.min(), Vec2ui(rect.width(), rect.height())))
|
||||
if (item->pick(x, y, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
@ -933,7 +935,7 @@ void Rendering::removeAllOverlayItems()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
String Rendering::toString() const
|
||||
String Rendering::debugString() const
|
||||
{
|
||||
String str = "Rendering: ";
|
||||
str += m_renderingName;
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
FramebufferObject* targetFramebuffer();
|
||||
void setTargetFramebuffer(FramebufferObject* framebuffer);
|
||||
|
||||
ref<RayIntersectSpec> createRayIntersectSpec(int winCoordX, int winCoordY) const;
|
||||
ref<RayIntersectSpec> rayIntersectSpecFromWindowCoordinates(int x, int y) const;
|
||||
bool rayIntersect(RayIntersectSpec& rayIntersectSpec, HitItemCollection* hitItemCollection);
|
||||
|
||||
BoundingBox boundingBox() const;
|
||||
@ -97,7 +97,7 @@ public:
|
||||
void removeDynamicUniformSet(DynamicUniformSet* dynUniformSet);
|
||||
void removeAllDynamicUniformSets();
|
||||
void addGlobalDynamicUniformSet(DynamicUniformSet* dynUniformSet);
|
||||
void removeAllGlobalUniformSets();
|
||||
void removeAllGlobalDynamicUniformSets();
|
||||
|
||||
const PerformanceInfo& performanceInfo() const;
|
||||
void enablePerformanceTiming(bool enable);
|
||||
@ -112,16 +112,16 @@ public:
|
||||
void addOverlayItem(OverlayItem* overlayItem, OverlayItem::LayoutCorner corner, OverlayItem::LayoutDirection direction);
|
||||
OverlayItem* overlayItem(size_t index, OverlayItem::LayoutCorner* corner, OverlayItem::LayoutDirection* direction);
|
||||
const OverlayItem* overlayItem(size_t index, OverlayItem::LayoutCorner* corner, OverlayItem::LayoutDirection* direction) const;
|
||||
OverlayItem* overlayItemFromWinCoord(uint winCoordX, uint winCoordY);
|
||||
OverlayItem* overlayItemFromWindowCoordinates(int x, int y);
|
||||
void removeOverlayItem(const OverlayItem* overlayItem);
|
||||
void removeAllOverlayItems();
|
||||
|
||||
String toString() const;
|
||||
String debugString() const;
|
||||
|
||||
private:
|
||||
void renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRendering);
|
||||
|
||||
typedef std::map<cvf::OverlayItem*, cvf::Rectui> OverlayItemRectMap;
|
||||
typedef std::map<cvf::OverlayItem*, cvf::Recti> OverlayItemRectMap;
|
||||
void calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap);
|
||||
void calculateOverlayItemLayout(OverlayItemRectMap* itemRectMap, OverlayItem::LayoutCorner corner, OverlayItem::LayoutDirection direction);
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "cvfShaderProgram.h"
|
||||
#include "cvfShaderProgramGenerator.h"
|
||||
#include "cvfRenderStateTextureBindings.h"
|
||||
#include "cvfRenderStateDepth.h"
|
||||
|
||||
namespace cvf {
|
||||
|
||||
@ -167,6 +168,7 @@ ref<Rendering> SingleQuadRenderingGenerator::generate()
|
||||
|
||||
ref<ShaderProgram> shaderProg = gen.generate();
|
||||
eff->setShaderProgram(shaderProg.p());
|
||||
eff->setRenderState(new RenderStateDepth(true, RenderStateDepth::LESS, false));
|
||||
|
||||
uint rs;
|
||||
for (rs = 0; rs < m_renderStateSet.count(); rs++)
|
||||
|
@ -49,23 +49,27 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
{
|
||||
if (! inputEvent) return false;
|
||||
bool isEventHandled = false;
|
||||
|
||||
switch (inputEvent->type())
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (me->button() == Qt::MidButton)
|
||||
{
|
||||
if (me->modifiers() & Qt::ShiftModifier)
|
||||
{
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, me->x(), me->y());
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
||||
m_isRotating = true;
|
||||
isEventHandled = true;
|
||||
}
|
||||
else if (me->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
cvf::HitItemCollection hic;
|
||||
bool hitSomething = m_viewer->rayPick(me->x(), me->y(), &hic);
|
||||
bool hitSomething = m_viewer->rayPick(translatedMousePosX, translatedMousePosY, &hic);
|
||||
|
||||
if (hitSomething)
|
||||
{
|
||||
@ -78,7 +82,7 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
initializeRotationCenter();
|
||||
}
|
||||
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, me->x(), me->y());
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
||||
//m_viewer->setCursor(RICursors::get(RICursors::ROTATE));
|
||||
m_isRotating = true;
|
||||
isEventHandled = true;
|
||||
@ -107,9 +111,12 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (m_isRotating)
|
||||
{
|
||||
bool needRedraw = m_trackball->updateNavigation(me->x(), me->y());
|
||||
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
||||
if (needRedraw)
|
||||
{
|
||||
m_viewer->update();
|
||||
@ -126,12 +133,15 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
initializeRotationCenter();
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
||||
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
||||
int translatedMousePosX = we->x();
|
||||
int translatedMousePosY = m_viewer->height() - we->y();
|
||||
|
||||
cvf::ref<cvf::Ray> ray;
|
||||
if (we->delta() > 0)
|
||||
ray = m_viewer->mainCamera()->rayFromWinCoord(we->x(), we->y());
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
else
|
||||
ray = m_viewer->mainCamera()->rayFromWinCoord((int)(1.0*we->x()), (int)(1.0*we->y()));
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates((int)(1.0*translatedMousePosX), (int)(1.0*translatedMousePosY));
|
||||
|
||||
if (ray.notNull() && abs(we->delta()) > 0)
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ void caf::CeetronNavigation::mouseMoveEvent(QMouseEvent* event)
|
||||
if (!m_viewer->canRender()) return;
|
||||
initializeRotationCenter();
|
||||
int posX = event->x();
|
||||
int posY = event->y();
|
||||
int posY = m_viewer->height() - event->y();
|
||||
|
||||
ManipulatorTrackball::NavigationType navType = getNavigationTypeFromMouseButtons(event->buttons());
|
||||
if (navType != m_trackball->activeNavigation())
|
||||
@ -137,7 +137,7 @@ void caf::CeetronNavigation::mousePressEvent(QMouseEvent* event)
|
||||
if (!m_viewer->canRender()) return;
|
||||
initializeRotationCenter();
|
||||
int posX = event->x();
|
||||
int posY = event->y();
|
||||
int posY = m_viewer->height() - event->y();
|
||||
|
||||
ManipulatorTrackball::NavigationType navType = getNavigationTypeFromMouseButtons(event->buttons());
|
||||
m_trackball->startNavigation(navType, posX, posY);
|
||||
@ -176,16 +176,18 @@ void caf::CeetronNavigation::wheelEvent(QWheelEvent* event)
|
||||
int navDelta = vpHeight/5;
|
||||
if (event->delta() < 0) navDelta *= -1;
|
||||
|
||||
int posY = m_viewer->height() - event->y();
|
||||
|
||||
if (m_viewer->mainCamera()->projection() == cvf::Camera::PERSPECTIVE)
|
||||
{
|
||||
m_trackball->startNavigation(ManipulatorTrackball::WALK, event->x(), event->y());
|
||||
m_trackball->startNavigation(ManipulatorTrackball::WALK, event->x(), posY);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_trackball->startNavigation(ManipulatorTrackball::ZOOM, event->x(), event->y());
|
||||
m_trackball->startNavigation(ManipulatorTrackball::ZOOM, event->x(), posY);
|
||||
}
|
||||
|
||||
m_trackball->updateNavigation(event->x(), event->y() - navDelta);
|
||||
m_trackball->updateNavigation(event->x(), posY + navDelta);
|
||||
m_trackball->endNavigation();
|
||||
|
||||
m_viewer->update();
|
||||
|
@ -324,8 +324,10 @@ bool caf::Viewer::rayPick(int winPosX, int winPosY, cvf::HitItemCollection* pick
|
||||
{
|
||||
CVF_ASSERT(m_mainRendering.notNull());
|
||||
|
||||
int translatedMousePosX = winPosX;
|
||||
int translatedMousePosY = height() - winPosY;
|
||||
|
||||
cvf::ref<cvf::RayIntersectSpec> ris = m_mainRendering->createRayIntersectSpec(winPosX, winPosY);
|
||||
cvf::ref<cvf::RayIntersectSpec> ris = m_mainRendering->rayIntersectSpecFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
if (ris.notNull())
|
||||
{
|
||||
bool retVal = m_mainRendering->rayIntersect(*ris, pickedPoints);
|
||||
@ -545,9 +547,8 @@ void caf::Viewer::releaseOGlResourcesForCurrentFrame()
|
||||
{
|
||||
cvf::Scene* currentScene = m_renderingSequence->firstRendering()->scene();
|
||||
makeCurrent();
|
||||
size_t modelCount = currentScene->modelCount();
|
||||
size_t i;
|
||||
for (i = 0; i < modelCount; ++i)
|
||||
cvf::uint modelCount = currentScene->modelCount();
|
||||
for (cvf::uint i = 0; i < modelCount; ++i)
|
||||
{
|
||||
cvf::Collection<cvf::Part> partCollection;
|
||||
currentScene->model(i)->allParts(&partCollection);
|
||||
|
Loading…
Reference in New Issue
Block a user