miaviewit-1.0.5/ 0000755 0001750 0000677 00000000000 13123163373 010525 5 0000000 0000000 miaviewit-1.0.5/configure.ac 0000644 0001750 0000677 00000014520 13123163275 012736 0000000 0000000 # This file is part of viewitgui - a library and program for the
# visualization of 3D data sets.
#
# Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
#
# viewitgui 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.
#
# viewitgui is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with viewitgui; if not, see .
AC_PREREQ(2.59)
AC_CONFIG_MACRO_DIR([m4])
# Making releases:
# libviewit_micro_version += 1
# libviewit_interface_age += 1
# libviewit_binary_age += 1
#
# if the interface has changed, then also do
# libviewit_current_interface += 1
#
# if backwards compatibility has also been broken, then do
#
# libviewit_interface_age = 0
# libviewit_binary_age = 0
#
m4_define([libviewit_major_version], [1])
m4_define([libviewit_minor_version], [0])
m4_define([libviewit_micro_version], [5])
m4_define([libviewit_current_interface], [0])
m4_define([libviewit_interface_age], [5])
m4_define([libviewit_binary_age], [5])
m4_define([libviewit_real_version],
[libviewit_major_version.libviewit_minor_version.libviewit_micro_version])
m4_define([libviewit_version], [libviewit_real_version])
m4_define([libviewit_unstable],
m4_if(m4_eval(libviewit_minor_version % 2), [1], [yes], [no]))
m4_define([libviewit_full_name], [The VIEWIT library])
AC_INIT([miaviewit], [libviewit_version], [gw.fossdev@gmail.com])
AC_CONFIG_SRCDIR([viewit/arrow.cc])
AM_INIT_AUTOMAKE(no-define)
AC_CONFIG_HEADER(config.h)
LIBVIEWIT_MAJOR_VERSION=libviewit_major_version
LIBVIEWIT_MINOR_VERSION=libviewit_minor_version
LIBVIEWIT_MICRO_VERSION=libviewit_micro_version
LIBVIEWIT_INTERFACE_AGE=libviewit_interface_age
LIBVIEWIT_BINARY_AGE=libviewit_binary_age
LIBVIEWIT_VERSION=libviewit_version
LIBVIEWIT_UNSTABLE=libviewit_unstable
AC_SUBST(LIBVIEWIT_MAJOR_VERSION)
AC_SUBST(LIBVIEWIT_MINOR_VERSION)
AC_SUBST(LIBVIEWIT_MICRO_VERSION)
AC_SUBST(LIBVIEWIT_INTERFACE_AGE)
AC_SUBST(LIBVIEWIT_BINARY_AGE)
AC_SUBST(LIBVIEWIT_VERSION)
AC_SUBST(LIBVIEWIT_UNSTABLE)
AC_SUBST(NAME_VERSION)
dnl The symbol LIBVIEWIT_UNSTABLE is defined above for substitution in
dnl Makefiles and conditionally defined here as a preprocessor symbol.
if test "x$LIBVIEWIT_UNSTABLE" = "xyes"; then
AC_DEFINE(LIBVIEWIT_UNSTABLE,1,
[Define to 1 if this is an unstable version of the libviewit])
fi
# libtool versioning
m4_define([lt_release], [libviewit_major_version.libviewit_minor_version])
m4_define([lt_current], [libviewit_current_interface])
m4_define([lt_revision], [libviewit_interface_age])
m4_define([lt_age], [m4_eval(libviewit_binary_age - libviewit_interface_age)])
LT_RELEASE=lt_release
LT_CURRENT=lt_current
LT_REVISION=lt_revision
LT_AGE=lt_age
LT_VERSION_INFO="lt_current:lt_revision:lt_age"
m4_define([LT_CURRENT_MINUS_AGE],[m4_eval(lt_current - lt_age)])
AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
AC_SUBST(LT_VERSION_INFO)
dnl Initialize maintainer mode
AM_MAINTAINER_MODE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXXCPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_ISC_POSIX
AM_PROG_LIBTOOL
AM_PROG_CC_STDC
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([sys/mman.h fcntl.h string.h unistd.h])
CXXFLAGS="$CXXFLAGS -std=c++11"
# Checks for libraries.
LIBS_SAVE=$LIBS
#check for GL
AC_CHECK_LIB(GL,glTranslatef,[
GL_LIB="-lGL"
AC_SUBST(GL_LIB)
],AC_MSG_ERROR(Unable to find the libGL))
#check for GLu
AC_CHECK_LIB(GLU,gluQuadricNormals,[
GLU_LIB="-lGLU"
AC_SUBST(GLU_LIB)
],AC_MSG_ERROR(Unable to find the libGLU), -lGL)
#check for GLe
AC_CHECK_LIB(gle,glePolyCone,[
GLE_LIB="-lgle"
AC_SUBST(GLE_LIB)
],AC_MSG_ERROR(Unable to find the libGLE), -lGLU -lGL)
AC_SEARCH_LIBS([sqrtf], [m])
#check for MIA and VISTAIO
SAVE_LIBS=$LIBS
PKG_CHECK_MODULES(MIA, miamesh-2.4 >= 2.4.4,[
AC_DEFINE(MIA_VERSION, 020404, [used MIA version])
], [
PKG_CHECK_MODULES(MIA, miamesh-2.2 >= 2.2.7,[
AC_DEFINE(MIA_VERSION, 020200, [used MIA version])
], [AC_MSG_ERROR(Unable to find mia >= 2.2.7)])
])
PKG_CHECK_MODULES(VISTAIO, libvistaio >= 1.2.14 ,, [AC_MSG_ERROR(Unable to find vistaio >= 1.2.14)])
PKG_CHECK_MODULES(XMLMM, libxml++-3.0, [
AC_DEFINE(LIBXMLMM_VERSION, 3, [used libxml++ version])
], [
PKG_CHECK_MODULES(XMLMM, libxml++-2.6,[
AC_DEFINE(LIBXMLMM_VERSION, 2, [used libxml++ version])
], [AC_MSG_ERROR(Unable to find libxml++)])
])
AC_SUBST(XMLMM_LIBS)
AC_SUBST(XMLMM_INCLUDES)
PKG_CHECK_MODULES(GLIBMM, glibmm-2.4)
AC_SUBST(GLIBMM_CFLAGS)
AC_SUBST(GLIBMM_LIBS)
PKG_CHECK_MODULES(GTKGLEXTMM, gtkglextmm-1.2)
AC_SUBST(GTKGLEXTMM_CFLAGS)
AC_SUBST(GTKGLEXTMM_LIBS)
CXXFLAGS="$CXXFLAGS $MIA_CFLAGS $VISTAIO_CFLAGS"
echo "vistaio: $VISTAIO_CFLAGS"
AC_SUBST(MIA_LIBS)
AC_SUBST(VISTAIO_LIBS)
LIBS=$LIBS_SAVE
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_STRUCT_TM
SAVE_CFLAGS=$CFLAGS
dnl Check for the shading language extension#
support_ogls=no
AC_ARG_ENABLE(volrenderer,
AC_HELP_STRING([--enable-volrenderer],
[turn on colume renderer if OGSL is available (default=no)]),
enable_volrenderer=yes)
if test y$enable_volrenderer = xyes ; then
CFLAGS="$CFLAGS -DGL_GLEXT_PROTOTYPES"
AC_CHECK_DECL(glCreateShaderObjectARB,[support_ogls=yes],[
AC_MSG_WARN("No headers upporting OGSL found -> volume rendering disabled")
support_ogls=no
],[
#include
#include
])
echo OGSL_VOLUMERENDERER: $support_ogls
fi
AM_CONDITIONAL(OGSL_VOLUMERENDERER, test x$support_ogls = xyes )
if test x$support_ogls = xyes ; then
AC_DEFINE(VOLUME_RENDERER, 1, [enable volume renderer])
fi
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([getcwd memset mkdir strdup])
AC_CONFIG_FILES([Makefile
viewit/Makefile
viewit/libviewit-config.hh
gui/Makefile
gui/src/Makefile
gui/pixmaps/Makefile
miaviewit.pc])
AC_OUTPUT
miaviewit-1.0.5/ChangeLog 0000644 0001750 0000677 00000005115 12745102071 012216 0000000 0000000 2016-07-24 Gert Wollny
* version bump to 1.0.4
* Enable compiling against libxml++-3.0
* Enable compiling against mia-2.4
2016-02-28 Gert Wollny
* version bump to 1.0.3
* replace BOOST-threads by c++11 threads (Closes: #4)
* correct SO-name handling
2015-10-21 Gert Wollny
* version bump to 1.0.2
* fix link dependencies with latest mia-2.2 release
* fix link dependencies on BOOST
2014-09-09 Gert Wollny
* version bump to 1.0.1
* depends now on mia-2.2
* gui/src/WinMain.cc: support multiple point lists and volume textures
* viewit/sphere.cc: correct color handling
* update automake boost macros
2013-05-21 Gert Wollny
* version bump because of changed dependecy
* update dependency on libvistaio >= 1.2.14
* update distribution files
* remove unused files in subdirectories
* make the proptotype volume rendering optional
* correct linking deps
* correct light and color values
* use mia class for snapshot saving
* correct the thread handling
* compile with clang
* add and port GUI
* update make files and shapshot server
* Move from libmona to MIA
2004-08-26 Gert Wollny
* viewit/mesh.hh: move base_header definition from libmona to this file
2004-07-14 Gert Wollny
* all: minimise libsigc++ dependecy
* conficgure.ac: better checking for libgle, libGLU, and libGL
* texture.cc: include for glTexImage3D
2004-02-24 Gert Wollny
* arrow.hh: added arrow list that is initialized by a pair of iterators
2004-02-12 Gert Wollny
* Mirko made a dynamic library and added a lot of stuff
2001-09-18 Gert Wollny
* texture.cc: Work around a OpenGL implementation bug which does not allow glTexSubImage2D to have odd width
* arrow.cc: started class to draw arrows to represent field
2001-08-29 Gert Wollny
* removed support for fullscreen
* changed texture handling
2001-08-23 Gert Wollny
* main.cc: made the thing compile with gcc 3.0.1 - dynamic_cast seems to be broken
* clip_plane.cc: added support for clip plane
* mesh.cc/camera.cc: improoved transparency ( seems to work now for a single object )
2001-08-22 Gert Wollny
* main.cc: colored mesh color scale show
* mesh.cc: added simple back-to-front ordering for the transparent case
* camera.cc: added a new camera model
2000-09-20 Gert Wollny
miaviewit-1.0.5/viewit/ 0000755 0001750 0000677 00000000000 13123163373 012034 5 0000000 0000000 miaviewit-1.0.5/viewit/voxelmove.hh 0000644 0001750 0000677 00000004136 12151742235 014325 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __voxelmove_hh
#define __voxelmove_hh
#include
#include
#include
#include
using namespace mia;
typedef T3DVectorSource C3DFVectorSource;
typedef TBrownVoxelMover TDeformation;
#define VOXELCLOUD_CLASSNAME "TVoxelCloud"
class TVoxelCloud : public TDrawable {
typedef std::list TVoxelList;
const TDeformation& _M_mover;
float _M_time_step;
float _M_voxel_lifetime;
TVoxelList _M_forward_voxels;
TVoxelList _M_backward_voxels;
float _M_age;
C3DFVectorSource _M_source;
int _M_size;
public:
TVoxelCloud(const string& name,int __size,
float __time_step,
float __voxel_lifetime,
const TDeformation& __deformation,
const C3DFVectorSource& __source);
shared_ptr get_vertex_list(int stride)const;
virtual bool animate();
void toggle_moving();
void init_voxels();
void set_lifetime(float lifetime);
float get_lifetime() const;
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
private:
virtual void do_gl_draw(const TCamera& c) const;
virtual bool do_handle_key_event(int key);
virtual bool do_handle_command_event(PEventInfo info);
};
#endif
miaviewit-1.0.5/viewit/version.cc 0000644 0001750 0000677 00000002143 12151742235 013750 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifdef HAVE_CONFIG_H
#include
#endif
#include
unsigned int libviewit_major_version = LIBVIEWIT_MAJOR_VERSION;
unsigned int libviewit_minor_version = LIBVIEWIT_MINOR_VERSION;
unsigned int libviewit_micro_version = LIBVIEWIT_MICRO_VERSION;
miaviewit-1.0.5/viewit/4DVector.hh 0000644 0001750 0000677 00000013111 12151742235 013724 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __MONA_4DVECTOR_HH
#define __MONA_4DVECTOR_HH 1
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
namespace mia {
#define g_vector_start '<'
#define g_vector_end '>'
template < class T > class T4DVector {
public:
T x,y,z,a;
T4DVector():x(0),y(0),z(0),a(0){};
T4DVector(int dim):x(0),y(0),z(0),a(0){
assert(dim == 4);
}
T4DVector(const T& _x,const T& _y,const T& _z, const T& _a):
x(_x),y(_y),z(_z),a(_a){
}
template T4DVector(const T4DVector& org):
x(T(org.x)),y(T(org.y)),z(T(org.z)),a(T(org.a)){
}
T operator[](int i)const {
// Cruel hack, i have to think of something better
return (&x)[i];
}
T& operator[](int i) {
// dito
return (&x)[i];
}
template T4DVector& operator =(const T4DVector& org){
if (this != &org) {
x=org.x; y=org.y; z=org.z, a=org.a;
}
return *this;
}
double norm()const{
return sqrt( x*x+ y*y+ z*z+ a*a);
}
double norm2()const{
return x*x + y*y + z*z + a*a;
}
double norm_inf() const{
const char *help= typeid(T).name();
double result;
if (strchr("csldfirx",help[0])!=0) {
result = fabs(x);
double b = fabs(y);
if (b > result) result = b;
b = fabs(z);
if (b > result) result = b;
b = fabs(a);
if (b > result) result = b;
}else if (help[0] == 'U') { // unsigned type
result = ( x > y ? ( x > z ? x : z ) : ( y > z ? y : z ));
result = a > result ? a : result;
}else{
fprintf(stderr,"error type infnorm\n");
}
// if elemt type is pointer or class , instanciation will fail anyway
// since no fabs is defined
return result;
}
int get_dim() const {
return 4;
}
T4DVector& operator +=(const T4DVector& u){
x+=u.x; y+=u.y; z+=u.z; a += u.a;
return *this;
}
T4DVector& operator -=(const T4DVector& u){
x-=u.x; y-=u.y; z-=u.z; a-=u.a;
return *this;
}
T4DVector& operator *=(const T& u){
x *= u; y *= u; z *= u; a *= u;
return *this;
}
T4DVector& operator /=(const T& u){
assert(u != T());
x /= u; y /= u; z /= u; a /= u;
return *this;
}
T4DVector operator +(const T4DVector& u)const{
return T4DVector(x+u.x, y+u.y, z+u.z,a+u.a);
}
T4DVector operator -(const T4DVector& u)const{
return T4DVector(x-u.x, y-u.y, z-u.z,a-u.a);
}
T operator *(const T4DVector& u)const{
return x*u.x+y*u.y+z*u.z+a*u.a;
}
T4DVector operator /(const T& u)const{
assert(u != T());
return T4DVector(x/u,y/u,z/u,a/u);
}
T4DVector operator *(const T& u)const{
return T4DVector(x*u,y*u,z*u,a*u);
}
bool operator == (const T4DVector& u)const{
return (x == u.x && y == u.y && z == u.z && a == u.a);
}
bool operator != (const T4DVector& u)const{
return (x != u.x && y != u.y && z != u.z && a != u.a);
}
bool operator < (const T4DVector& u)const{
return (x < u.x && y < u.y && z < u.z && a < u.a);
}
bool operator > (const T4DVector& u)const{
return (x > u.x && y > u.y && z > u.z && a > u.a);
}
bool operator <= (const T4DVector& u)const{
return (x <= u.x && y <= u.y && z <= u.z && a <= u.a);
}
bool operator >= (const T4DVector& u)const{
return (x >= u.x && y >= u.y && z >= u.z && a >= u.a);
}
friend T4DVector operator *(const T& a,const T4DVector& b){
return b * a;
}
/// print out the vector to the stream \a *os
void write(std::ostream& os)const {
os << "(" << x << ", " << y << ", " << z << "," << a << ")";
}
void read(std::istream& is) {
char c;
T r,s,t,u;
is >> c;
if (c == g_vector_start) {
is >> r;
is >> c;
if (c != ',') {
is.clear(std::ios::badbit);
return;
}
is >> s;
is >> c;
if (c != ',') {
is.clear(std::ios::badbit);
return;
}
is >> t;
is >> c;
if (c != ',') {
is.clear(std::ios::badbit);
return;
}
is >> u;
is >> c;
if (c != g_vector_end) {
is.clear(std::ios::badbit);
return;
}
x = r;
y = s;
z = t;
a = u;
}else
is.putback(c);
}
};
template double fabs(const T4DVector& t)
{
return t.norm();
}
typedef T4DVector C4DFVector;
typedef T4DVector C4DBounds;
/// stream output operator for 4DVector
template
std::ostream& operator << (std::ostream& os, const T4DVector& v)
{
v.write(os);
return os;
}
/// stream input operator for 4DVector
template
std::istream& operator >> (std::istream& is, T4DVector& v)
{
v.read(is);
return is;
}
} // namespace mona
#endif // __MONA_4DVECTOR_HH
miaviewit-1.0.5/viewit/glmesh.cc 0000644 0001750 0000677 00000036705 12151742235 013555 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#define GL_GLEXT_PROTOTYPES 1
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace mia;
typedef struct {
C3DBounds t;
float z_dist;
} STriangle;
#if 0
template<> struct __type_traits {
typedef __true_type has_trivial_default_constructor;
typedef __true_type has_trivial_copy_constructor;
typedef __true_type has_trivial_assignment_operator;
typedef __true_type has_trivial_destructor;
typedef __true_type is_POD_type;
};
#endif
inline bool operator < (const STriangle& a, const STriangle& b)
{
return a.z_dist < b.z_dist;
}
struct TGLMeshData {
PTriangleMesh _M_mesh;
mutable std::vector _M_triangle_midpoints;
GL3DGrayTexture *_M_texture;
float _M_max_grow_log;
float _M_max_shrink_log;
float _M_max_grow;
float _M_max_shrink;
float _M_inv_grow_log;
float _M_inv_shrink_log;
float _M_inv_grow;
float _M_inv_shrink;
float _M_max_scale;
int _M_scale_type;
const TDrawable& _M_owner;
bool do_draw_decoration;
TGLMeshData(PTriangleMesh mesh,const TDrawable& owner);
bool do_handle_key_event(int key);
void do_gl_draw(const TCamera& c,float alpha) const;
void init_texturing()const;
void deinit_texturing()const;
void sort_triangles(std::priority_queue *st, const TCamera& c)const;
void draw_decoration(const C2DBounds& viewport,const TGLText& writer);
void evaluate_triangle_midpoints()const;
void apply_color_change();
void toggle_scale_type();
void inside_out();
void gl_attach();
};
TGLMeshData::TGLMeshData(PTriangleMesh mesh, const TDrawable& owner):
_M_mesh(mesh),
_M_triangle_midpoints(mesh->triangle_size()),
_M_texture(NULL),
_M_max_grow_log(0),
_M_max_shrink_log(0),
_M_max_grow(0),
_M_max_shrink(0),
_M_max_scale(0),
_M_scale_type(md_scale_2mm),
_M_owner(owner),
do_draw_decoration(false)
{
// inside_out();
if (! (_M_mesh->get_available_data() & CTriangleMesh::ed_normal))
_M_mesh->evaluate_normals();
evaluate_triangle_midpoints();
if (_M_mesh->get_available_data() & CTriangleMesh::ed_scale) {
CTriangleMesh::const_scale_iterator sb = mesh->scale_begin();
CTriangleMesh::const_scale_iterator se = mesh->scale_end();
while (sb != se) {
if (_M_max_grow < *sb)
_M_max_grow = *sb;
if (_M_max_shrink > *sb)
_M_max_shrink = *sb;
++sb;
}
_M_max_grow_log = log(_M_max_grow);
_M_max_shrink = - _M_max_shrink;
_M_max_shrink_log = _M_max_shrink > 0 ? log(_M_max_shrink) : 0;
cerr << "scale: " << _M_max_shrink << ":" <<_M_max_grow << endl;
_M_inv_grow_log = _M_max_grow_log != 0 ? 1.0 / _M_max_grow_log : 0.0;
_M_inv_shrink_log = _M_inv_shrink_log != 0 ? 1.0 / _M_inv_shrink_log : 0.0;
_M_inv_grow = _M_max_grow != 0 ? 1.0 / _M_max_grow : 0.0;
_M_inv_shrink = _M_inv_shrink != 0 ? 1.0 / _M_inv_shrink : 0.0;
do_draw_decoration = true;
}
}
void TGLMeshData::toggle_scale_type()
{
++_M_scale_type;
if (_M_scale_type == md_last) {
_M_scale_type = md_standart;
}
apply_color_change();
}
void TGLMeshData::gl_attach()
{
apply_color_change();
}
void TGLMeshData::inside_out()
{
CTriangleMesh::triangle_iterator tb = _M_mesh->triangles_begin();
CTriangleMesh::triangle_iterator te = _M_mesh->triangles_end();
while (tb != te) {
unsigned int tmp = (*tb).z;
(*tb).z = (*tb).y;
(*tb).y = tmp;
++tb;
}
}
void TGLMeshData::sort_triangles(std::priority_queue *stq, const TCamera& c)const
{
CTriangleMesh::const_triangle_iterator tb = _M_mesh->triangles_begin();
CTriangleMesh::const_triangle_iterator te = _M_mesh->triangles_end();
std::vector::const_iterator tmb = _M_triangle_midpoints.begin();
while( tb != te) {
STriangle st;
st.t = *tb;
st.z_dist = - c.get_z_dist(*tmb);
stq->push(st);
++tb;
++tmb;
}
}
void TGLMeshData::evaluate_triangle_midpoints()const
{
CTriangleMesh::const_triangle_iterator tb = _M_mesh->triangles_begin();
CTriangleMesh::const_triangle_iterator te = _M_mesh->triangles_end();
std::vector::iterator tmb = _M_triangle_midpoints.begin();
while (tb != te) {
*tmb = (_M_mesh->vertex_at((*tb).x) +
_M_mesh->vertex_at((*tb).y) +
_M_mesh->vertex_at((*tb).z)) / 3.0f;
++tb;
++tmb;
}
}
void TGLMeshData::draw_decoration(const C2DBounds& viewport,const TGLText& writer)
{
if (!do_draw_decoration)
return;
int y = viewport.y;
glColor4f(0.0f,.5f,0.0f,0.3f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glVertex2f(5.0f,y - 10.0f);
glVertex2f(90.0f,y - 10.0f);
glVertex2f(90.0f,y - 110.0f);
glVertex2f(5.0f,y - 110.0f);
glEnd();
glDisable(GL_BLEND);
glBegin(GL_QUAD_STRIP);
glColor3fv(&_M_owner.get_color2().x);
glVertex2f(10.0f,y - 20.0f);
glVertex2f(20.0f,y - 20.0f);
// in this case we do not mark zero
if (_M_scale_type != md_standart) {
glColor3fv(&_M_owner.get_color1().x);
glVertex2f(10.0f,y - 60.0f);
glVertex2f(20.0f,y - 60.0f);
}
glColor3fv(&_M_owner.get_color3().x);
glVertex2f(10.0f,y - 100.0f);
glVertex2f(20.0f,y - 100.0f);
glEnd();
char value[20];
switch (_M_scale_type) {
case md_log:
snprintf(value,20," e^%3.1f",_M_max_grow_log);
glColor3fv(&_M_owner.get_color2().x);
writer.write(25, int(y - 34), value);
glColor3fv(&_M_owner.get_color1().x);
writer.write(25, int(y - 67), " 0.0");
snprintf(value,20,"-e^%3.1f",_M_max_shrink_log);
glColor3fv(&_M_owner.get_color3().x);
writer.write(25 , int(y - 100), value);
break;
case md_standart:
snprintf(value,20,"%5.1f",_M_max_grow);
glColor3fv(&_M_owner.get_color2().x);
writer.write(25, int(y - 34), value);
snprintf(value,20,"%5.1f",-_M_max_shrink);
glColor3fv(&_M_owner.get_color3().x);
writer.write(25 , int(y - 100), value);
break;
default:
if (_M_max_scale > _M_max_grow)
snprintf(value,20,"%5.1f",_M_max_scale);
else
snprintf(value,20,"%5.1f+",_M_max_scale);
glColor3fv(&_M_owner.get_color2().x);
writer.write(25, int(y - 34), value);
glColor3fv(&_M_owner.get_color1().x);
writer.write(25, int(y - 67), " 0.0");
if (_M_max_scale > _M_max_shrink)
snprintf(value,20,"%5.1f",-_M_max_scale);
else
snprintf(value,20,"%5.1f-",-_M_max_scale);
glColor3fv(&_M_owner.get_color3().x);
writer.write(25 , int(y - 100), value);
}
}
void TGLMeshData::apply_color_change()
{
_M_max_scale = 2.0f;
if (! (_M_mesh->get_available_data() & CTriangleMesh::ed_scale)) {
return;
}
float inv_max_scale = 0.5f;
const CTriangleMesh& m = *_M_mesh;
CTriangleMesh::const_scale_iterator sb = m.scale_begin();
CTriangleMesh::const_scale_iterator se = m.scale_end();
CTriangleMesh::color_iterator cb = _M_mesh->color_begin();
switch (_M_scale_type) {
case md_log:
while (sb != se) {
float scale = *sb;
TColor color;
if (scale < 0) { // if max_shrink == 0 then never true;
scale = log( 1.0f - scale);
color = ((_M_max_shrink_log - scale ) * _M_owner.get_color1() +
scale * _M_owner.get_color3()) * _M_inv_shrink_log;
}else if (scale > 0){
scale = log(scale + 1.0f);
color = ((_M_max_grow_log - scale) * _M_owner.get_color1() +
scale * _M_owner.get_color2()) * _M_inv_grow_log;
}else{
color = _M_owner.get_color1();
}
(*cb).x = color.x;
(*cb).y = color.y;
(*cb).z = color.z;
++cb;
++sb;
}
break;
case md_divide:
while (sb != se) {
float scale = *sb;
TColor color;
if (scale < 0) { // if max_shrink == 0 then never true;
color = _M_owner.get_color3();
}else if (scale > 0){
color = _M_owner.get_color2();
}else{
color = _M_owner.get_color1();
}
(*cb).x = color.x;
(*cb).y = color.y;
(*cb).z = color.z;
++cb;
++sb;
}
break;
case md_standart:
while (sb != se) {
float scale = *sb;
TColor color;
float s = (scale + _M_max_shrink)/ (_M_max_grow + _M_max_shrink);
color = s * _M_owner.get_color2() + (1.0f - s) * _M_owner.get_color3();
(*cb).x = color.x;
(*cb).y = color.y;
(*cb).z = color.z;
++cb;
++sb;
}
break;
case md_scale_32mm:
_M_max_scale *= 2.0;
inv_max_scale *= 0.5;
case md_scale_16mm:
_M_max_scale *= 2.0;
inv_max_scale *= 0.5;
case md_scale_8mm:
_M_max_scale *= 2.0;
inv_max_scale *= 0.5;
case md_scale_4mm:
_M_max_scale *= 2.0;
inv_max_scale *= 0.5;
case md_scale_2mm:
while (sb != se) {
float scale = *sb;
TColor color;
if (scale < 0) { // if max_shrink == 0 then never true;
if (scale > -_M_max_scale)
color = ((scale + _M_max_scale) * _M_owner.get_color1() -
scale * _M_owner.get_color3()) * inv_max_scale;
else
color = _M_owner.get_color3();
}else if (scale > 0){
if (scale < _M_max_scale)
color = ((_M_max_scale - scale) * _M_owner.get_color1() +
scale * _M_owner.get_color2()) * inv_max_scale;
else
color = _M_owner.get_color2();
}else{
color = _M_owner.get_color1();
}
(*cb).x = color.x;
(*cb).y = color.y;
(*cb).z = color.z;
++cb;
++sb;
}
break;
default:
std::cerr << "Warning: unknown scale type" << std::endl;
}
}
bool TGLMeshData::do_handle_key_event(int key)
{
switch (key) {
case 's':toggle_scale_type();
break;
case 'd':do_draw_decoration = !do_draw_decoration;
break;
default:
return false;
}
return true;
}
void TGLMeshData::init_texturing()const
{
if (!_M_texture)
return;
_M_texture->bind();
glEnable(GL_TEXTURE);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(3, GL_FLOAT, 0, _M_mesh->get_vertex_pointer());
}
void TGLMeshData::deinit_texturing()const
{
if (!_M_texture)
return;
glDisable(GL_TEXTURE);
}
void TGLMeshData::do_gl_draw(const TCamera& c, float alpha) const
{
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
if (_M_mesh->get_color_pointer()) {
glColorPointer(3, GL_FLOAT, 0, _M_mesh->get_color_pointer());
glEnableClientState(GL_COLOR_ARRAY);
}
if (_M_mesh->get_normal_pointer()) {
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, _M_mesh->get_normal_pointer());
}
init_texturing();
// draw the mesh
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, _M_mesh->get_vertex_pointer());
/*
if (_M_owner.draw_shiny()) {
cvdebug() << "TGLMeshData: draw shiny\n";
TColor specular_color(.5,.5,0.5,1.0);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,&specular_color.x);
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,5.0f);
}else{
cvdebug() << "TGLMeshData: draw normal\n";
TColor black(.0,.0,0.0,0.0);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,&black.x);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,&black.x);
}
*/
if (!_M_owner.is_transparent()) {
glDrawElements(GL_TRIANGLES,3 * _M_mesh->triangle_size(),GL_UNSIGNED_INT,
_M_mesh->get_triangle_pointer());
}else{
if (_M_mesh->get_color_pointer()) {
glBlendColor(0.0,0.0,0.0,alpha);
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
}
std::priority_queue __st;
sort_triangles(&__st,c);
cvdebug() << "mesh drawn transparent" << endl;
while ( ! __st.empty() ) {
// cerr << __st.top().z_dist << endl;
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, &__st.top().t.x);
__st.pop();
}
}
// (un)set client state
deinit_texturing();
if (_M_mesh->get_normal_pointer())
glDisableClientState(GL_NORMAL_ARRAY);
if (_M_mesh->get_color_pointer()) {
glDisableClientState(GL_COLOR_ARRAY);
}
glDisableClientState(GL_VERTEX_ARRAY);
}
TGLMesh::TGLMesh(const string& name, PTriangleMesh mesh):
TDrawable(name),
data(new TGLMeshData(mesh,*this))
{
light_on();
culling_on();
cull_back();
}
TGLMesh::~TGLMesh()
{
delete data;
}
bool TGLMesh::do_handle_key_event(int key)
{
switch (key) {
case 'g':toggle_draw_shiny(); break;
case 'l':toggle_lightmodel(); break; // light on both sides or not
case 'k':toggle_culling_enable();break;
case 'p':
if (do_cull_front())
cull_back();
else
cull_front();
break;
default:
if (! data->do_handle_key_event(key))
return TDrawable::do_handle_key_event(key);
}
return true;
}
void TGLMesh::do_gl_draw(const TCamera& c) const
{
cvdebug() << "Mesh draw with color " << get_color1() << "\n";
glColor4fv(&get_color1().x);
data->do_gl_draw(c, get_color1().a);
}
void TGLMesh::set_texture(GL3DGrayTexture *texture)
{
data->_M_texture = texture;
}
void TGLMesh::draw_decoration(const C2DBounds& viewport,const TGLText& writer)
{
data->draw_decoration(viewport,writer);
}
void TGLMesh::gl_attach()
{
data->gl_attach();
}
bool TGLMesh::do_handle_command_event(PEventInfo info) {
switch (info->get_command()) {
case EV_GLMESH_GET_STATE: {
TGLMeshEventInfo& ev = dynamic_cast(*info);
ev.set_draw_shiny(draw_shiny());
ev.set_light_model(need_light());
ev.set_culling(culling_is_enabled());
ev.set_front_face_culling(do_cull_front());
ev.set_color1(get_color1());
ev.set_color2(get_color2());
ev.set_color3(get_color3());
ev.set_has_color(true);
} break;
case EV_GLMESH_TOGGLE_SHINY:
toggle_draw_shiny();
break;
case EV_GLMESH_TOGGLE_LIGHTMODEL:
toggle_lightmodel();
break;
case EV_GLMESH_TOGGLE_CULLING:
toggle_culling_enable();
break;
case EV_GLMESH_TOGGLE_FRONTFACECULLING:
if (do_cull_front())
cull_back();
else
cull_front();
break;
case EV_GLMESH_SET_COLOR1: {
TGLMeshEventInfo& ev = dynamic_cast(*info);
set_color1(ev.get_color1());
if (data->_M_mesh->get_available_data() & CTriangleMesh::ed_scale)
apply_color_change();
else
set_diffuse_front_color(ev.get_color1());
} break;
case EV_GLMESH_SET_COLOR2: {
TGLMeshEventInfo& ev = dynamic_cast(*info);
set_color2(ev.get_color2());
if (data->_M_mesh->get_available_data() & CTriangleMesh::ed_scale)
apply_color_change();
else
set_diffuse_front_color(ev.get_color2());
apply_color_change();
} break;
case EV_GLMESH_SET_COLOR3: {
TGLMeshEventInfo& ev = dynamic_cast(*info);
set_color3(ev.get_color3());
apply_color_change();
} break;
case EV_GLMESH_TOGGLE_COLORSCALE:
data->toggle_scale_type();
break;
case EV_GLMESH_SHOW_DECORATION:
data->do_draw_decoration = !data->do_draw_decoration;
break;
default: return TDrawable::do_handle_command_event(info);
}
return true;
}
const char* TGLMesh::get_classname() const
{
return GLMESH_CLASSNAME;
}
void TGLMesh::get_classname_list(list *classlist) const
{
if (classlist) {
classlist->push_front(GLMESH_CLASSNAME);
TDrawable::get_classname_list(classlist);
}
}
CTriangleMesh* TGLMesh::get_mesh()
{
return data->_M_mesh.get();
}
void TGLMesh::apply_color_change()
{
data->apply_color_change();
}
miaviewit-1.0.5/viewit/mesh.hh 0000644 0001750 0000677 00000021100 12151742235 013223 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef d__mesh_hh
#define d__mesh_hh
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
using namespace mia;
#include
#include
struct base_header {
char name_space[3];
char type[14];
short endian_test;
};
struct tri_mesh_header {
base_header base;
size_t n_vertices;
size_t n_triangles;
};
#define TRIMESH_TYPENAME "TriMesh"
#define SMOOTHTRIMESH_TYPENAME "STriMesh"
#define COLORSMOOTHTRIMESH_TYPENAME "CSTriMesh"
#define TRIANGLEMESHABASE_CLASSNAME "CTriangleMeshABase"
#define TRIANGLEMESH_CLASSNAME "CTriangleMeshA"
#define SMOOTHTRIANGLEMESH_CLASSNAME "TSmoothTriangleMesh"
#define COLORSMOOTHMESH_CLASSNAME "TColorSmoothMesh"
/// the base class for all triangle meshes
class CTriangleMeshABase: public TDrawable {
protected:
size_t n_triangles;
triangle_ui_t *triangles;
size_t n_vertices;
C3DFVector *triangle_mid_points;
mutable C3DFVector m_center;
public:
CTriangleMeshABase(const string& name, size_t n_triangles, triangle_ui_t *t,size_t _num_vertices);
CTriangleMeshABase(const string& name, const CTriangleMeshABase& org);
~CTriangleMeshABase();
virtual const TVertexList *get_vertex_list(int stride)const = 0;
virtual const char* get_type_name()const = 0;
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
const C3DFVector get_center()const;
bool do_export(FILE*f)const;
protected:
triangle_ui_t *tri_mirror;
virtual bool do_handle_key_event(int key);
virtual void do_gl_draw(const TCamera& c) const;
private:
class collect_t {
public:
int i;
float d;
bool operator < (const collect_t& o)const {
return d < o.d;
}
};
void povray_output_description(FILE *f)const;
virtual bool write_vertices(FILE *f)const=0;
protected:
template
bool do_write_vertices(FILE *f)const;
template
void sort_triangles(const triangle *in, triangle *out, const TCamera& c)const;
template
void calc_triangle_mid_points(vertex_type *vertex);
template
void calc_center(vertex_type *vertex);
};
/// a triangle mesh with no normals (can not be lit)
class CTriangleMeshA: public CTriangleMeshABase {
vertex_t *vertices;
public:
CTriangleMeshA(const string& name, int _n_triangles, triangle_ui_t *t,
int _num_vertices, vertex_t *v);
~CTriangleMeshA();
const vertex_t *get_vertices()const {return vertices;}
virtual TVertexList *get_vertex_list(int stride)const;
virtual void povray_output_object(FILE *f)const;
virtual const char* get_type_name()const;
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
protected:
virtual bool write_vertices(FILE *f)const;
void gl_attach();
void do_gl_draw(const TCamera& c) const;
};
/// a trinagle mesh with normals at the vertexes
class TSmoothTriangleMesh: public CTriangleMeshABase {
normal_vertex_t *vertices;
public:
TSmoothTriangleMesh(const string& name, int _n_triangles, triangle_ui_t *t,
int _num_vertices, normal_vertex_t *v);
TSmoothTriangleMesh(const string& name, int _n_triangles, triangle_ui_t *t,
int _num_vertices, vertex_t *v);
TSmoothTriangleMesh(const string& name, const CTriangleMeshA& mesh);
TSmoothTriangleMesh(const string& name, const TSmoothTriangleMesh& mesh,
const C3DTransformation& deform);
TSmoothTriangleMesh(const string& name, const CTriangleMeshA& mesh,
const C3DTransformation& deform);
~TSmoothTriangleMesh();
void deform(const C3DTransformation& shift);
const normal_vertex_t *get_vertices()const {return vertices;}
virtual TVertexList *get_vertex_list(int stride)const;
virtual void povray_output_object(FILE *f)const;
virtual const char* get_type_name()const;
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
protected:
virtual void do_gl_draw(const TCamera& c) const;
private:
virtual bool write_vertices(FILE *f)const;
void create_from_vertex_array(const vertex_t *v);
void recalc_normals();
void gl_attach();
};
/// a mesh with normals and colors defined per vertex
class TColorSmoothMesh: public CTriangleMeshABase {
color_normal_vertex_t *vertices;
float *vertex_deform_scale;
float max_shrink;
float max_grow;
float inv_max_shrink;
float inv_max_grow;
float inv_max_shrink_log;
float inv_max_grow_log;
float max_grow_log;
float max_shrink_log;
float ms,ims;
int scale_type;
bool do_draw_decoration;
public:
enum EScaleType {
st_standart,
st_divide,
st_log,
st_scale_2mm,
st_scale_4mm,
st_scale_8mm,
st_scale_16mm,
st_scale_32mm,
st_last
};
TColorSmoothMesh(const string& name, int _n_triangles, triangle_ui_t *t,
int _n_vertices, color_normal_vertex_t *v);
TColorSmoothMesh(const string& name, int _n_triangles, triangle_ui_t *t,
int _n_vertices, color_normal_vertex_t *v, float *scale);
template
TColorSmoothMesh(const string& name, const TSmoothTriangleMesh& mesh,
const Deformation& deform,bool bdeform);
~TColorSmoothMesh();
virtual TVertexList *get_vertex_list(int stride)const;
unique_ptr get_vertex_normal_list(int stride)const;
virtual const char* get_type_name()const;
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
void apply_color_change();
float get_max_shrink()const;
float get_max_grow()const;
void show_decoration(bool value);
virtual void set_transparency(float alpha);
void set_scale_type(EScaleType t) {
scale_type = t;
}
void toggle_scale_type();
virtual void draw_decoration(const C2DBounds& viewport,const TGLText& writer);
virtual void povray_output_object(FILE *f)const;
virtual void povray_output_description(FILE *f)const;
protected:
virtual bool do_handle_key_event(int key);
virtual void do_gl_draw(const TCamera& c) const;
private:
virtual bool write_vertices(FILE *f)const;
void povray_write_color(FILE *f,float scale)const;
void gl_attach();
};
inline void TColorSmoothMesh::show_decoration(bool value)
{
do_draw_decoration = value;
}
inline float TColorSmoothMesh::get_max_shrink()const
{
return max_shrink;
}
inline float TColorSmoothMesh::get_max_grow()const
{
return max_grow;
}
template
TColorSmoothMesh::TColorSmoothMesh(const string& name, const TSmoothTriangleMesh& mesh,
const Deformation& deform, bool bdeform):
CTriangleMeshABase(name,mesh),
max_shrink(0.0f),
max_grow(0.0f),
max_grow_log(0.0f),
max_shrink_log(0.0f),
scale_type(st_standart),
do_draw_decoration(true)
{
vertices = new color_normal_vertex_t[n_vertices];
vertex_deform_scale = new float[n_vertices];
color_normal_vertex_t *cnv = vertices;
const normal_vertex_t *nv = mesh.get_vertices();
for (size_t i = 0; i < n_vertices; i++,++cnv,++nv) {
cnv->normal = nv->normal;
cnv->vertex = nv->vertex;
C3DFVector defo = deform(cnv->vertex - (0.5f * cnv->normal));
if (bdeform)
cnv->vertex += defo;
float shift = dot(defo, cnv->normal);
if (shift > 0) {
vertex_deform_scale[i] = -shift;
if (shift > max_shrink) max_shrink = shift;
shift = log(shift + 1.0);
if (shift > max_shrink_log) max_shrink_log = shift;
}else{
shift = -shift;
vertex_deform_scale[i] = shift;
if (shift > max_grow) max_grow = shift;
shift = log(shift + 1.0);
if (shift > max_grow_log) max_grow_log = shift;
}
}
if (max_shrink != 0 ) {
inv_max_shrink = 1.0f / max_shrink;
inv_max_shrink_log = 1.0f / max_shrink_log;
cerr << "max_shrink : " << max_shrink << endl;
}
if (max_grow != 0 ) {
inv_max_grow_log = 1.0f / max_grow_log;
inv_max_grow = 1.0f / max_grow;
cerr << "max_grow : " << max_grow << endl;
}
}
#endif
miaviewit-1.0.5/viewit/planeexpose.cc 0000644 0001750 0000677 00000027432 12151742235 014616 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
using namespace std;
#include
#include
float BasePlaneExpose::deform_thresh = .0001;
unsigned int BasePlaneExpose::max_objs = 200;
BasePlaneExpose::BasePlaneExpose(const GL2DTexture& _Texture):
obj_size(0),
Texture(_Texture),
ObjIndexArray(0),
PointArray(0),
fine_point_array(0),
fine_display(false)
{
}
BasePlaneExpose::~BasePlaneExpose()
{
delete[] ObjIndexArray;
if (fine_point_array)
delete[] fine_point_array;
delete[] PointArray;
}
inline void BasePlaneExpose::draw_point(const GLTexPoint& pPoint) const
{
glTexCoord2f(pPoint.tex.x, pPoint.tex.y);
glNormal3f(pPoint.normal.x,pPoint.normal.y,pPoint.normal.z);
glVertex3f(pPoint.loc.x,pPoint.loc.y,pPoint.loc.z);
}
void BasePlaneExpose::draw() const
{
if (!fine_display) { // fast display is default
glBegin(GL_QUADS);
GLuint *pObjIndexArray = ObjIndexArray;
for (int i = 0; i < obj_size / 4; i++) {
draw_point(PointArray[*pObjIndexArray++]);
draw_point(PointArray[*pObjIndexArray++]);
draw_point(PointArray[*pObjIndexArray++]);
draw_point(PointArray[*pObjIndexArray++]);
}
glEnd();
} else {// print every little little quad
GLTexPoint *p_point_y0 = fine_point_array;
GLTexPoint *p_point_y1 = &p_point_y0[m_coordinates.get_size().x];
for (size_t y = 0; y < m_coordinates.get_size().y-1; y++){
glBegin(GL_QUAD_STRIP);
for (size_t x =0; x < m_coordinates.get_size().x; x++) {
draw_point(*p_point_y1++);
draw_point(*p_point_y0++);
}
glEnd();
}
}
}
void BasePlaneExpose::set_fine_display(bool fine)
{
int ya,ye,xa,xe;
fine_display = fine;
if (!fine_display || fine_point_array)
return;
T3DVector2DField normals(m_coordinates.get_size());
fine_point_array = new GLTexPoint[m_coordinates.get_size().y * m_coordinates.get_size().x];
GLTexPoint *p = fine_point_array;
const float tex_step_x = Texture.get_tex_xcoord(1.0) / (m_coordinates.get_size().x);
const float tex_step_y = Texture.get_tex_ycoord(1.0) / (m_coordinates.get_size().y);
C2DFVector tex(0.0,0.0);
for (size_t y = 0; y < m_coordinates.get_size().y; y++,tex.y += tex_step_y) {
if (y > 0) {ya = y-1; ye = y;}
else {ya = y; ye = y+1;}
tex.x = 0.0;
for (size_t x = 0; x < m_coordinates.get_size().x;
x++,tex.x += tex_step_x,p++) {
if (x > 0) {xa = x-1; xe = x;}
else {xa = x; xe = x+1;}
p->tex = tex;
C3DFVector normal = get_quad_normal(xa,ya,xe,ye);
normals(xa,ya) += normal;
normals(xa,ye) += normal;
normals(xe,ye) += normal;
normals(xe,ya) += normal;
p->loc = m_coordinates(x,y);
}
}
T3DVector2DField::const_iterator normal_iterator = normals.begin();
T3DVector2DField::const_iterator ne = normals.end();
p = fine_point_array;
while (normal_iterator != ne) {
float help= (*normal_iterator).norm();
if (help > 0.0)
(*p++).normal = *normal_iterator++ / help;
else
(*p++).normal = *normal_iterator++;
}
}
C3DFVector BasePlaneExpose::get_quad_normal(int x,int y,int xe,int ye)const
{
C3DFVector result = (m_coordinates(xe,y) - m_coordinates(x,y)) ^
(m_coordinates(x,ye) - m_coordinates(x,y));
float norm = result.norm();
if (norm > 0.0)
result /= norm;
return result;
}
void BasePlaneExpose::create_point_table()
{
std::list objs;
std::vector Points(m_coordinates.get_size().x * m_coordinates.get_size().y);
int num_points = generate_map(&Points,&objs);
if (PointArray) {
delete PointArray;
}
if (ObjIndexArray)
delete ObjIndexArray;
obj_size = 4 * objs.size();
ObjIndexArray = new GLuint[obj_size];
GLuint *pObjIndexArray = ObjIndexArray;
for(std::list::const_iterator i= objs.begin();
i != objs.end(); i++) {
C3DFVector normal = ((Points[(*i).xa_ya_idx].GetDeform() -
Points[(*i).xe_ya_idx].GetDeform()) ^
(Points[(*i).xe_ye_idx].GetDeform() -
Points[(*i).xe_ya_idx].GetDeform()));
Points[(*i).xa_ya_idx].normal_ref() -= normal;
Points[(*i).xe_ya_idx].normal_ref() -= normal;
Points[(*i).xe_ye_idx].normal_ref() -= normal;
Points[(*i).xa_ye_idx].normal_ref() -= normal;
*pObjIndexArray++ = (*i).xa_ya_idx;
*pObjIndexArray++ = (*i).xe_ya_idx;
*pObjIndexArray++ = (*i).xe_ye_idx;
*pObjIndexArray++ = (*i).xa_ye_idx;
}
PointArray = new GLTexPoint[num_points];
GLTexPoint *pPointArray = PointArray;
for (int i = 0; i < num_points; i++,pPointArray++) {
Points[i].GetTexPoint(pPointArray);
}
}
float BasePlaneExpose::get_deform(const std::vector& Points,const TWorkObject& wo)
{
if (wo.xe - wo.xa < 2 || wo.ye - wo.ya < 2) {
return 0.0;
}
float max_deform = 0.0;
// Get deformed corners of the input quad
const C3DFVector& xa_ya_deform = Points[wo.quad.xa_ya_idx].GetDeform();
const C3DFVector& xe_ya_deform = Points[wo.quad.xe_ya_idx].GetDeform();
const C3DFVector& xa_ye_deform = Points[wo.quad.xa_ye_idx].GetDeform();
const C3DFVector& xe_ye_deform = Points[wo.quad.xe_ye_idx].GetDeform();
int nx = m_coordinates.get_size().x;
// generate the y - interpolation factors
float y_step = 1.0 / (wo.ye - wo.ya);
float dy = 0.0;float my = 1.0;
for (int y = wo.ya; y < wo.ye; y++,dy += y_step,my -= y_step) {
// goto start of line
T3DVector2DField::iterator d_help = m_coordinates.begin();
advance(d_help, wo.xa + y * nx);
// generate the x-interpolation factors
float x_step = 1.0 / (wo.xe - wo.xa);
float dx = 0.0;float mx = 1.0;
for (int x = wo.xa; x < wo.xe; x++,d_help++,dx += x_step,mx -= x_step) {
// get the deformation
C3DFVector v_delta = *d_help -
bilin_interpol(xa_ya_deform,xe_ya_deform,xa_ye_deform,xe_ye_deform,
dx,mx,dy,my);
float new_deform = v_delta.norm2();
if ( new_deform > max_deform) {
max_deform = new_deform;
}
}
}
return max_deform;
}
int BasePlaneExpose::generate_map(std::vector *Points,std::list *objs)
{
int nx = m_coordinates.get_size().x-1;
int ny = m_coordinates.get_size().y-1;
std::priority_queue WorkObjects;
const float end_xtex = Texture.get_tex_xcoord(1.0);
const float end_ytex = Texture.get_tex_ycoord(1.0);
const float tex_step_x = Texture.get_tex_xcoord(1.0) / (nx+1);
const float tex_step_y = Texture.get_tex_ycoord(1.0) / (ny+1);
int index = 0;
// Create the initial square
(*Points)[index++] = TPoint(m_coordinates(0,0),0,0);
(*Points)[index++] = TPoint(m_coordinates(nx,0),end_xtex,0);
(*Points)[index++] = TPoint(m_coordinates(nx,ny),end_xtex,end_ytex);
(*Points)[index++] = TPoint(m_coordinates(0,ny),0,end_ytex);
TWorkObject wo = {1.0,0,nx,0,ny,{0,1,2,3}};
wo.priority = get_deform(*Points,wo);
// check the deformation
if ( wo.priority > deform_thresh) {
// needs further work
WorkObjects.push(wo);
}else{
// ready to go
objs->push_back(wo.quad);
}
while (!WorkObjects.empty() && max_objs > objs->size() + WorkObjects.size()) {
TWorkObject co = WorkObjects.top();
WorkObjects.pop();
// new version: divide into four new rectangles
int xn = (co.xe - co.xa) / 2 + co.xa;
int yn = (co.ye - co.ya) / 2 + co.ya;
int idx_xn_ya = index;
(*Points)[index++] = TPoint(m_coordinates(xn,co.ya),
xn * tex_step_x,co.ya * tex_step_y);
int idx_xn_ye = index;
(*Points)[index++] = TPoint(m_coordinates(xn,co.ye),
xn * tex_step_x,co.ye * tex_step_y);
int idx_xa_yn = index;
(*Points)[index++] = TPoint(m_coordinates(co.xa,yn),
co.xa * tex_step_x ,yn * tex_step_y);
int idx_xe_yn = index;
(*Points)[index++] = TPoint(m_coordinates(co.xe,yn),
co.xe * tex_step_x ,yn * tex_step_y);
int idx_xn_yn = index;
(*Points)[index++] = TPoint(m_coordinates(xn,yn),
xn * tex_step_x ,yn * tex_step_y);
TWorkObject no = co;
no.xe = xn;
no.ye = yn;
no.quad.xa_ya_idx = co.quad.xa_ya_idx;
no.quad.xe_ya_idx = idx_xn_ya;
no.quad.xa_ye_idx = idx_xa_yn;
no.quad.xe_ye_idx = idx_xn_yn;
no.priority = get_deform(*Points,no);
if ( no.priority > deform_thresh)
WorkObjects.push(no);
else
objs->push_back(no.quad);
no = co;
no.xa = xn;
no.ye = yn;
no.quad.xa_ya_idx = idx_xn_ya;
no.quad.xe_ya_idx = co.quad.xe_ya_idx;
no.quad.xa_ye_idx = idx_xn_yn;
no.quad.xe_ye_idx = idx_xe_yn;
no.priority = get_deform(*Points,no);
if ( no.priority > deform_thresh)
WorkObjects.push(no);
else
objs->push_back(no.quad);
no = co;
no.xe = xn;
no.ya = yn;
no.quad.xa_ya_idx = idx_xa_yn;
no.quad.xe_ya_idx = idx_xn_yn;
no.quad.xa_ye_idx = co.quad.xa_ye_idx;
no.quad.xe_ye_idx = idx_xn_ye;
no.priority = get_deform(*Points,no);
if ( no.priority > deform_thresh)
WorkObjects.push(no);
else
objs->push_back(no.quad);
no = co;
no.xa = xn;
no.ya = yn;
no.quad.xa_ya_idx = idx_xn_yn;
no.quad.xe_ya_idx = idx_xe_yn;
no.quad.xa_ye_idx = idx_xn_ye;
no.quad.xe_ye_idx = co.quad.xe_ye_idx;
no.priority = get_deform(*Points,no);
if ( no.priority > deform_thresh)
WorkObjects.push(no);
else
objs->push_back(no.quad);
}
// if we stopped, since maximal divisio of tiles reached
// collect latest ones
while (!WorkObjects.empty()) {
objs->push_back(WorkObjects.top().quad);
WorkObjects.pop();
}
return index;
}
XYPlaneExpose::XYPlaneExpose(const GL2DTexture& _Texture,const C3DTransformation& Deform,int z):
BasePlaneExpose(_Texture)
{
T3DVector2DField c(C2DBounds(Deform.get_size().x, Deform.get_size().y));
C3DBounds b(0,0,z);
C3DBounds e(Deform.get_size().x, Deform.get_size().y, z+1);
copy(Deform.begin_range(b, e), Deform.end_range(b, e), c.begin());
set_coordinates(c);
T3DVector2DField::iterator i = c.begin();
for (size_t y = 0; y < c.get_size().y; y++) {
for (size_t x = 0; x < c.get_size().x; x++,i++) {
(*i) = C3DFVector(x,y,z) - (*i); }
}
create_point_table();
}
XZPlaneExpose::XZPlaneExpose(const GL2DTexture& _Texture,const C3DTransformation& Deform,int y):
BasePlaneExpose(_Texture)
{
T3DVector2DField c(C2DBounds(Deform.get_size().x, Deform.get_size().z));
C3DBounds b(0,y,0);
C3DBounds e(Deform.get_size().x, y+1, Deform.get_size().z);
copy(Deform.begin_range(b, e), Deform.end_range(b, e), c.begin());
set_coordinates(c);
T3DVector2DField::iterator i = c.begin();
for (size_t z = 0; z < c.get_size().y; z++) {
for (size_t x = 0; x < c.get_size().x; x++,i++) {
(*i) = C3DFVector(x,y,z) - (*i);
}
}
create_point_table();
}
YZPlaneExpose::YZPlaneExpose(const GL2DTexture& _Texture,const C3DTransformation& Deform,int x):
BasePlaneExpose(_Texture)
{
T3DVector2DField c(C2DBounds(Deform.get_size().y, Deform.get_size().z));
C3DBounds b(x,0,0);
C3DBounds e(x+1, Deform.get_size().y, Deform.get_size().z);
copy(Deform.begin_range(b, e), Deform.end_range(b, e), c.begin());
set_coordinates(c);
T3DVector2DField::iterator i = c.begin();
for (size_t z = 0; z < c.get_size().y; z++) {
for (size_t y = 0; y < c.get_size().x; y++,i++) {
(*i) = C3DFVector(x,y,z) - (*i);
}
}
create_point_table();
}
namespace mia {
template class T2DDatafield;
}
miaviewit-1.0.5/viewit/pov_output.cc 0000644 0001750 0000677 00000005754 12151742235 014522 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
TPovOutput::TPovOutput(int snap_num)
{
stringstream s;
s << "pov_snap" << setw(5) << setfill('0') << snap_num << ".pov";
file = fopen(s.str().c_str(),"w");
if (!file)
std::runtime_error("unable to create pov-output file");
}
TPovOutput::~TPovOutput()
{
}
void TPovOutput::init(const C3DFVector& trans, const C3DFVector& rot, const C3DFVector& shift,float width,float height)
{
fprintf(file,"camera {\n\tlocation <0, 0, 0> ");
fprintf(file,"\n\tdirection < 0, 0, -1.6666>");
fprintf(file,"\n\tup < 0, 1, 0>");
fprintf(file,"\n\tright < %f/%f, 0, 0>",width,height);
fprintf(file,"\n\ttranslate <%f, %f, %f >",-trans.x, -trans.y, -trans.z);
fprintf(file,"\n\trotate <%f, 0, 0 >\n\trotate <0, %f, 0 >\n\trotate <0, 0, %f >",-rot.x, -rot.y, -rot.z);
fprintf(file,"\n\ttranslate < %f, %f, %f >\n}\n",-shift.x, -shift.y, -shift.z);
fprintf(file,"light_source {\n\t<128, 20, 256 >\n\tcolor rgb <1.0,1.0,1.0> \n");
fprintf(file,"\n\ttranslate <%f, %f, %f >",-trans.x, -trans.y, -trans.z);
fprintf(file,"\n\trotate <%f, 0, 0 >\n\trotate <0, %f, 0 >\n\trotate <0, 0, %f >",-rot.x, -rot.y, -rot.z);
fprintf(file,"\n\ttranslate < %f, %f, %f >\n}\n",-shift.x, -shift.y, -shift.z);
fprintf(file,"light_source {\n\t<-128, -220, 256 >\n\tcolor rgb <.3,.3,.3> \n");
fprintf(file,"\n\ttranslate <%f, %f, %f >",-trans.x, -trans.y, -trans.z);
fprintf(file,"\n\trotate <%f, 0, 0 >\n\trotate <0, %f, 0 >\n\trotate <0, 0, %f >",-rot.x, -rot.y, -rot.z);
fprintf(file,"\n\ttranslate < %f, %f, %f >\n}\n",-shift.x, -shift.y, -shift.z);
// fprintf(file,"light_source {\n\t< -200128, -220, -156 >\n\tcolor rgb <1.0,1.0,1.0> \n}\n");
}
void TPovOutput::write(const TDrawMap& data)
{
TDrawMap::const_iterator i = data.begin();
while ( i != data.end() ) {
if ((*i).second->is_visible()) {
fprintf(file,"#declare %s = ",(*i).first.c_str());
(*i).second->povray_output_attributes(file);
fprintf(file,"%s\n",(*i).first.c_str());
}
i++;
}
}
void TPovOutput::finish()
{
fclose(file);
}
miaviewit-1.0.5/viewit/shader.cc 0000644 0001750 0000677 00000011504 12151742235 013532 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#include
#define CUBE_MAP_SIZE 1
void CShading::pre_draw()
{
}
void CShading::post_draw()
{
}
void CShading::gl_attach()
{
}
void CShading::gl_detach()
{
}
CColorGradientSphereShading::CColorGradientSphereShading(const C3DFVector &v, const float &vmax)
: m_texture(new T4DVector[TEXTURE_ARRAY_SIZE_HEIGHT * TEXTURE_ARRAY_SIZE_WIDTH])
{
C3DFVector Color1(255, 0, 0);
C3DFVector Color2( 50, 50, 50);
C3DFVector Color3( 0, 0, 255);
// north pole (z-axis)
C3DFVector temp1;
C3DFVector temp2;
if (v.z < 1.0) {
temp1 = Color1;
temp1 *= 1.0 - v.z;
temp2 = Color2;
temp2 *= v.z;
} else {
temp1 = Color3;
temp1 *= v.z / vmax;
temp2 = Color2;
temp2 *= 1.0 - (v.z / vmax);
}
temp1 += temp2;
T4DVector temp3(GLubyte(temp1.x), GLubyte(temp1.y), GLubyte(temp1.z), 255);
m_texture[0] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[1] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[2] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[3] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
// south pole (z-axis)
m_texture[12] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[13] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[14] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[15] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
// x-axis
if (v.x < 1.0) {
temp1 = Color1;
temp1 *= 1.0 - v.x;
temp2 = Color2;
temp2 *= v.x;
} else {
temp1 = Color3;
temp1 *= v.x / vmax;
temp2 = Color2;
temp2 *= 1.0 - (v.x / vmax);
}
temp1 += temp2;
temp3 = T4DVector(GLubyte(temp1.x), GLubyte(temp1.y), GLubyte(temp1.z), 255);
m_texture[4] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[5] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[8] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[9] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
// y-axis
if (v.y < 1.0) {
temp1 = Color1;
temp1 *= 1.0 - v.y;
temp2 = Color2;
temp2 *= v.y;
} else {
temp1 = Color3;
temp1 *= v.y / vmax;
temp2 = Color2;
temp2 *= 1.0 - (v.y / vmax);
}
temp1 += temp2;
temp3 = T4DVector(GLubyte(temp1.x), GLubyte(temp1.y), GLubyte(temp1.z), 255);
m_texture[6] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[7] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[10] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
m_texture[11] = temp3; // T4DVector(temp1.x, temp1.y, temp1.z, 255);
}
CColorGradientSphereShading::~CColorGradientSphereShading()
{
delete [] m_texture;
}
void CColorGradientSphereShading::pre_draw() {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texture_name);
}
void CColorGradientSphereShading::post_draw()
{
glDisable(GL_TEXTURE_2D);
}
void CColorGradientSphereShading::gl_attach()
{
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
glGenTextures(1,&m_texture_name);
glBindTexture(GL_TEXTURE_2D, m_texture_name);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXTURE_ARRAY_SIZE_WIDTH,
TEXTURE_ARRAY_SIZE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE,
&m_texture[0].x);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}
void CColorGradientSphereShading::gl_detach()
{
glDeleteTextures(1,&m_texture_name);
}
CColorShading::CColorShading(const C3DFVector& color)
: m_color(color.x, color.y, color.z, 1.0)
{}
CColorShading::~CColorShading()
{}
void CColorShading::post_draw()
{}
void CColorShading::pre_draw()
{
glMaterialfv(GL_FRONT,GL_DIFFUSE,&m_color.x);
}
miaviewit-1.0.5/viewit/smarty.cc 0000644 0001750 0000677 00000012521 12151742235 013603 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#include
#include
#include
#include
using namespace std;
TSmarty::TSmarty(const C3DFVector& position, shared_ptr shape, shared_ptr shading ):
m_position(position),
m_shape(shape),
m_shading(shading)
{
if (!m_shape)
m_shape.reset(new CSphereShape(1.0f));
if (!m_shading)
m_shading.reset(new CShading());
}
TSmarty::TSmarty(const TSmarty& org):
m_position(org.m_position),
m_shape(org.m_shape),
m_shading(org.m_shading)
{
}
TSmarty& TSmarty::operator = (const TSmarty& org)
{
m_position = org.m_position;
m_shape = org.m_shape;
m_shading = org.m_shading;
return *this;
}
/** free that stuff, here only a dummy to provide a virtual destructor */
TSmarty::~TSmarty()
{
}
/** prepare the smarty for drawing */
void TSmarty::pre_draw()
{
glTranslatef(m_position.x,
m_position.y,
m_position.z);
m_shape->pre_draw();
m_shading->pre_draw();
}
/** clean up after drawing */
void TSmarty::post_draw()
{
m_shading->post_draw();
}
/** create the neccessary GL-instances */
void TSmarty::gl_attach()
{
m_shape->gl_attach();
m_shading->gl_attach();
}
/** remove the neccessary GL-instances */
void TSmarty::gl_detach()
{
m_shape->gl_detach();
m_shading->gl_detach();
}
TSmarties::TSmarties(const string& name)
: TDrawable(name), m_draw_smarty_step(1024)
{
set_light_model(1);
light_on();
culling_off();
//cull_front();
set_color1(TColor(.7,.7,.7,1.0));
set_color2(TColor(.3,.3,1.0,1.0));
set_color3(TColor(1.0,.3,.2,1.0));
// set_diffuse_front_color(TColor(1.0,0.0,0.0,1.0));
// set_diffuse_back_color(TColor(0.0,1.0,0.0,1.0));
}
TSmarties::~TSmarties()
{
std::list::iterator ibeg = m_smarties.begin();
std::list::iterator iend = m_smarties.end();
while (ibeg != iend) delete *ibeg++;
}
void TSmarties::add_smarty(TSmarty *smarty)
{
m_smarties.push_front(smarty);
}
void TSmarties::remove_smarty(TSmarty *smarty)
{
std::list::iterator ibeg = m_smarties.begin();
std::list::iterator iend = m_smarties.end();
while (ibeg != iend) {
if (*ibeg == smarty) {
delete smarty;
ibeg = iend;
} else
ibeg++;
}
}
void TSmarties::gl_attach()
{
m_GLSphereDrawList = glGenLists(1);
m_qobj = gluNewQuadric();
//gluQuadricNormals(m_qobj,(GLenum) GLU_SMOOTH);
gluQuadricDrawStyle(m_qobj,(GLenum) GLU_FILL);
gluQuadricOrientation(m_qobj,(GLenum) GLU_OUTSIDE );
//gluQuadricTexture(m_qobj, (GLenum) GL_TRUE);
glNewList(m_GLSphereDrawList,GL_COMPILE);
gluSphere(m_qobj, 1.0, 14, 14 );
glEndList();
std::list::iterator ibeg = m_smarties.begin();
std::list::iterator iend = m_smarties.end();
while (ibeg != iend) (*ibeg++)->gl_attach();
}
void TSmarties::gl_detach()
{
glDeleteLists(m_GLSphereDrawList,1);
gluDeleteQuadric(m_qobj);
std::list::iterator ibeg = m_smarties.begin();
std::list::iterator iend = m_smarties.end();
while (ibeg != iend) (*ibeg++)->gl_detach();
}
const char* TSmarties::get_classname() const
{
return SMARTIES_CLASSNAME;
}
void TSmarties::get_classname_list(list *classlist) const
{
if (classlist) {
classlist->push_front(SMARTIES_CLASSNAME);
TDrawable::get_classname_list(classlist);
}
}
void TSmarties::do_gl_draw(const TCamera& c) const
{
std::list::const_iterator ibeg = m_smarties.begin();
std::list::const_iterator iend = m_smarties.end();
glEnable(GL_NORMALIZE);
glMatrixMode(GL_MODELVIEW);
size_t i = 0;
while (ibeg != iend && m_draw_smarty_step > i) {
glPushMatrix();
(*ibeg)->pre_draw();
glCallList(m_GLSphereDrawList);
(*ibeg)->post_draw();
glPopMatrix();
ibeg++;
++i;
}
glDisable(GL_NORMALIZE);
}
void TSmarties::increase_smarty_number()
{
m_draw_smarty_step *= 2;
if (m_draw_smarty_step > m_smarties.size())
m_draw_smarty_step = m_smarties.size();
}
void TSmarties::decrease_smarty_number()
{
if (m_draw_smarty_step > 64)
m_draw_smarty_step /=2;
}
bool TSmarties::do_handle_key_event(int key)
{
switch (key) {
case 'N':
increase_smarty_number();
break;
case 'n':
decrease_smarty_number();
break;
default: return TDrawable::do_handle_key_event(key);
}
return true;
}
bool TSmarties::do_handle_command_event(PEventInfo info)
{
switch (info->get_command()) {
case EV_SMARTIES_INCREASE_SMARTY_NUMBER:
increase_smarty_number();
break;
case EV_SMARTIES_DECREASE_SMARTY_NUMBER:
decrease_smarty_number();
break;
default:
return TDrawable::do_handle_command_event(info);
}
return true;
}
miaviewit-1.0.5/viewit/planeexpose.hh 0000644 0001750 0000677 00000007355 12151742235 014632 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __planeexpose_h
#define __planeexpose_h
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include
using namespace mia;
#include
class BasePlaneExpose {
static float deform_thresh;
static unsigned int max_objs;
struct GLTexPoint {
T2DVector tex;
T3DVector normal;
T3DVector loc;
};
class TPoint{
C2DFVector tex;
C3DFVector normal;
C3DFVector deform;
public:
TPoint() {};
TPoint(const C3DFVector& d,float tx,float ty):
tex(tx,ty),normal(0.0,0.0,0.0),deform(d){
};
const C3DFVector& GetDeform() const {
return deform;
}
C3DFVector& normal_ref() {
return normal;
}
C3DFVector& deform_ref() {
return deform;
}
C2DFVector tex_ref() {
return tex;
}
void GetTexPoint(GLTexPoint *retval) const{
retval->tex = tex;
GLfloat normal_norm = normal.norm();
assert(normal_norm > 0.0);
retval->normal = normal/normal_norm;
retval->loc = deform;
}
};
struct TQuad {
int xa_ya_idx,xe_ya_idx,xe_ye_idx,xa_ye_idx;
};
struct TWorkObject {
float priority;
int xa,xe,ya,ye;
TQuad quad;
bool operator < (const TWorkObject& other)const {
return priority < other.priority;
}
};
enum plane_type {plane_xy, plane_xz, plane_yz};
int obj_size;
const GL2DTexture& Texture;
GLuint *ObjIndexArray;
GLTexPoint *PointArray;
GLTexPoint *fine_point_array;
protected:
typedef T2DDatafield T3DVector2DField;
private:
T3DVector2DField m_coordinates;
bool fine_display;
public:
BasePlaneExpose(const GL2DTexture& Texture);
virtual ~BasePlaneExpose();
void draw() const;
void set_fine_display(bool fine);
bool get_fine_display()const;
protected:
void set_coordinates(T3DVector2DField c) {
m_coordinates = c;
};
void create_point_table();
private:
float get_deform(const std::vector& Points,const TWorkObject& wo);
int generate_map(std::vector *Points,std::list *objs);
C3DFVector get_quad_normal(int x,int y,int xe,int ye)const;
void draw_point(const GLTexPoint& pPoint)const;
};
class XYPlaneExpose: public BasePlaneExpose {
public:
XYPlaneExpose(const GL2DTexture& _Texture,const C3DTransformation& Deform,int plane);
};
class XZPlaneExpose: public BasePlaneExpose {
public:
XZPlaneExpose(const GL2DTexture& _Texture,const C3DTransformation& Deform,int plane);
};
class YZPlaneExpose: public BasePlaneExpose {
public:
YZPlaneExpose(const GL2DTexture& _Texture,const C3DTransformation& Deform,int plane);
};
template
inline In bilin_interpol(const In& xa_ya,const In& xe_ya,const In& xa_ye,const In& xe_ye,
float dx,float mx,float dy,float my)
{
return ( (my * mx) * xa_ya + (my * dx) * xe_ya ) +
( (dy * mx) * xa_ye + (dy * dx) * xe_ye ) ;
}
inline bool BasePlaneExpose::get_fine_display()const
{
return fine_display;
}
#endif
miaviewit-1.0.5/viewit/voxelmove.cc 0000644 0001750 0000677 00000010730 12151742235 014310 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#include
#include
TVoxelCloud::TVoxelCloud(const string& name, int __size, float __time_step,
float __voxel_lifetime,
const TDeformation& __deformation,
const C3DFVectorSource& __source):
TDrawable(name),
_M_mover(__deformation),
_M_time_step(__time_step),
_M_voxel_lifetime(__voxel_lifetime),
_M_age(0),
_M_source(__source),
_M_size(__size)
{
init_voxels();
}
void TVoxelCloud::init_voxels()
{
_M_forward_voxels.clear();
_M_backward_voxels.clear();
for( int i = 0; i < _M_size; ++i) {
bool b = false;
C3DFVector s;
do {
s = _M_source();
b = _M_mover(s) < 1.0;
} while (b);
_M_forward_voxels.push_back(s);
_M_backward_voxels.push_back(s);
}
}
shared_ptr TVoxelCloud::get_vertex_list(int stride)const
{
shared_ptr result(new TVertexList);
TVoxelList::const_iterator li = _M_forward_voxels.begin();
TVoxelList::const_iterator le = _M_forward_voxels.end();
int i =0;
while (li != le) {
if (! (i % stride) )
result->push_back(*li);
++li;
++i;
}
li = _M_backward_voxels.begin();
le = _M_backward_voxels.end();
i =0;
while (li != le) {
if (! (i % stride) )
result->push_back(*li);
++li;
++i;
}
return result;
}
void TVoxelCloud::do_gl_draw(const TCamera& c) const
{
TVoxelList::const_iterator li = _M_forward_voxels.begin();
TVoxelList::const_iterator le = _M_forward_voxels.end();
glPointSize(2.0f);
glEnable(GL_POINT_SMOOTH);
glBegin(GL_POINTS);
glColor3fv(&get_color1().x);
while (li != le) {
glVertex3fv(&(*li).x);
++li;
}
li = _M_backward_voxels.begin();
le = _M_backward_voxels.end();
glColor3fv(&get_color2().x);
while (li != le) {
glVertex3fv(&(*li).x);
++li;
}
glEnd();
glDisable(GL_POINT_SMOOTH);
}
bool TVoxelCloud::do_handle_key_event(int key)
{
switch (key) {
case 'p':init_voxels();break;
case 'o':set_animated(true); break;
default:return TDrawable::do_handle_key_event(key);
}
return true;
}
bool TVoxelCloud::do_handle_command_event(PEventInfo info)
{
switch (info->get_command()) {
case EV_VOXELCLOUD_GET_STATE: {
TVoxelCloudEventInfo& ev = dynamic_cast(*info);
ev.set_lifetime(_M_voxel_lifetime);
return true;
}
case EV_VOXELCLOUD_SET_LIFETIME: {
TVoxelCloudEventInfo& ev = dynamic_cast(*info);
init_voxels();
_M_voxel_lifetime = ev.get_lifetime();
return true;
}
case EV_VOXELCLOUD_TOGGLE_DIFFUSION:
set_animated(is_animated());
return true;
}
return TDrawable::do_handle_command_event(info);
}
bool TVoxelCloud::animate()
{
if (!is_animated()) return false;
TVoxelList::iterator li = _M_forward_voxels.begin();
TVoxelList::iterator le = _M_forward_voxels.end();
while (li != le) {
_M_mover.forward(&*li,_M_time_step);
if (! _M_source.inside(*li)) {
*li = _M_source();
}
++li;
}
li = _M_backward_voxels.begin();
le = _M_backward_voxels.end();
while (li != le) {
_M_mover.backward(&*li,_M_time_step);
if (! _M_source.inside(*li)) {
*li = _M_source();
}
++li;
}
_M_age += _M_time_step;
if (_M_age >= _M_voxel_lifetime) set_animated(false);
return is_animated();
}
void TVoxelCloud::toggle_moving() {
set_animated(is_animated());
}
void TVoxelCloud::set_lifetime(float lifetime)
{
init_voxels();
_M_voxel_lifetime = lifetime;
}
float TVoxelCloud::get_lifetime() const
{
return _M_voxel_lifetime;
}
const char* TVoxelCloud::get_classname() const
{
return VOXELCLOUD_CLASSNAME;
}
void TVoxelCloud::get_classname_list(list *classlist) const
{
if (classlist) {
classlist->push_front(VOXELCLOUD_CLASSNAME);
TDrawable::get_classname_list(classlist);
}
}
miaviewit-1.0.5/viewit/selector.hh 0000644 0001750 0000677 00000002747 12151742235 014127 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __selector_hh
#define __selector_hh
#include
class TArrowListGrow;
#define SELECTOR_CLASSNAME "TSelector"
class TSelector: public TDrawable {
class TSelectorData *data;
public:
TSelector(const string& name,TCamera *c,TArrowListGrow *select_list);
~TSelector();
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
protected:
virtual bool do_handle_mouse_event(int button,int x, int y);
virtual bool do_handle_key_event(int key);
virtual void do_gl_draw(const TCamera& c) const;
virtual void draw_decoration(const C2DBounds& viewport,const TGLText& writer);
};
#endif
miaviewit-1.0.5/viewit/vistaloader.hh 0000644 0001750 0000677 00000002625 12151742235 014617 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __VISTALOADER_HH
#define __VISTALOADER_HH
#include
#include
#include
using namespace mia;
class TDrawable;
TDrawable* load_tensorfield(const std::string& name, const std::string& filename);
TDrawable* load_wireframe(const std::string& name, const std::string& filename);
bool load_texture_images(const std::string& filename, P3DTransformation defo,
TDrawable **xy_slice, const std::string& xy_slice_name,
TDrawable **xz_slice, const std::string& xz_slice_name,
TDrawable **yz_slice, const std::string& yz_slice_name);
#endif
miaviewit-1.0.5/viewit/Makefile.am 0000644 0001750 0000677 00000004453 12664577126 014034 0000000 0000000 # This file is part of viewitgui - a library and program for the
# visualization of 3D data sets.
#
# Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
#
# viewitgui 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.
#
# viewitgui is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with viewitgui; if not, see .
lib_LTLIBRARIES = libmiaviewit.la
#libmiaviewitI.la
AM_CPPFLAGS=@MIA_CFLAGS@ @VISTAIO_CFLAGS@ @GLIBMM_CFLAGS@
#libmiaviewitI_la_SOURCES = mesh_loader.cc mesh_loader.hh
if OGSL_VOLUMERENDERER
volrend_HEADER=volumerenderer.hh
volrend_SOURCES=volumerenderer.cc
else
volrend_DIST = volumerenderer.hh volumerenderer.cc
endif
libmiaviewitdir=$(includedir)/miaviewit-$(LT_RELEASE)/viewit
libmiaviewit_HEADERS = glerror.hh voxelmove.hh texture.hh cp_draw.hh trajects.hh \
mesh.hh drawable.hh glvector.hh planeexpose.hh glimage.hh camera.hh clip_plane.hh \
pov_output.hh arrow.hh event.hh glviewer.hh light.hh snapshot.hh gltext.hh \
selector.hh structures.hh slice.hh measure.hh glmesh.hh pixel.hh \
brown_diffuser.hh sphere.hh coordaxes.hh wireframe.hh shape.hh \
shader.hh smarty.hh vistaloader.hh status.hh 4DVector.hh voxelmover.hh \
$(volrend_HEADER)
libmiaviewit_la_SOURCES = glerror.cc voxelmove.cc \
texture.cc cp_draw.cc \
mesh.cc \
trajects.cc \
drawable.cc glvector.cc \
planeexpose.cc glimage.cc pov_output.cc \
camera.cc clip_plane.cc \
arrow.cc event.cc glviewer.cc light.cc \
snapshot.cc gltext.cc selector.cc slice.cc \
measure.cc trackball.h trackball.c glmesh.cc \
sphere.cc coordaxes.cc wireframe.cc \
smarty.cc shader.cc shape.cc \
vistaloader.cc version.cc\
$(volrend_SOURCES)
libmiaviewit_la_LDFLAGS = \
-version-info $(LT_VERSION_INFO) --as-needed
libmiaviewit_la_LIBADD = @GLIBMM_LIBS@ @MIA_LIBS@ @VISTAIO_LIBS@ -lgle -lGLU -lGL -lm
EXTRA_DIST=libviewit-config.hh.in $(volrend_DIST)
miaviewit-1.0.5/viewit/coordaxes.hh 0000644 0001750 0000677 00000003363 12151742235 014271 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __COORDAXES_HH
#define __COORDAXES_HH
#include
#define COORDAXES_CLASSNAME "TCoordAxes"
/// a class to handle OpenGL coordinate system (axes)
class TCoordAxes : public TDrawable {
protected:
C3DFVector __origin;
bool do_draw_decoration;
public:
TCoordAxes(const string& name);
TCoordAxes(const string& name, const C3DFVector& origin);
~TCoordAxes();
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist) const;
virtual void draw_decoration(const C2DBounds& viewport,const TGLText& writer);
protected:
/**
The Key-event handler for a TCoordAxes object. It obeys the following keys:
\begin{itemize}
\item 'd' - toggle the drawing of the legend
\end{itemize}
*/
virtual bool do_handle_key_event(int key);
virtual bool do_handle_command_event(PEventInfo info);
virtual void do_gl_draw(const TCamera& c) const;
};
#endif
miaviewit-1.0.5/viewit/glmesh.hh 0000644 0001750 0000677 00000006052 12151742235 013557 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __glmesh_hh
#define __glmesh_hh
#include
using namespace mia;
#include
#include
using namespace std;
class GL3DGrayTexture ;
#define GLMESH_CLASSNAME "TGLMesh"
enum EScaleType {
md_standart, /** *classlist)const;
virtual const char* get_classname()const;
/** attach the mesh to the gl context */
virtual void gl_attach();
void apply_color_change();
private:
/** handles the following key events
a - change color scale
d - toggle decoration display
f - tollgle front-/back-faceculling
g - toggle glossy surface
k - toggle culling
l - toggle light model (one-side/two-side)
\todo d should go into TDrawable
*/
bool do_handle_key_event(int key);
bool do_handle_command_event(PEventInfo info);
void do_gl_draw(const TCamera& c) const;
struct TGLMeshData *data;
};
#endif
miaviewit-1.0.5/viewit/measure.hh 0000644 0001750 0000677 00000003276 12151742235 013746 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __measure_hh
#define __measure_hh
#include
#include
using namespace mia;
#define MEASURE_CLASSNAME "TMeasure"
class TMeasure: public TDrawable {
class TMeasureData *data;
public:
TMeasure(const string& name,TCamera *c, P3DTransformation field);
~TMeasure();
bool handle_event(event_t *event);
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
void set_vectorfield(P3DTransformation field);
protected:
virtual bool do_handle_mouse_event(int button,int x, int y);
virtual bool do_handle_key_event(int key);
virtual void do_gl_draw(const TCamera& c) const;
virtual void draw_decoration(const C2DBounds& viewport,const TGLText& writer);
virtual void do_select();
virtual bool do_export(FILE *f)const;
virtual void gl_attach();
virtual void gl_detach();
};
#endif
miaviewit-1.0.5/viewit/arrow.cc 0000644 0001750 0000677 00000036071 12151742235 013424 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#include
#include
#include
#include
#include
#include
using namespace mia;
#include
#include
#include
using namespace std;
C3DFVector operator - (const TArrow& a, const TArrow& b)
{
return a.start - b.start;
}
struct Flipper{
void operator () (TArrow& a){
a.flip();
}
};
struct arrow_coll_t{
TArrow a;
double dist;
};
bool TArrowListData::do_export(FILE *f) const
{
assert(f);
errno = 0;
list::const_iterator i = arrow_list.begin();
list::const_iterator end = arrow_list.end();
fprintf(f,"%d\n", (unsigned int)arrow_list.size());
bool success = true;
while (i != end && success) {
success = (*i).do_export(f);
++i;
};
return errno==0;
}
bool TArrowListData::do_handle_key_event(int key)
{
switch (key) {
case 'n': n_draw_arrow_step *= 2; break;
case 'N': n_draw_arrow_step /= 2;
if (n_draw_arrow_step < 1 )
n_draw_arrow_step = 1;
break;
case 'm': if (magnify < 5.0) magnify += 1.0; break;
case 'M': if (magnify > 1.0) magnify -= 1.0; break;
case 'f': for_each(arrow_list.begin(), arrow_list.end(), Flipper());
break;
default:return false;
}
return true;
}
bool TArrowListData::do_handle_command_event(PEventInfo info)
{
switch (info->get_command()) {
case EV_ARROWLIST_INCREASE_ARROW_NUMBER:
do_handle_key_event('N');
return true;
case EV_ARROWLIST_DECREASE_ARROW_NUMBER:
do_handle_key_event('n');
return true;
case EV_ARROWLIST_INCREASE_ARROW_LENGTH:
do_handle_key_event('m');
return true;
case EV_ARROWLIST_DECREASE_ARROW_LENGTH:
do_handle_key_event('M');
return true;
case EV_ARROWLIST_FLIP_ARROWS:
do_handle_key_event('f');
return true;
}
return false;
}
void TArrowListData::add_arrow(const TArrow& arrow)
{
arrow_list.push_back(arrow);
}
void TArrowListData::clear()
{
arrow_list.clear();
}
TColor bottom_color(.5f,0.0f,.5f,0.3f);
TArrowList::TArrowList(const string& name):
TDrawable(name),
data(new TArrowListData())
{
light_on();
}
TArrowList::TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color):
TDrawable(name),
data(new TArrowListData())
{
set_color1(shaft_color);
set_color2(hat_color);
set_color3(bottom_color);
light_on();
}
TArrowList::TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color,
const TNormalVertexList& vl, const C3DTransformation& deform):
TDrawable(name),
data(new TArrowListData())
{
set_color1(shaft_color);
set_color2(hat_color);
set_color3(bottom_color);
TNormalVertexList::const_iterator end = vl.end();
for (TNormalVertexList::const_iterator i = vl.begin(); i != end; ++i) {
C3DFVector v = deform.apply( (*i).vertex);
v -= (v * (*i).normal) * (*i).normal;
if (v.norm2() > 0.5) {
data->add_arrow( TArrow((*i).vertex + v, (*i).vertex ));
}
}
light_on();
}
TArrowList::TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color,
const TVertexList& vl, const C3DTransformation& deform):
TDrawable(name),
data(new TArrowListData())
{
set_color1(shaft_color);
set_color2(hat_color);
set_color3(bottom_color);
TVertexList::const_iterator end = vl.end();
for (TVertexList::const_iterator i = vl.begin(); i != end; ++i) {
C3DFVector v = deform.apply( *i);
if (v.norm2() > 0.5) {
data->add_arrow( TArrow(*i + v, *i ));
}
}
light_on();
}
TArrowList::TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color,FILE *f, P3DTransformation deform):
TDrawable(name),
data(new TArrowListData())
{
set_color1(shaft_color);
set_color2(hat_color);
set_color3(bottom_color);
char buf[1024];
C3DFVector s,d;
if (!fgets(buf,1024,f)) {
delete data;
throw "empty file";
}
if (strncmp(buf,"ArrowList",9)) {
delete data;
throw "file is not an arrow list";
}
while(fgets(buf,1024,f)) {
if (buf[0] == '#')
continue;
if (sscanf(buf,"< %f, %f, %f > < %f, %f, %f >",&s.x, &s.y, &s.z, &d.x, &d.y, &d.z)!= 6)
continue;
if (deform) // if there is a vectorfield, override the readings
d = -1.0f * deform->apply(s);
data->add_arrow(TArrow(s,s+d));
}
cerr << name << " got " << data->size() << " arrows" << endl;
light_on();
}
const char* TArrowList::get_classname() const
{
return ARROWLIST_CLASSNAME;
}
void TArrowList::get_classname_list(list *classlist) const
{
if (classlist) {
classlist->push_front(ARROWLIST_CLASSNAME);
TDrawable::get_classname_list(classlist);
}
}
void TArrowList::double_arrow_number()
{
data->do_handle_key_event('N');
}
void TArrowList::half_arrow_number()
{
data->do_handle_key_event('n');
}
void TArrowList::increase_arrow_size()
{
data->do_handle_key_event('m');
}
void TArrowList::decrease_arrow_size()
{
data->do_handle_key_event('M');
}
int TArrowList::size()const
{
return data->size();
}
TArrowList::~TArrowList()
{
delete data;
}
void TArrowList::gl_attach()
{
data->gl_attach();
glNewList(data->get_arrow_disp_list(),GL_COMPILE);
glColor4fv(&get_color2().x);
data->draw_hat();
glEndList();
glNewList(data->get_arrow_disp_list()+1,GL_COMPILE);
glColor4fv(&get_color1().x);
data->draw_shaft();
glColor4fv(&get_color3().x);
data->draw_bottom();
glEndList();
glDisableClientState(GL_VERTEX_ARRAY);
}
void TArrowListData::gl_attach()
{
list::iterator i = arrow_list.begin();
list::iterator end = arrow_list.end();
while ( i != end ) {
(*i).gl_attach();
++i;
}
arrow_disp_list = glGenLists(2);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
}
class TArrowListData *TArrowList::get_data()const
{
return data;
}
bool TArrowList::do_handle_key_event(int key)
{
if (!data->do_handle_key_event(key))
return TDrawable::do_handle_key_event(key);
return true;
}
bool TArrowList::do_handle_command_event(PEventInfo info)
{
if (data->do_handle_command_event(info))
return true;
return TDrawable::do_handle_command_event(info);
}
void TArrowList::gl_detach()
{
data->gl_detach();
}
inline void TArrowListData::gl_detach()
{
glDeleteLists(arrow_disp_list,2);
}
void TArrowList::do_gl_draw(const TCamera& c) const
{
glEnable(GL_COLOR_MATERIAL);
data->do_gl_draw(c);
glDisable(GL_COLOR_MATERIAL);
}
void TArrowListData::do_gl_draw(const TCamera& c) const
{
list::const_iterator i = arrow_list.begin();
list::const_iterator end = arrow_list.end();
int draw_idx = 0;
while ( i != end ) {
++draw_idx;
if (draw_idx >= n_draw_arrow_step) {
glPushMatrix();
//glLoadIdentity();
(*i).init_position();
//c.gl_reuse_camera();
if (magnify != 1.0f)
glScalef(1.0,1.0,magnify);
glCallList(arrow_disp_list);
if (!c.low_detail())
glCallList(arrow_disp_list+1);
glPopMatrix();
draw_idx = 0;
}
++i;
}
}
TArrow::TArrow(const C3DFVector& start_, const C3DFVector& end_):
start(start_),
dir(end_ - start)
{
}
void TArrow::gl_attach()
{
const float umrechen_fak = 180.0f / M_PI;
float dir_norm = dir.norm();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// translation
glTranslatef(start.x,start.y,start.z);
C3DFVector axis(dir.y, -dir.x, 0.0f);
float axis_norm = axis.norm();
if (axis_norm != 0.0) { // rotation necessary
float angle = - umrechen_fak * acos(dir.z / dir_norm);
axis /= axis_norm;
glRotatef(angle,axis.x,axis.y,axis.z);
}
// scaling
float scale = dir_norm / 5.0;
if (scale < 1.0) {
glScalef(scale,scale,scale);
}else{
glScalef(1.0f,1.0f,scale);
}
glGetFloatv(GL_MODELVIEW_MATRIX,matrix);
}
void TArrow::flip()
{
start = start + dir;
dir *= -1;
gl_attach();
}
void TArrow::init_position()const
{
glMultMatrixf(matrix);
}
bool TArrow::do_export(FILE *f)const
{
assert(f);
return (fprintf(f,"< %f, %f, %f > < %f, %f, %f >\n",
start.x, start.y, start.z,
dir.x, dir.y, dir.z) > 0);
}
void TArrowListData::draw_hat()const
{
glBegin(GL_TRIANGLES);
for (int i = 0; i < 8; i++) {
glNormal3fv(&top_normal[i].x);
glVertex3fv(&vertices[3*top[3*i+2]]);
//glNormal3fv(&top_normal[i].x);
glVertex3fv(&vertices[3*top[3*i]]);
glNormal3fv(&top_normal[(i+1) % 8].x);
glVertex3fv(&vertices[3*top[3*i+1]]);
}
glEnd();
}
void TArrowListData::draw_shaft()const
{
glBegin(GL_QUAD_STRIP);
for (int i = 0; i < 9; i ++) {
glNormal3fv(&side_quad_strip_normal[i].x);
glVertex3fv(&side_quad_strip_vertex[2*i].x);
glVertex3fv(&side_quad_strip_vertex[2*i+1].x);
}
glEnd();
//glDrawElements(GL_QUAD_STRIP,18,GL_UNSIGNED_BYTE,side_quad_strip);
}
void TArrowListData::draw_bottom()const
{
glNormal3fv(bottom_normal);
glDrawElements(GL_TRIANGLES,24,GL_UNSIGNED_BYTE,bottom);
glNormal3fv(bottom_normal);
glDrawElements(GL_QUAD_STRIP,18,GL_UNSIGNED_BYTE,hat_bottom_quad_strip);
}
float TArrowListData::vertices[3*26] = {
+0.0f, 0.0f, 0.0f, // 0
+0.5f, 0.0f, 0.0f, // 1
+0.353f, 0.353f, 0.0f, // 2
+0.0f, 0.5f, 0.0f, // 3
-0.353f, 0.353f, 0.0f, // 4
-0.5f, 0.0f, 0.0f, // 5
-0.353f, -0.353f, 0.0f, // 6
+0.0f, -0.5f, 0.0f, // 7
+0.353f, -0.353f, 0.0f, // 8
+0.5f, 0.0f, 3.0f, // 9
+0.353f, 0.353f, 3.0f, // 10
+0.0f, 0.5f, 3.0f, // 11
-0.353f, 0.353f, 3.0f, // 12
-0.5f, 0.0f, 3.0f, // 13
-0.353f, -0.353f, 3.0f, // 14
+0.0f, -0.5f, 3.0f, // 15
+0.353f, -0.353f, 3.0f, // 16
+1.0f, 0.0f, 3.0f, // 17
+0.707f, 0.707f, 3.0f, // 18
+0.0f, 1.0f, 3.0f, // 19
-0.707f, 0.707f, 3.0f, // 20
-1.0f, 0.0f, 3.0f, // 21
-0.707f, -0.707f, 3.0f, // 22
+0.0f, -1.0f, 3.0f, // 23
+0.707f, -0.707f, 3.0f, // 24
+0.0f, 0.0f, 5.0f // 25
};
C3DFVector TArrowListData::side_quad_strip_normal[9]= {
C3DFVector(+1.0f, 0.0f, 0.0f), // 1
C3DFVector(+0.707f, 0.707f, 0.0f), // 2
C3DFVector(+0.0f, 1.0f, 0.0f), // 3
C3DFVector(-0.707f, 0.707f, 0.0f), // 4
C3DFVector(-1.0f, 0.0f, 0.0f), // 5
C3DFVector(-0.707f, -0.707f, 0.0f), // 6
C3DFVector(+0.0f, -1.0f, 0.0f), // 7
C3DFVector(+0.707f, -0.707f, 0.0f), // 8
C3DFVector(+1.0f, 0.0f, 0.0f) // 1
};
C3DFVector TArrowListData::side_quad_strip_vertex[18]= {
C3DFVector(+0.5f, 0.0f, 0.0f), // 1
C3DFVector(+0.5f, 0.0f, 3.0f), // 1
C3DFVector(+0.353f, 0.353f, 0.0f), // 2
C3DFVector(+0.353f, 0.353f, 3.0f), // 2
C3DFVector(+0.0f, 0.5f, 0.0f), // 3
C3DFVector(+0.0f, 0.5f, 3.0f), // 3
C3DFVector(-0.353f, 0.353f, 0.0f), // 4
C3DFVector(-0.353f, 0.353f, 3.0f), // 4
C3DFVector(-0.5f, 0.0f, 0.0f), // 5
C3DFVector(-0.5f, 0.0f, 3.0f), // 5
C3DFVector(-0.353f, -0.353f, 0.0f), // 6
C3DFVector(-0.353f, -0.353f, 3.0f), // 6
C3DFVector(+0.0f, -0.5f, 0.0f), // 7
C3DFVector(+0.0f, -0.5f, 3.0f), // 7
C3DFVector(+0.353f, -0.353f, 0.0f), // 8
C3DFVector(+0.353f, -0.353f, 3.0f), // 8
C3DFVector(+0.5f, 0.0f, 0.0f), // 1
C3DFVector(+0.5f, 0.0f, 3.0f) // 1
};
bool TArrowList::do_export(FILE *f)const
{
fprintf(f,"ArrowList\n");
return data->do_export(f);
}
TArrowListGrow::TArrowListGrow(const string& name,const TColor& _start_color, const TColor& _end_color,
P3DTransformation deform_):
TArrowList(name,_start_color,_end_color),
deform(deform_)
{
}
TArrowListGrow::TArrowListGrow(const string& name,const TColor& shaft_color, const TColor& hat_color,
FILE *f,P3DTransformation deform_):
TArrowList(name,shaft_color,hat_color,f,deform_),
deform(deform_)
{
}
TArrowListGrow::TArrowListGrow(const string& name,P3DTransformation deform_):
TArrowList(name),
deform(deform_)
{
}
void TArrowListGrow::add_vector(const C3DFVector& v)
{
gl_detach();
if (deform) {
cerr << "added vector with deform"<< endl;
C3DFVector delta = deform->apply(v);
get_data()->add_arrow(TArrow(v + delta, v ));
} else {
cerr << "added vector without deform"<< endl;
get_data()->add_arrow(TArrow(v, v ));
}
gl_attach();
}
void TArrowListGrow::set_vectorfield(P3DTransformation deform_)
{
gl_detach();
get_data()->clear();
deform = deform_;
gl_attach();
}
void TArrowListGrow::clear()
{
gl_detach();
get_data()->clear();
gl_attach();
}
const char* TArrowListGrow::get_classname() const
{
return ARROWLISTGROW_CLASSNAME;
}
void TArrowListGrow::get_classname_list(list *classlist) const
{
if (classlist) {
classlist->push_front(ARROWLISTGROW_CLASSNAME);
TArrowList::get_classname_list(classlist);
}
}
float TArrowListData::bottom_normal[3] = {0.0f, 0.0f, -1.0f};
unsigned char TArrowListData::bottom[24] = {
0,1,2,0,2,3,0,3,4,0,4,5,0,5,6,0,6,7,0,7,8,0,8,1
};
unsigned char TArrowListData::side_quad_strip[18]= {
1,9,2,10,3,11,4,12,5,13,6,14,7,15,8,16,1,9
};
unsigned char TArrowListData::hat_bottom_quad_strip[18] = {
9,17,10,18,11,19,12,20,13,21,14,22,15,23,16,24,9,17
};
C3DFVector TArrowListData::top_normal[8] = {
C3DFVector(+1.0f /sqrt(1.25f), 0.0f, 0.5f/sqrt(1.25f)), // 1
C3DFVector(+0.707f/sqrt(1.25f), 0.707f / sqrt(1.25f), 0.5f/sqrt(1.25f)), // 2
C3DFVector(+0.0f, 1.0f / sqrt(1.25f), 0.5f/sqrt(1.25f)), // 3
C3DFVector(-0.707f/sqrt(1.25f), 0.707f / sqrt(1.25f), 0.5f/sqrt(1.25f)), // 4
C3DFVector(-1.0f /sqrt(1.25f), 0.0f, 0.5f/sqrt(1.25f)), // 5
C3DFVector(-0.707f/sqrt(1.25f), -0.707f / sqrt(1.25f), 0.5f/sqrt(1.25f)), // 6
C3DFVector(+0.0f, -1.0f / sqrt(1.25f), 0.5f/sqrt(1.25f)), // 7
C3DFVector(+0.707f, -0.707f / sqrt(1.25f), 0.5f/sqrt(1.25f)) // 8
};
int TArrowListData::top[24] = {
17,18,25, 18,19, 25,19,20, 25,20,21, 25,21,22, 25,22,23, 25,23,24, 25,24,17,25
};
TArrowList::TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color, FILE *f):
TDrawable(name),
data(new TArrowListData())
{
set_color1(shaft_color);
set_color2(hat_color);
set_color3(bottom_color);
char buf[1024];
C3DFVector s,d;
if (!fgets(buf,1024,f)) {
delete data;
throw "empty file";
}
if (strncmp(buf,"ArrowList",9)) {
delete data;
throw "file is not an arrow list";
}
while(fgets(buf,1024,f)) {
if (buf[0] == '#')
continue;
if (sscanf(buf,"< %f, %f, %f > < %f, %f, %f >",&s.x, &s.y, &s.z, &d.x, &d.y, &d.z)!= 6)
continue;
data->add_arrow(TArrow(s,s+d));
}
cerr << name << " got " << data->size() << " arrows" << endl;
light_on();
}
miaviewit-1.0.5/viewit/structures.hh 0000644 0001750 0000677 00000002403 12151742235 014517 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __structures_hh
#define __structures_hh
#include
struct vertex_t {
C3DFVector vertex;
};
struct normal_vertex_t {
C3DFVector normal;
C3DFVector vertex;
};
struct color_normal_vertex_t {
TColor color;
C3DFVector normal;
C3DFVector vertex;
};
struct triangle_ui_t {
unsigned int a,b,c;
};
struct ushort_triangle_t {
unsigned short a,b,c;
};
typedef std::list TNormalVertexList;
#endif
miaviewit-1.0.5/viewit/texture.hh 0000644 0001750 0000677 00000006567 12151742235 014013 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __texture_h
#define __texture_h
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
using namespace std;
//typedef T2DImage C2DUBImage;
class GLTextureBase {
GLuint id;
public:
GLTextureBase();
virtual ~GLTextureBase();
virtual void bind() const=0;
GLuint get_id() const;
void gl_attach();
void gl_detach();
private:
virtual void do_gl_attach()=0;
virtual void do_gl_detach();
};
class GL1DAlphaTexture: public GLTextureBase {
public:
GL1DAlphaTexture();
void set_texture_data(GLubyte *alpha, int size);
void bind()const;
virtual void do_gl_attach();
};
class GL2DHTexture : public GLTextureBase {
int steps;
float ambient;
float diffuse;
float specular;
float shine;
float tm[16];
public:
GL2DHTexture(int _steps,float ambient, float diffuse, float specular,float shine);
void bind()const;
void create_textur_matrix(const mia::C3DFVector& light_pos,const mia::C3DFVector& camera_pos,const mia::C3DFVector& me);
void gl_texture_matrix_on()const;
void gl_texture_matrix_off()const;
private:
virtual void do_gl_attach();
};
class GL2DTexture : public GLTextureBase {
private:
struct TGL2DTextureData *data;
public:
typedef mia::C2DUBImage LuminData;
GL2DTexture(const mia::C2DBounds& in_size);
~GL2DTexture();
virtual void set_data(const LuminData& data);
float get_tex_xcoord(float x) const;
float get_tex_ycoord(float y) const;
void bind() const;
protected:
size_t get_inwidth() const;
size_t get_inheight() const;
TGL2DTextureData *get_data() const {
return data;
}
private:
virtual void do_gl_attach();
};
class GL3DGrayTexture : public GLTextureBase {
private:
struct TGL3DGrayTextureData *data;
public:
typedef mia::C3DUBDatafield GrayData;
GL3DGrayTexture(const mia::C3DBounds& in_size);
~GL3DGrayTexture();
virtual void set_data(const GrayData& data);
void bind() const;
private:
virtual void do_gl_attach();
};
class GL2DLATexture:public GL2DTexture {
public:
GL2DLATexture(const mia::C2DBounds& in_size);
virtual void set_data(const LuminData& data);
private:
void do_gl_attach();
};
class T2DAlphaSphere: public GLTextureBase {
mia::C2DUBImage shape;
bool dithered_texture;
public:
T2DAlphaSphere(int radius);
T2DAlphaSphere(const mia::C2DUBImage& _shape);
void bind() const;
bool has_dithered_texture()const;
private:
virtual void do_gl_attach();
};
inline GLuint GLTextureBase::get_id() const
{
return id;
}
inline bool T2DAlphaSphere::has_dithered_texture()const
{
return dithered_texture;
}
#endif
miaviewit-1.0.5/viewit/arrow.hh 0000644 0001750 0000677 00000012034 12151742235 013427 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __arrow_hh
#define __arrow_hh
#include
#include
#include
#include
#define ARROWLIST_CLASSNAME "TArrowList"
#define ARROWLISTGROW_CLASSNAME "TArrowListGrow"
/// a class to draw some arrows : set size is predefined
class TArrowList: public TDrawable {
class TArrowListData *data;
public:
TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color,
const TNormalVertexList& vl, const C3DTransformation& deform);
TArrowList(const string& name,const TColor& _start_color, const TColor& _end_color,
const TVertexList& vl, const C3DTransformation& deform);
TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color);
TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color, FILE *f,
P3DTransformation deform);
template
TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color,
InputIterator begin, InputIterator end, const C3DTransformation& deform_);
TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color, FILE *f);
TArrowList(const string& name);
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
~TArrowList();
int size()const;
void double_arrow_number();
void half_arrow_number();
void increase_arrow_size();
void decrease_arrow_size();
virtual void gl_attach();
virtual void gl_detach();
protected:
class TArrowListData *get_data()const;
private:
virtual void do_gl_draw(const TCamera& c) const;
virtual bool do_handle_key_event(int key);
virtual bool do_handle_command_event(PEventInfo info);
virtual bool do_export(FILE *f)const;
};
/// a class to draw some arrows : arrows can be added later
class TArrowListGrow: public TArrowList {
P3DTransformation deform;
public:
TArrowListGrow(const string& name,const TColor& _start_color, const TColor& _end_color,
P3DTransformation deform_);
TArrowListGrow(const string& name,const TColor& shaft_color, const TColor& hat_color,
FILE *f, P3DTransformation deform_);
TArrowListGrow(const string& name, P3DTransformation deform);
void add_vector(const C3DFVector& v);
void set_vectorfield(P3DTransformation deform_);
void clear();
virtual const char* get_classname()const;
virtual void get_classname_list(list *classlist)const;
};
class TArrow {
C3DFVector start, dir;
float matrix[16];
public:
TArrow(const C3DFVector& start, const C3DFVector& end);
void init_position()const;
void gl_attach();
void flip();
bool do_export(FILE *f)const;
friend C3DFVector operator - (const TArrow& a, const TArrow& b);
};
class TArrowListData {
static float bottom_normal[3];
static C3DFVector side_quad_strip_normal[9];
static C3DFVector side_quad_strip_vertex[18];
static C3DFVector top_normal[8];
static unsigned char bottom[24];
static unsigned char side_quad_strip[18];
static unsigned char hat_bottom_quad_strip[18];
static int top[24];
static float vertices[ 3 * 26 ];
float magnify;
int n_draw_arrow_step;
list arrow_list;
GLuint arrow_disp_list;
public:
TArrowListData():magnify(1.0f),n_draw_arrow_step(1){};
void draw_hat()const;
void draw_shaft()const;
void draw_bottom()const;
void add_arrow(const TArrow& arrow);
void clear();
void gl_attach();
void gl_detach();
bool do_export(FILE *f)const;
void do_gl_draw(const TCamera& c) const;
bool do_handle_key_event(int key);
bool do_handle_command_event(PEventInfo info);
GLuint get_arrow_disp_list()const {
return arrow_disp_list;
}
int size()const {
return arrow_list.size();
}
};
extern TColor bottom_color;
template < class InputIterator>
TArrowList::TArrowList(const string& name,const TColor& shaft_color, const TColor& hat_color,
InputIterator begin, InputIterator end, const C3DTransformation& deform):
TDrawable(name),
data(new TArrowListData())
{
set_color1(shaft_color);
set_color2(hat_color);
set_color3(bottom_color);
for (; begin != end; ++begin) {
C3DFVector v = deform.apply( *begin);
if (v.norm2() > 0.5) {
data->add_arrow( TArrow(*begin + v, *begin ));
}
}
light_on();
}
#endif
miaviewit-1.0.5/viewit/trackball.h 0000644 0001750 0000677 00000006272 11764474111 014077 0000000 0000000 /*
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* trackball.h
* A virtual trackball implementation
* Written by Gavin Bell for Silicon Graphics, November 1988.
*/
/*
* Pass the x and y coordinates of the last and current positions of
* the mouse, scaled so they are from (-1.0 ... 1.0).
*
* The resulting rotation is returned as a quaternion rotation in the
* first paramater.
*/
void
trackball(float q[4], float p1x, float p1y, float p2x, float p2y, float radius);
/*
* Given two quaternions, add them together to get a third quaternion.
* Adding quaternions to get a compound rotation is analagous to adding
* translations to get a compound translation. When incrementally
* adding rotations, the first argument here should be the new
* rotation, the second and third the total rotation (which will be
* over-written with the resulting new total rotation).
*/
void
add_quats(float *q1, float *q2, float *dest);
/*
* A useful function, builds a rotation matrix in Matrix based on
* given quaternion.
*/
void
build_rotmatrix(float m[4][4], float q[4]);
/*
* This function computes a quaternion based on an axis (defined by
* the given vector) and an angle about which to rotate. The angle is
* expressed in radians. The result is put into the third argument.
*/
void
axis_to_quat(float a[3], float phi, float q[4]);
miaviewit-1.0.5/viewit/brown_diffuser.hh 0000644 0001750 0000677 00000004675 12151742235 015327 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#ifndef __brow_diffuser_h
#define __brow_diffuser_h
#ifdef HAVE_CONFIG_H
#include
#endif
#include
using namespace mia;
#include
#include
#include
class TRandom {
public:
TRandom();
float operator ()(float max)const;
C3DFVector operator()(const C3DFVector& max)const;
};
typedef std::vector TBrownVectors;
TBrownVectors *brownies_init(int cnt, P3DTransformation _field);
class TBrownDiffuser{
TRandom rand_source;
P3DTransformation field;
T3DCounter counter;
TBrownVectors *seed;
TPixelList crosses;
TPixelList *forward_pixel_list;
TPixelList *backward_pixel_list;
TCollector collector;
float b_factor;
float f_factor;
C3DUBImage *mask;
public:
TBrownDiffuser(int seed_size, P3DTransformation _field,
float _b_factor, float _f_factor, C3DUBImage *mask);
~TBrownDiffuser();
void add_pixels(int cnt);
void move_pixels(float timestep);
void remove_dead_pixels();
TPixelList *get_backward_pixel_list()const;
TPixelList *get_forward_pixel_list()const;
void get_speed_list(TSpeedPixelQueue *collector, float speed_limit);
void get_critical_locations(TCriticalLocations *crosses, float max_dist_square);
int get_collected()const;
private:
void move_pixel(TPixel *pixel, float timestep);
};
// inline implementations
inline int TBrownDiffuser::get_collected()const
{
return collector.size();
}
inline TPixelList *TBrownDiffuser::get_backward_pixel_list()const
{
return backward_pixel_list;
}
inline TPixelList *TBrownDiffuser::get_forward_pixel_list()const
{
return forward_pixel_list;
}
#endif
miaviewit-1.0.5/viewit/volumerenderer.cc 0000644 0001750 0000677 00000064402 12151742235 015327 0000000 0000000 /* -*- mia-c++ -*-
*
* This file is part of viewitgui - a library and program for the
* visualization of 3D data sets.
*
* Copyright (c) Leipzig, Madrid 1999-2013 Mirco Hellmann, Gert Wollny
*
* viewitgui 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.
*
* viewitgui is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with viewitgui; if not, see .
*/
#define GL_GLEXT_PROTOTYPES 1
#include
#include
#include
#include
#include
/**************************************************************************************************************
the shader class represents a OpenGL Shading Langunge Shader
*/
class TGLShader{
public:
GLhandleARB ShadeProgram; //handle for the shaderprogram
TGLShader();
~TGLShader();
void useShader(); //use the created shader
void stopShader(); //unload the shader
static const char frag_shader[];
static const char vert_shader[];
private:
void install_shader(const GLcharARB *VertexShaderSource, const GLcharARB *FragmentShaderSource); //complete shader install
int shaderSize(char *fileName); //getting the size
int readShader(char *fileName, char *shaderText, int size); //read shader file
int readShaderSource(char *fileName, GLcharARB **Shader); //read the shader
GLhandleARB volumeVS, volumeFS; //handles for ver&frag
};
TGLShader::TGLShader()
{
install_shader(vert_shader, frag_shader);
}
TGLShader::~TGLShader()
{
glDeleteObjectARB(ShadeProgram); //delete the shading program
}
int TGLShader::shaderSize(char *fileName)
{
//
// Returns the size in bytes of the shader fileName.
// If an error occurred, it returns -1.
//
// File name convention:
//
// .vert
// .frag
//
FILE* shader;
char name[100];
int count;
strcpy(name, fileName);
//
// Open the file
//
shader = fopen(name, "r");
if (!shader)
return -1;
//
// Seek to the end and find its position
//
count = fseek(shader, 0, SEEK_END);
count = ftell(shader);
fclose(shader);
return count;
}
int TGLShader::readShader(char *fileName, char *shaderText, int size)
{
//
// Reads a shader from the supplied file and returns the shader in the
// arrays passed in. Returns 1 if successful, 0 if an error occurred.
// The parameter size is an upper limit of the amount of bytes to read.
// It is ok for it to be too big.
//
FILE *shader;
char name[100];
int count;
strcpy(name, fileName);
//
// Open the file
//
shader = fopen(name, "r");
if (!shader)
return -1;
//
// Get the shader from a file.
//
fseek(shader, 0, SEEK_SET);
count = fread(shaderText, 1, size, shader);
shaderText[count] = '\0';
if (ferror(shader))
count = 0;
else count = 1;
fclose(shader);
return count;
}
int TGLShader::readShaderSource(char *fileName, GLcharARB **Shader)
{
int Size;
//
// Allocate memory to hold the source of our shaders.
//
Size = shaderSize(fileName);
if (Size == -1)
{
return 0;
}
*Shader = (GLcharARB *) malloc(Size);
//
// Read the source code
//
if (!readShader(fileName, *Shader, Size))
{
return 0;
}
return 1;
}
void TGLShader::install_shader(const GLcharARB* VertexShaderSource, const GLcharARB* FragmentShaderSource)
{
GLint vertCompiled, fragCompiled; //status values
std::cerr << "compile shaders" << std::endl;
volumeVS = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); //creating the shader Objects
volumeFS = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
glShaderSourceARB(volumeVS, 1, &VertexShaderSource, NULL);
//setting the sources for shader Objects
glCompileShaderARB(volumeVS);//compile the shader Objects
glGetObjectParameterivARB(volumeVS,GL_OBJECT_COMPILE_STATUS_ARB, &vertCompiled); //check for succesful Compilation
if (!vertCompiled) {
std::cerr << "Vertexshader not compiled" << std::endl;
GLcharARB log[2048];
GLsizei msg_length = 0;
glGetInfoLogARB(volumeVS, 2048, &msg_length, log);
std::cerr << log << std::endl;
}
glShaderSourceARB(volumeFS, 1, &FragmentShaderSource, NULL);
glCompileShaderARB(volumeFS);
glGetObjectParameterivARB(volumeFS,GL_OBJECT_COMPILE_STATUS_ARB, &fragCompiled);
if (!fragCompiled) {
std::cerr << "Fragmentshader not compiled" << std::endl;
GLcharARB log[2048];
GLsizei msg_length = 0;
glGetInfoLogARB(volumeFS, 2048, &msg_length, log);
std::cerr << log << std::endl;
}
ShadeProgram = glCreateProgramObjectARB(); //create the shading program
}
void TGLShader::useShader()
{
GLint linked; //status value
glAttachObjectARB(ShadeProgram, volumeVS); //attache the loaded shaders
glAttachObjectARB(ShadeProgram, volumeFS);
glLinkProgramARB(ShadeProgram); //link the shading programm
glGetObjectParameterivARB(ShadeProgram,GL_OBJECT_LINK_STATUS_ARB, &linked); //check for succesful linking
if (!linked ) {
std::cerr << "ShadeProgram not linked\n";
std::cerr << gluErrorString(glGetError()) << std::endl;
}
glUseProgramObjectARB(ShadeProgram); //use the shading program
}
void TGLShader::stopShader()
{
GLint linked;
glDetachObjectARB(ShadeProgram, volumeVS); //detach the shader Objects
glDetachObjectARB(ShadeProgram, volumeFS);
glLinkProgramARB(ShadeProgram); //link an empty shade program
glGetObjectParameterivARB(ShadeProgram,GL_OBJECT_LINK_STATUS_ARB, &linked); //check for linking
if (!linked ) std::cerr << "ShadeProgram not linked" << std::endl;
glUseProgramObjectARB(ShadeProgram); //use the empty shader program
}
/**************************************************************************************************************/
//************** creating a plane based on 3 points ******************
C4DFVector CreatePlaneFromPoints(C3DFVector P0, C3DFVector P1, C3DFVector P2){
P1.x = P1.x - P0.x;
P1.y = P1.y - P0.y;
P1.z = P1.z - P0.z;
P2.x = P2.x - P0.x;
P2.y = P2.y - P0.y;
P2.z = P2.z - P0.z;
C4DFVector Plane;
Plane.x = P1.y*P2.z-P1.z*P2.y;
Plane.y = P1.z*P2.x-P1.x*P2.z;
Plane.z = P1.x*P2.y-P1.y*P2.x;
Plane.a=-(Plane.x*P0.x+Plane.y*P0.y+Plane.z*P0.z);
return Plane;
};
//************* creating a plane ortogonal to a line **********
C4DFVector CreatePlaneOnLine(C3DFVector Start, C3DFVector Direction, GLfloat t){
Start.x=Start.x+t*Direction.x;
Start.y=Start.y+t*Direction.y;
Start.z=Start.z+t*Direction.z;
C4DFVector Plane;
Plane.x = Direction.x;
Plane.y = Direction.y;
Plane.z = Direction.z;
Plane.a=-(Plane.x*Start.x+Plane.y*Start.y+Plane.z*Start.z);
return Plane;
};
//************* calculating an intersection between a line and a plane ******************
C3DFVector IntersectPlaneLine(C4DFVector Plane, C3DFVector LinePoint1, C3DFVector LinePoint2, GLfloat dividend){
LinePoint2.x = LinePoint2.x - LinePoint1.x;
LinePoint2.y = LinePoint2.y - LinePoint1.y;
LinePoint2.z = LinePoint2.z - LinePoint1.z;
if(dividend==0.0f) dividend=(Plane.x*LinePoint2.x+Plane.y*LinePoint2.y+Plane.z*LinePoint2.z);
C3DFVector IntersectPoint;
if (dividend!=0.0)
{
GLfloat t = -(Plane.x*LinePoint1.x+Plane.y*LinePoint1.y+Plane.z*LinePoint1.z+Plane.a)/dividend;
{
IntersectPoint.x=LinePoint1.x+t*LinePoint2.x;
IntersectPoint.y=LinePoint1.y+t*LinePoint2.y;
IntersectPoint.z=LinePoint1.z+t*LinePoint2.z;
}
}
return IntersectPoint;
};
//************ testing of an intersection between line and plane ******************
GLfloat DoesIntersectPlaneLine(C4DFVector Plane, C3DFVector LinePoint1, C3DFVector LinePoint2){
LinePoint2.x = LinePoint2.x - LinePoint1.x;
LinePoint2.y = LinePoint2.y - LinePoint1.y;
LinePoint2.z = LinePoint2.z - LinePoint1.z;
GLfloat dividend =(Plane.x*LinePoint2.x+Plane.y*LinePoint2.y+Plane.z*LinePoint2.z);
return dividend;
};
//************ calculating the first and last samplepoint and the sampledistance *****************
void FirstAndLastSamplePoint(C3DFVector& Peye, C3DFVector& Ptarget, C3DFVector& Direction, GLfloat& distance)
{
GLfloat PointsOfBox[8][3] = //definig all points of the box
{
{0.0f,0.0f,0.0f},
{0.0f,0.0f,256.0f},
{0.0f,256.0f,0.0f},
{0.0f,256.0f,256.0f},
{256.0f,0.0f,0.0f},
{256.0f,0.0f,256.0f},
{256.0f,256.0f,0.0f},
{256.0f,256.0f,256.0f}
};
C3DFVector VertexResults[8],Raypoint; //VertexResults will contain the intersections with the viewing ray, Raypoint is the actual Point of the Box
int PointsFound=0; //0 points found yet; can be less then 8
for(int corner=0;corner<8;corner++){
Raypoint.x=PointsOfBox[corner][0]; //source point is a boxcorner
Raypoint.y=PointsOfBox[corner][1];
Raypoint.z=PointsOfBox[corner][2];
C4DFVector Plane = CreatePlaneOnLine(Raypoint, Direction, 0); //creating a plane on the corner orthogonal to the ray
GLfloat Intersection = DoesIntersectPlaneLine(Plane,Peye,Ptarget); //checking fot intersection
if(Intersection!=0.0) //if intersection takes place, add the point to vertexlist
{
C3DFVector Pintersect = IntersectPlaneLine(Plane,Peye,Ptarget,Intersection); //calculating fot intersection
VertexResults[PointsFound].x=Pintersect.x; //adding the intersection
VertexResults[PointsFound].y=Pintersect.y;
VertexResults[PointsFound].z=Pintersect.z;
PointsFound++;
}
}
//loop over all intersections
GLfloat max = 0,min = 0; //helpvalues
int maxp = 0, minp = 0;
for(int i=0; imax) {max=distance; maxp=i;} //keep max and mins as value and point
if(distanceVertexAngles[pos]) pos=j;
TempAng=VertexAngles[h];
VertexAngles[h]=VertexAngles[pos];
VertexAngles[pos]=TempAng;
TempPol=Polylist[h];
Polylist[h]=Polylist[pos];
Polylist[pos]=TempPol;
}
}
//********** computing the gradient of the volumedataset *************
void get_gradient(GLubyte* volumetexture, C3DBounds in_size)
{
for(size_t zdir=0;zdir *classlist) const
{
if (classlist) {
classlist->push_front(VOLUMERENDERER_CLASSNAME);
TDrawable::get_classname_list(classlist);
}
}
bool TVolumeRenderer::do_handle_key_event(int key)
{
return TDrawable::do_handle_key_event(key);
}
bool TVolumeRenderer::do_handle_command_event(PEventInfo info)
{
//if (__data->do_handle_command_event(info))
// return true;
return TDrawable::do_handle_command_event(info);
}
void TVolumeRenderer::pass_transfer_table(const TransferTable& transfertable)
{
GLint texLoc2; //location value
glActiveTexture(GL_TEXTURE1); //activate textur 1
glBindTexture(GL_TEXTURE_1D,transfertexid);
glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //set the filters for 1D textures
glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexImage1D(GL_TEXTURE_1D,0, GL_RGBA, transfertable.size(), 0, GL_RGBA, GL_FLOAT, &transfertable[0]); //create the texture
texLoc2 = glGetUniformLocationARB(Shader->ShadeProgram, "TransferTable"); //locate the uniform in the shader
if (texLoc2==-1) std::cerr << "TransferTable not found" << std::endl; //check for existance
glUniform1iARB(texLoc2, 1); //pass the location to the shader
}
void TVolumeRenderer::gl_attach()
{
glEnable(GL_ALPHA_TEST); //enable alphatest for threshold
glGenTextures(1, &volumetexid); //generate a texture
glGenTextures(1, &transfertexid);
glEnable(GL_TEXTURE_3D); //enable 3dtextures
glEnable(GL_TEXTURE_1D); //enable 1dtextures
glActiveTexture(GL_TEXTURE0); //activate texture 0
glBindTexture(GL_TEXTURE_3D,volumetexid);
glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //set the filters
glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
C3DBounds in_size = _M_volumen_data.get_size(); //get the size of the volume data
C3DBounds size(1,1,1);
while (size.x < in_size.x) size.x <<= 1; //calculate the size for a surrounding 2*n texture
while (size.y < in_size.y) size.y <<= 1;
while (size.z < in_size.z) size.z <<= 1;
if((size.x>size.y)&&(size.x>size.z)) texsize=size.x; //finding the biggest size
else if(size.y>size.z) texsize=size.y; else texsize=size.z;
int in_texsize = in_size.x*in_size.y*in_size.z; //original volumedata size
volumetexture = new GLubyte[in_texsize*4]; //create storage for volumedata
C3DUBImage::const_iterator textsrc=_M_volumen_data.begin(); //get the begining of the data
for(int alpha=0; alphauseShader(); //use the shader
GLint texLoc; //texture location
texLoc = glGetUniformLocationARB(Shader->ShadeProgram, "VolumeTexture"); //passing the volumetextur location to shader
glUniform1iARB(texLoc, 0);
TransferTable tt(256);
TransferTable::iterator i = tt.begin();
for(size_t k=0;kShadeProgram, "LightDirection"); //getting the location for LigntDirection
GLfloat LightPos[4];
glGetLightfv(GL_LIGHT0,GL_POSITION,LightPos); //getting the light position
glUniform3fARB(var, LightPos[0], LightPos[1], LightPos[2]);
/* *** Passing a Light at EyePoint*****
glUniform3fARB(var, -Direction.x, -Direction.y, -Direction.z);
*/
/**************************** setting the threshold ****************************************/
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_ALPHA_TEST);
glAlphaFunc(GL_GEQUAL,threshold);
//**************************** getting first and last samplepoint ******************************
FirstAndLastSamplePoint(Peye, Ptarget, Direction, sampledistance);
sampledistance = sampledistance*(256.0f/(GLfloat(texsize)*slice_multiplier));
//**************************** loop over all the sampling points of the viewing ray ************
for(GLfloat Distance=0;Distance<1;Distance=Distance+sampledistance)
{
Plane=CreatePlaneOnLine(Peye, Direction, Distance); //creating a slicing plane at the samplepoint of the ray
IntersectionOfPlaneAndBox(Plane, VertexResults, PointsFound); //getting all intersectionpoints with the box
//if more than 3 points have been found an order must been given
if(PointsFound>3) {
AddingAveragePoint(VertexResults, PointsFound); //a point in the middle must be added to create triangles
int Polylist[7]={0,1,2,3,4,5,6}; //representing the order of the points
SortThePoints(VertexResults, PointsFound, Polylist); //bringing an order to the points
//rendering the triangles in their order
int next;
glBindTexture(GL_TEXTURE_3D,volumetexid);
glBegin(GL_TRIANGLES);
for(i=0;i