mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0023226: Extend OpenGl_Context to store map of shared GPU resources
OpenGl_Resource was slightly corrected and OpenGl_Element was extended with Release method to manage GPU resources. OpenGl_PrimitiveArray now uses new OpenGl_VertexBuffer class (requires OpenGL 1.5+). Strange workarounds for feedback mode were removed. OpenGl_Context now provides access to shared GPU resources and manages resources queue for delayed release (replaces functionality of removed OpenGl_ResourceCleaner). Loaded GL_ARB_texture_buffer_object and GL_ARB_draw_instanced extensions. Global maps of views, workspaces and structures were moved to OpenGl_GraphicDriver members. UserDrawCallback() function moved to OpenGl_GraphicDriver methods. Aspect_GraphicCallbackStruct now holds handle of OpenGl_Context instead of system-dependent pointers to GL context definition. New classes NCollection_Vec2, NCollection_Vec3 and NCollection_Vec4 implements interface to low-level data (points, vertices, colors) in GLSL-style. Removed EnableVBO argument from vdrawparray Draw Harness command Corrected compilation errors Fixed wrong argument in Index VBO initialization Fixed several cases of incorrect memory management in TKV3d Visual3d_ViewManager::Remove() Destroy structures before last view removed for correct GPU resources management. Graphic3d_Structure::GraphicClear() Remove groups to avoid usage of dead OpenGl_Group pointers. V3d_View::Remove() Fixed mistake in #0000280 patch. Small correction Fixed OCC280 test command Replace removed view within created one in ViewerTest EventManager. ViewerTest, do not create unused 3D view In current design NIS_View always created and used for both - NIS objects and AIS objects.
This commit is contained in:
@@ -80,3 +80,6 @@ NCollection_Haft.h
|
||||
NCollection_DefaultHasher.hxx
|
||||
NCollection_DefineAlloc.hxx
|
||||
|
||||
NCollection_Vec2.hxx
|
||||
NCollection_Vec3.hxx
|
||||
NCollection_Vec4.hxx
|
||||
|
230
src/NCollection/NCollection_Vec2.hxx
Normal file
230
src/NCollection/NCollection_Vec2.hxx
Normal file
@@ -0,0 +1,230 @@
|
||||
// Created by: Kirill GAVRILOV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _NCollection_Vec2_H__
|
||||
#define _NCollection_Vec2_H__
|
||||
|
||||
//! Auxiliary macros to define couple of similar access components as vector methods.
|
||||
//! @return 2 components by their names in specified order
|
||||
#define NCOLLECTION_VEC_COMPONENTS_2D(theX, theY) \
|
||||
const NCollection_Vec2<Element_t> theX##theY##() const { return NCollection_Vec2<Element_t>(theX##(), theY##()); } \
|
||||
const NCollection_Vec2<Element_t> theY##theX##() const { return NCollection_Vec2<Element_t>(theY##(), theX##()); }
|
||||
|
||||
//! Defines the 2D-vector template.
|
||||
//! The main target for this class - to handle raw low-level arrays (from/to graphic driver etc.).
|
||||
template<typename Element_t>
|
||||
class NCollection_Vec2
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Returns the number of components.
|
||||
static int Length()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
//! Empty constructor. Construct the zero vector.
|
||||
NCollection_Vec2()
|
||||
{
|
||||
v[0] = v[1] = Element_t(0);
|
||||
}
|
||||
|
||||
//! Initialize ALL components of vector within specified value.
|
||||
explicit NCollection_Vec2 (const Element_t theXY)
|
||||
{
|
||||
v[0] = v[1] = theXY;
|
||||
}
|
||||
|
||||
//! Per-component constructor.
|
||||
explicit NCollection_Vec2 (const Element_t theX,
|
||||
const Element_t theY)
|
||||
{
|
||||
v[0] = theX;
|
||||
v[1] = theY;
|
||||
}
|
||||
|
||||
//! Copy constructor.
|
||||
NCollection_Vec2 (const NCollection_Vec2& theVec2)
|
||||
{
|
||||
v[0] = theVec2[0];
|
||||
v[1] = theVec2[1];
|
||||
}
|
||||
|
||||
//! Assignment operator.
|
||||
const NCollection_Vec2& operator= (const NCollection_Vec2& theVec2)
|
||||
{
|
||||
v[0] = theVec2[0];
|
||||
v[1] = theVec2[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Alias to 1st component as X coordinate in XY.
|
||||
Element_t x() const { return v[0]; }
|
||||
|
||||
//! Alias to 2nd component as Y coordinate in XY.
|
||||
Element_t y() const { return v[1]; }
|
||||
|
||||
//! @return 2 components by their names in specified order (in GLSL-style)
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(x, y);
|
||||
|
||||
//! Alias to 1st component as X coordinate in XY.
|
||||
Element_t& x() { return v[0]; }
|
||||
|
||||
//! Alias to 2nd component as Y coordinate in XY.
|
||||
Element_t& y() { return v[1]; }
|
||||
|
||||
//! Raw access to the data (to simplify OpenGL exchange).
|
||||
const Element_t* GetData() const { return v; }
|
||||
operator const Element_t*() const { return v; }
|
||||
operator Element_t*() { return v; }
|
||||
|
||||
//! Compute per-component summary.
|
||||
NCollection_Vec2& operator+= (const NCollection_Vec2& theAdd)
|
||||
{
|
||||
v[0] += theAdd.v[0];
|
||||
v[1] += theAdd.v[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component summary.
|
||||
friend NCollection_Vec2 operator+ (const NCollection_Vec2& theLeft,
|
||||
const NCollection_Vec2& theRight)
|
||||
{
|
||||
return NCollection_Vec2 (theLeft.v[0] + theRight.v[0],
|
||||
theLeft.v[1] + theRight.v[1]);
|
||||
}
|
||||
|
||||
//! Compute per-component subtraction.
|
||||
NCollection_Vec2& operator-= (const NCollection_Vec2& theDec)
|
||||
{
|
||||
v[0] -= theDec.v[0];
|
||||
v[1] -= theDec.v[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component subtraction.
|
||||
friend NCollection_Vec2 operator- (const NCollection_Vec2& theLeft,
|
||||
const NCollection_Vec2& theRight)
|
||||
{
|
||||
return NCollection_Vec2 (theLeft.v[0] - theRight.v[0],
|
||||
theLeft.v[1] - theRight.v[1]);
|
||||
}
|
||||
|
||||
//! Unary -.
|
||||
NCollection_Vec2 operator-() const
|
||||
{
|
||||
return NCollection_Vec2 (-x(), -y());
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
NCollection_Vec2& operator*= (const NCollection_Vec2& theRight)
|
||||
{
|
||||
v[0] *= theRight.v[0];
|
||||
v[1] *= theRight.v[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
friend NCollection_Vec2 operator* (const NCollection_Vec2& theLeft,
|
||||
const NCollection_Vec2& theRight)
|
||||
{
|
||||
return NCollection_Vec2 (theLeft.v[0] * theRight.v[0],
|
||||
theLeft.v[1] * theRight.v[1]);
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
void Multiply (const Element_t theFactor)
|
||||
{
|
||||
v[0] *= theFactor;
|
||||
v[1] *= theFactor;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
NCollection_Vec2 Multiplied (const Element_t theFactor) const
|
||||
{
|
||||
return NCollection_Vec2 (v[0] * theFactor,
|
||||
v[1] * theFactor);
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
NCollection_Vec2& operator*= (const Element_t theFactor)
|
||||
{
|
||||
Multiply (theFactor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component division by scale factor.
|
||||
NCollection_Vec2& operator/= (const Element_t theInvFactor)
|
||||
{
|
||||
v[0] /= theInvFactor;
|
||||
v[1] /= theInvFactor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
NCollection_Vec2 operator* (const Element_t theFactor) const
|
||||
{
|
||||
return Multiplied (theFactor);
|
||||
}
|
||||
|
||||
//! Compute per-component division by scale factor.
|
||||
NCollection_Vec2 operator/ (const Element_t theInvFactor) const
|
||||
{
|
||||
return NCollection_Vec2(v[0] / theInvFactor,
|
||||
v[1] / theInvFactor);
|
||||
}
|
||||
|
||||
//! Computes the dot product.
|
||||
Element_t Dot (const NCollection_Vec2& theOther) const
|
||||
{
|
||||
return x() * theOther.x() + y() * theOther.y();
|
||||
}
|
||||
|
||||
//! Computes the vector modulus (magnitude, length).
|
||||
Element_t Modulus() const
|
||||
{
|
||||
return std::sqrt (x() * x() + y() * y());
|
||||
}
|
||||
|
||||
//! Computes the square of vector modulus (magnitude, length).
|
||||
//! This method may be used for performance tricks.
|
||||
Element_t SquareModulus() const
|
||||
{
|
||||
return x() * x() + y() * y();
|
||||
}
|
||||
|
||||
//! Constuct DX unit vector.
|
||||
static NCollection_Vec2 DX()
|
||||
{
|
||||
return NCollection_Vec2 (Element_t(1), Element_t(0));
|
||||
}
|
||||
|
||||
//! Constuct DY unit vector.
|
||||
static NCollection_Vec2 DY()
|
||||
{
|
||||
return NCollection_Vec2 (Element_t(0), Element_t(1));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Element_t v[2];
|
||||
|
||||
};
|
||||
|
||||
#endif // _NCollection_Vec2_H__
|
352
src/NCollection/NCollection_Vec3.hxx
Normal file
352
src/NCollection/NCollection_Vec3.hxx
Normal file
@@ -0,0 +1,352 @@
|
||||
// Created by: Kirill GAVRILOV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _NCollection_Vec3_H__
|
||||
#define _NCollection_Vec3_H__
|
||||
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <NCollection_Vec2.hxx>
|
||||
|
||||
//! Auxiliary macros to define couple of similar access components as vector methods
|
||||
#define NCOLLECTION_VEC_COMPONENTS_3D(theX, theY, theZ) \
|
||||
const NCollection_Vec3<Element_t> theX##theY##theZ##() const { return NCollection_Vec3<Element_t>(theX##(), theY##(), theZ##()); } \
|
||||
const NCollection_Vec3<Element_t> theX##theZ##theY##() const { return NCollection_Vec3<Element_t>(theX##(), theZ##(), theY##()); } \
|
||||
const NCollection_Vec3<Element_t> theY##theX##theZ##() const { return NCollection_Vec3<Element_t>(theY##(), theX##(), theZ##()); } \
|
||||
const NCollection_Vec3<Element_t> theY##theZ##theX##() const { return NCollection_Vec3<Element_t>(theY##(), theZ##(), theX##()); } \
|
||||
const NCollection_Vec3<Element_t> theZ##theY##theX##() const { return NCollection_Vec3<Element_t>(theZ##(), theY##(), theX##()); } \
|
||||
const NCollection_Vec3<Element_t> theZ##theX##theY##() const { return NCollection_Vec3<Element_t>(theZ##(), theX##(), theY##()); }
|
||||
|
||||
//! Generic 3-components vector.
|
||||
//! To be used as RGB color pixel or XYZ 3D-point.
|
||||
//! The main target for this class - to handle raw low-level arrays (from/to graphic driver etc.).
|
||||
template<typename Element_t>
|
||||
class NCollection_Vec3
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Returns the number of components.
|
||||
static int Length()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
//! Empty constructor. Construct the zero vector.
|
||||
NCollection_Vec3()
|
||||
{
|
||||
std::memset (this, 0, sizeof(NCollection_Vec3));
|
||||
}
|
||||
|
||||
//! Initialize ALL components of vector within specified value.
|
||||
explicit NCollection_Vec3 (Element_t theValue)
|
||||
{
|
||||
v[0] = v[1] = v[2] = theValue;
|
||||
}
|
||||
|
||||
//! Per-component constructor.
|
||||
explicit NCollection_Vec3 (const Element_t theX,
|
||||
const Element_t theY,
|
||||
const Element_t theZ)
|
||||
{
|
||||
v[0] = theX;
|
||||
v[1] = theY;
|
||||
v[2] = theZ;
|
||||
}
|
||||
|
||||
//! Constructor from 2-components vector.
|
||||
explicit NCollection_Vec3 (const NCollection_Vec2<Element_t>& theVec2)
|
||||
{
|
||||
v[0] = theVec2[0];
|
||||
v[1] = theVec2[1];
|
||||
v[2] = Element_t(0);
|
||||
}
|
||||
|
||||
//! Copy constructor.
|
||||
NCollection_Vec3 (const NCollection_Vec3& theVec3)
|
||||
{
|
||||
std::memcpy (this, &theVec3, sizeof(NCollection_Vec3));
|
||||
}
|
||||
|
||||
//! Assignment operator.
|
||||
const NCollection_Vec3& operator= (const NCollection_Vec3& theVec3)
|
||||
{
|
||||
std::memcpy (this, &theVec3, sizeof(NCollection_Vec3));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Alias to 1st component as X coordinate in XYZ.
|
||||
Element_t x() const { return v[0]; }
|
||||
|
||||
//! Alias to 1st component as RED channel in RGB.
|
||||
Element_t r() const { return v[0]; }
|
||||
|
||||
//! Alias to 2nd component as Y coordinate in XYZ.
|
||||
Element_t y() const { return v[1]; }
|
||||
|
||||
//! Alias to 2nd component as GREEN channel in RGB.
|
||||
Element_t g() const { return v[1]; }
|
||||
|
||||
//! Alias to 3rd component as Z coordinate in XYZ.
|
||||
Element_t z() const { return v[2]; }
|
||||
|
||||
//! Alias to 3rd component as BLUE channel in RGB.
|
||||
Element_t b() const { return v[2]; }
|
||||
|
||||
//! @return 2 components by their names in specified order (in GLSL-style)
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(x, y);
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(x, z);
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(y, z);
|
||||
|
||||
//! @return 3 components by their names in specified order (in GLSL-style)
|
||||
NCOLLECTION_VEC_COMPONENTS_3D(x, y, z);
|
||||
|
||||
//! Alias to 1st component as X coordinate in XYZ.
|
||||
Element_t& x() { return v[0]; }
|
||||
|
||||
//! Alias to 1st component as RED channel in RGB.
|
||||
Element_t& r() { return v[0]; }
|
||||
|
||||
//! Alias to 2nd component as Y coordinate in XYZ.
|
||||
Element_t& y() { return v[1]; }
|
||||
|
||||
//! Alias to 2nd component as GREEN channel in RGB.
|
||||
Element_t& g() { return v[1]; }
|
||||
|
||||
//! Alias to 3rd component as Z coordinate in XYZ.
|
||||
Element_t& z() { return v[2]; }
|
||||
|
||||
//! Alias to 3rd component as BLUE channel in RGB.
|
||||
Element_t& b() { return v[2]; }
|
||||
|
||||
//! @return XY-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& xy()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[0]);
|
||||
}
|
||||
|
||||
//! @return YZ-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& yz()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[1]);
|
||||
}
|
||||
|
||||
//! Raw access to the data (for OpenGL exchange).
|
||||
const Element_t* GetData() const { return v; }
|
||||
operator const Element_t*() const { return v; }
|
||||
operator Element_t*() { return v; }
|
||||
|
||||
//! Compute per-component summary.
|
||||
NCollection_Vec3& operator+= (const NCollection_Vec3& theAdd)
|
||||
{
|
||||
v[0] += theAdd.v[0];
|
||||
v[1] += theAdd.v[1];
|
||||
v[2] += theAdd.v[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component summary.
|
||||
friend NCollection_Vec3 operator+ (const NCollection_Vec3& theLeft,
|
||||
const NCollection_Vec3& theRight)
|
||||
{
|
||||
NCollection_Vec3 aSumm = NCollection_Vec3 (theLeft);
|
||||
return aSumm += theRight;
|
||||
}
|
||||
|
||||
//! Unary -.
|
||||
NCollection_Vec3 operator-() const
|
||||
{
|
||||
return NCollection_Vec3 (-x(), -y(), -z());
|
||||
}
|
||||
|
||||
//! Compute per-component subtraction.
|
||||
NCollection_Vec3& operator-= (const NCollection_Vec3& theDec)
|
||||
{
|
||||
v[0] -= theDec.v[0];
|
||||
v[1] -= theDec.v[1];
|
||||
v[2] -= theDec.v[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component subtraction.
|
||||
friend NCollection_Vec3 operator- (const NCollection_Vec3& theLeft,
|
||||
const NCollection_Vec3& theRight)
|
||||
{
|
||||
NCollection_Vec3 aSumm = NCollection_Vec3 (theLeft);
|
||||
return aSumm -= theRight;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
void Multiply (const Element_t theFactor)
|
||||
{
|
||||
v[0] *= theFactor;
|
||||
v[1] *= theFactor;
|
||||
v[2] *= theFactor;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
NCollection_Vec3& operator*= (const NCollection_Vec3& theRight)
|
||||
{
|
||||
v[0] *= theRight.v[0];
|
||||
v[1] *= theRight.v[1];
|
||||
v[2] *= theRight.v[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
friend NCollection_Vec3 operator* (const NCollection_Vec3& theLeft,
|
||||
const NCollection_Vec3& theRight)
|
||||
{
|
||||
NCollection_Vec3 aResult = NCollection_Vec3 (theLeft);
|
||||
return aResult *= theRight;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
NCollection_Vec3& operator*= (const Element_t theFactor)
|
||||
{
|
||||
Multiply (theFactor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
NCollection_Vec3 operator* (const Element_t theFactor) const
|
||||
{
|
||||
return Multiplied (theFactor);
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication by scale factor.
|
||||
NCollection_Vec3 Multiplied (const Element_t theFactor) const
|
||||
{
|
||||
NCollection_Vec3 aCopyVec3 (*this);
|
||||
aCopyVec3 *= theFactor;
|
||||
return aCopyVec3;
|
||||
}
|
||||
|
||||
//! Compute per-component division by scale factor.
|
||||
NCollection_Vec3& operator/= (const Element_t theInvFactor)
|
||||
{
|
||||
v[0] /= theInvFactor;
|
||||
v[1] /= theInvFactor;
|
||||
v[2] /= theInvFactor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component division by scale factor.
|
||||
NCollection_Vec3 operator/ (const Element_t theInvFactor)
|
||||
{
|
||||
NCollection_Vec3 aResult (this);
|
||||
return aResult /= theInvFactor;
|
||||
}
|
||||
|
||||
//! Computes the dot product.
|
||||
Element_t Dot (const NCollection_Vec3& theOther) const
|
||||
{
|
||||
return x() * theOther.x() + y() * theOther.y() + z() * theOther.z();
|
||||
}
|
||||
|
||||
//! Computes the vector modulus (magnitude, length).
|
||||
Element_t Modulus() const
|
||||
{
|
||||
return std::sqrt (x() * x() + y() * y() + z() * z());
|
||||
}
|
||||
|
||||
//! Computes the square of vector modulus (magnitude, length).
|
||||
//! This method may be used for performance tricks.
|
||||
Element_t SquareModulus() const
|
||||
{
|
||||
return x() * x() + y() * y() + z() * z();
|
||||
}
|
||||
|
||||
//! Normalize the vector.
|
||||
void Normalize()
|
||||
{
|
||||
Element_t aModulus = Modulus();
|
||||
if (aModulus != Element_t(0)) // just avoid divide by zero
|
||||
{
|
||||
x() = x() / aModulus;
|
||||
y() = y() / aModulus;
|
||||
z() = z() / aModulus;
|
||||
}
|
||||
}
|
||||
|
||||
//! Normalize the vector.
|
||||
NCollection_Vec3 Normalized() const
|
||||
{
|
||||
NCollection_Vec3 aCopy (*this);
|
||||
aCopy.Normalize();
|
||||
return aCopy;
|
||||
}
|
||||
|
||||
//! Computes the cross product.
|
||||
static NCollection_Vec3 Cross (const NCollection_Vec3& theVec1,
|
||||
const NCollection_Vec3& theVec2)
|
||||
{
|
||||
return NCollection_Vec3(theVec1.y() * theVec2.z() - theVec1.z() * theVec2.y(),
|
||||
theVec1.z() * theVec2.x() - theVec1.x() * theVec2.z(),
|
||||
theVec1.x() * theVec2.y() - theVec1.y() * theVec2.x());
|
||||
}
|
||||
|
||||
//! Compute linear interpolation between to vectors.
|
||||
//! @param theT - interpolation coefficient 0..1;
|
||||
//! @return interpolation result.
|
||||
static NCollection_Vec3 GetLERP (const NCollection_Vec3& theFrom,
|
||||
const NCollection_Vec3& theTo,
|
||||
const Element_t theT)
|
||||
{
|
||||
return theFrom * (Element_t(1) - theT) + theTo * theT;
|
||||
}
|
||||
|
||||
//! Constuct DX unit vector.
|
||||
static NCollection_Vec3 DX()
|
||||
{
|
||||
return NCollection_Vec3 (Element_t(1), Element_t(0), Element_t(0));
|
||||
}
|
||||
|
||||
//! Constuct DY unit vector.
|
||||
static NCollection_Vec3 DY()
|
||||
{
|
||||
return NCollection_Vec3 (Element_t(0), Element_t(1), Element_t(0));
|
||||
}
|
||||
|
||||
//! Constuct DZ unit vector.
|
||||
static NCollection_Vec3 DZ()
|
||||
{
|
||||
return NCollection_Vec3 (Element_t(0), Element_t(0), Element_t(1));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Element_t v[3]; //!< define the vector as array to avoid structure alignment issues
|
||||
|
||||
};
|
||||
|
||||
//! Optimized concretization for float type.
|
||||
template<> inline NCollection_Vec3<float>& NCollection_Vec3<float>::operator/= (const float theInvFactor)
|
||||
{
|
||||
Multiply (1.0f / theInvFactor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Optimized concretization for double type.
|
||||
template<> inline NCollection_Vec3<double>& NCollection_Vec3<double>::operator/= (const double theInvFactor)
|
||||
{
|
||||
Multiply (1.0 / theInvFactor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // _NCollection_Vec3_H__
|
321
src/NCollection/NCollection_Vec4.hxx
Normal file
321
src/NCollection/NCollection_Vec4.hxx
Normal file
@@ -0,0 +1,321 @@
|
||||
// Created by: Kirill GAVRILOV
|
||||
// Copyright (c) 2012 OPEN CASCADE SAS
|
||||
//
|
||||
// The content of this file is subject to the Open CASCADE Technology Public
|
||||
// License Version 6.5 (the "License"). You may not use the content of this file
|
||||
// except in compliance with the License. Please obtain a copy of the License
|
||||
// at http://www.opencascade.org and read it completely before using this file.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
||||
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
||||
//
|
||||
// The Original Code and all software distributed under the License is
|
||||
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
||||
// Initial Developer hereby disclaims all such warranties, including without
|
||||
// limitation, any warranties of merchantability, fitness for a particular
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
#ifndef _NCollection_Vec4_H__
|
||||
#define _NCollection_Vec4_H__
|
||||
|
||||
#include <NCollection_Vec3.hxx>
|
||||
|
||||
//! Generic 4-components vector.
|
||||
//! To be used as RGBA color vector or XYZW 3D-point with special W-component
|
||||
//! for operations with projection / model view matrices.
|
||||
//! Use this class for 3D-points carefully because declared W-component may
|
||||
//! results in incorrect results if used without matrices.
|
||||
template<typename Element_t>
|
||||
class NCollection_Vec4
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Returns the number of components.
|
||||
static size_t Length()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
//! Empty constructor. Construct the zero vector.
|
||||
NCollection_Vec4()
|
||||
{
|
||||
std::memset (this, 0, sizeof(NCollection_Vec4));
|
||||
}
|
||||
|
||||
//! Initialize ALL components of vector within specified value.
|
||||
explicit NCollection_Vec4 (const Element_t theValue)
|
||||
{
|
||||
v[0] = v[1] = v[2] = v[3] = theValue;
|
||||
}
|
||||
|
||||
//! Per-component constructor.
|
||||
explicit NCollection_Vec4 (const Element_t theX,
|
||||
const Element_t theY,
|
||||
const Element_t theZ,
|
||||
const Element_t theW)
|
||||
{
|
||||
v[0] = theX;
|
||||
v[1] = theY;
|
||||
v[2] = theZ;
|
||||
v[3] = theW;
|
||||
}
|
||||
|
||||
//! Constructor from 2-components vector.
|
||||
explicit NCollection_Vec4 (const NCollection_Vec2<Element_t>& theVec2)
|
||||
{
|
||||
v[0] = theVec2[0];
|
||||
v[1] = theVec2[1];
|
||||
v[2] = v[3] = Element_t (0);
|
||||
}
|
||||
|
||||
//! Constructor from 3-components vector.
|
||||
explicit NCollection_Vec4(const NCollection_Vec3<Element_t>& theVec3)
|
||||
{
|
||||
std::memcpy (this, &theVec3, sizeof(NCollection_Vec3<Element_t>));
|
||||
v[3] = Element_t (0);
|
||||
}
|
||||
|
||||
//! Constructor from 3-components vector + alpha value.
|
||||
explicit NCollection_Vec4(const NCollection_Vec3<Element_t>& theVec3,
|
||||
const Element_t theAlpha) {
|
||||
std::memcpy (this, &theVec3, sizeof(NCollection_Vec3<Element_t>));
|
||||
v[3] = theAlpha;
|
||||
}
|
||||
|
||||
//! Copy constructor.
|
||||
NCollection_Vec4 (const NCollection_Vec4& theVec4)
|
||||
{
|
||||
std::memcpy (this, &theVec4, sizeof(NCollection_Vec4));
|
||||
}
|
||||
|
||||
//! Assignment operator.
|
||||
const NCollection_Vec4& operator= (const NCollection_Vec4& theVec4)
|
||||
{
|
||||
std::memcpy (this, &theVec4, sizeof(NCollection_Vec4));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Alias to 1st component as X coordinate in XYZW.
|
||||
Element_t x() const { return v[0]; }
|
||||
|
||||
//! Alias to 1st component as RED channel in RGBA.
|
||||
Element_t r() const { return v[0]; }
|
||||
|
||||
//! Alias to 2nd component as Y coordinate in XYZW.
|
||||
Element_t y() const { return v[1]; }
|
||||
|
||||
//! Alias to 2nd component as GREEN channel in RGBA.
|
||||
Element_t g() const { return v[1]; }
|
||||
|
||||
//! Alias to 3rd component as Z coordinate in XYZW.
|
||||
Element_t z() const { return v[2]; }
|
||||
|
||||
//! Alias to 3rd component as BLUE channel in RGBA.
|
||||
Element_t b() const { return v[2]; }
|
||||
|
||||
//! Alias to 4th component as W coordinate in XYZW.
|
||||
Element_t w() const { return v[3]; }
|
||||
|
||||
//! Alias to 4th component as ALPHA channel in RGBA.
|
||||
Element_t a() const { return v[3]; }
|
||||
|
||||
//! @return 2 of XYZW components in specified order as vector in GLSL-style
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(x, y);
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(x, z);
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(x, w);
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(y, z);
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(y, w);
|
||||
NCOLLECTION_VEC_COMPONENTS_2D(z, w);
|
||||
|
||||
//! @return 3 of XYZW components in specified order as vector in GLSL-style
|
||||
NCOLLECTION_VEC_COMPONENTS_3D(x, y, z);
|
||||
NCOLLECTION_VEC_COMPONENTS_3D(x, y, w);
|
||||
NCOLLECTION_VEC_COMPONENTS_3D(x, z, w);
|
||||
NCOLLECTION_VEC_COMPONENTS_3D(y, z, w);
|
||||
|
||||
//! @return RGB components as vector
|
||||
NCOLLECTION_VEC_COMPONENTS_3D(r, g, b);
|
||||
|
||||
//! Alias to 1st component as X coordinate in XYZW.
|
||||
Element_t& x() { return v[0]; }
|
||||
|
||||
//! Alias to 1st component as RED channel in RGBA.
|
||||
Element_t& r() { return v[0]; }
|
||||
|
||||
//! Alias to 2nd component as Y coordinate in XYZW.
|
||||
Element_t& y() { return v[1]; }
|
||||
|
||||
//! Alias to 2nd component as GREEN channel in RGBA.
|
||||
Element_t& g() { return v[1]; } // Green color
|
||||
|
||||
//! Alias to 3rd component as Z coordinate in XYZW.
|
||||
Element_t& z() { return v[2]; }
|
||||
|
||||
//! Alias to 3rd component as BLUE channel in RGBA.
|
||||
Element_t& b() { return v[2]; }
|
||||
|
||||
//! Alias to 4th component as W coordinate in XYZW.
|
||||
Element_t& w() { return v[3]; }
|
||||
|
||||
//! Alias to 4th component as ALPHA channel in RGBA.
|
||||
Element_t& a() { return v[3]; }
|
||||
|
||||
//! @return XY-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& xy()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[0]);
|
||||
}
|
||||
|
||||
//! @return YZ-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& yz()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[1]);
|
||||
}
|
||||
|
||||
//! @return YZ-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& zw()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[2]);
|
||||
}
|
||||
|
||||
//! @return XYZ-components modifiable vector
|
||||
NCollection_Vec3<Element_t>& xyz()
|
||||
{
|
||||
return *((NCollection_Vec3<Element_t>* )&v[0]);
|
||||
}
|
||||
|
||||
//! @return YZW-components modifiable vector
|
||||
NCollection_Vec3<Element_t>& yzw()
|
||||
{
|
||||
return *((NCollection_Vec3<Element_t>* )&v[1]);
|
||||
}
|
||||
|
||||
//! Raw access to the data (for OpenGL exchange).
|
||||
const Element_t* GetData() const { return v; }
|
||||
operator const Element_t*() const { return v; }
|
||||
operator Element_t*() { return v; }
|
||||
|
||||
//! Compute per-component summary.
|
||||
NCollection_Vec4& operator+= (const NCollection_Vec4& theAdd)
|
||||
{
|
||||
v[0] += theAdd.v[0];
|
||||
v[1] += theAdd.v[1];
|
||||
v[2] += theAdd.v[2];
|
||||
v[3] += theAdd.v[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component summary.
|
||||
friend NCollection_Vec4 operator+ (const NCollection_Vec4& theLeft,
|
||||
const NCollection_Vec4& theRight)
|
||||
{
|
||||
NCollection_Vec4 aSumm = NCollection_Vec4 (theLeft);
|
||||
return aSumm += theRight;
|
||||
}
|
||||
|
||||
//! Compute per-component subtraction.
|
||||
NCollection_Vec4& operator-= (const NCollection_Vec4& theDec)
|
||||
{
|
||||
v[0] -= theDec.v[0];
|
||||
v[1] -= theDec.v[1];
|
||||
v[2] -= theDec.v[2];
|
||||
v[3] -= theDec.v[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component subtraction.
|
||||
friend NCollection_Vec4 operator- (const NCollection_Vec4& theLeft,
|
||||
const NCollection_Vec4& theRight)
|
||||
{
|
||||
NCollection_Vec4 aSumm = NCollection_Vec4 (theLeft);
|
||||
return aSumm -= theRight;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
NCollection_Vec4& operator*= (const NCollection_Vec4& theRight)
|
||||
{
|
||||
v[0] *= theRight.v[0];
|
||||
v[1] *= theRight.v[1];
|
||||
v[2] *= theRight.v[2];
|
||||
v[3] *= theRight.v[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
friend NCollection_Vec4 operator* (const NCollection_Vec4& theLeft,
|
||||
const NCollection_Vec4& theRight)
|
||||
{
|
||||
NCollection_Vec4 aResult = NCollection_Vec4 (theLeft);
|
||||
return aResult *= theRight;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
void Multiply (const Element_t theFactor)
|
||||
{
|
||||
v[0] *= theFactor;
|
||||
v[1] *= theFactor;
|
||||
v[2] *= theFactor;
|
||||
v[3] *= theFactor;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
NCollection_Vec4& operator*=(const Element_t theFactor)
|
||||
{
|
||||
Multiply (theFactor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
NCollection_Vec4 operator* (const Element_t theFactor) const
|
||||
{
|
||||
return Multiplied (theFactor);
|
||||
}
|
||||
|
||||
//! Compute per-component multiplication.
|
||||
NCollection_Vec4 Multiplied (const Element_t theFactor) const
|
||||
{
|
||||
NCollection_Vec4 aCopyVec4 (*this);
|
||||
aCopyVec4 *= theFactor;
|
||||
return aCopyVec4;
|
||||
}
|
||||
|
||||
//! Compute per-component division by scale factor.
|
||||
NCollection_Vec4& operator/= (const Element_t theInvFactor)
|
||||
{
|
||||
v[0] /= theInvFactor;
|
||||
v[1] /= theInvFactor;
|
||||
v[2] /= theInvFactor;
|
||||
v[3] /= theInvFactor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Compute per-component division by scale factor.
|
||||
NCollection_Vec4 operator/ (const Element_t theInvFactor)
|
||||
{
|
||||
NCollection_Vec4 aResult(this);
|
||||
return aResult /= theInvFactor;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Element_t v[4]; //!< define the vector as array to avoid structure alignment issues
|
||||
|
||||
};
|
||||
|
||||
//! Optimized concretization for float type.
|
||||
template<> inline NCollection_Vec4<float>& NCollection_Vec4<float>::operator/= (const float theInvFactor)
|
||||
{
|
||||
Multiply (1.0f / theInvFactor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Optimized concretization for double type.
|
||||
template<> inline NCollection_Vec4<double>& NCollection_Vec4<double>::operator/= (const double theInvFactor)
|
||||
{
|
||||
Multiply (1.0 / theInvFactor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // _NCollection_Vec4_H__
|
Reference in New Issue
Block a user