Commit 3d77088a authored by Kirill Terekhov's avatar Kirill Terekhov
Browse files

move graphical examples that require opengl and glut to separate repository

parent c75eb406
if (USE_MESH)
add_subdirectory(AdaptiveMesh)
add_subdirectory(DrawGrid)
add_subdirectory(DrawGridTests)
add_subdirectory(GridGen)
endif (USE_MESH)
if (USE_OPTIMIZER AND USE_SOLVER)
......@@ -11,7 +9,6 @@ if (USE_OPTIMIZER)
add_subdirectory(OptimizerFunction)
endif ()
if (USE_SOLVER)
add_subdirectory(DrawMatrix)
add_subdirectory(MatSolve)
endif (USE_SOLVER)
if (USE_SOLVER AND USE_MESH)
......
project(DrawGrid)
set(SOURCE main.cpp
rotate.cpp
clipboard.cpp
rotate.h
inc_glut.h
clipboard.h
color.h
coord.h
coord.cpp
octree.h
streamline.h
streamline.cpp
svg_line.h
svg_line.cpp
face2gl.h
face2gl.cpp
color_bar.h
color_bar.cpp
printtext.cpp
tga.h
tga.cpp
screenshot.h
screenshot.cpp
volumetric.h
volumetric.cpp
input.h
input.cpp
picker.h
picker.cpp
clipper.h
clipper.cpp
vector.h
vector.cpp)
find_package(OpenGL)
find_package(GLUT)
if(OPENGL_FOUND)
if(GLUT_FOUND)
message("linking DrawGrid with GLUT and OpenGL")
include_directories(${OPENGL_INCLUDE_DIR})
include_directories(${GLUT_INCLUDE_DIR})
add_executable(DrawGrid ${SOURCE})
target_link_libraries(DrawGrid inmost ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES})
if(USE_MPI)
target_link_libraries(DrawGrid ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(DrawGrid PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
install(TARGETS DrawGrid EXPORT inmost-targets RUNTIME DESTINATION bin)
else(GLUT_FOUND)
message("GLUT not found, not building DrawGrid")
endif(GLUT_FOUND)
else(OPENGL_FOUND)
message("OpenGL not found, not building DrawGrid")
endif(OPENGL_FOUND)
#include "clipboard.h"
#if defined(_WIN32)
#include <windows.h>
bool setTextToPasteboard(std::string as)
{
size_t reqLength = ::MultiByteToWideChar( CP_UTF8, 0, as.c_str(), (int)as.length(), 0, 0 );
std::wstring text( reqLength, L'\0' );
::MultiByteToWideChar( CP_UTF8, 0, as.c_str(), (int)as.length(), &text[0], (int)text.length() );
bool ok = false;
if (OpenClipboard(NULL))
{
EmptyClipboard();
HGLOBAL hClipboardData;
size_t bytes = text.length()+1 * sizeof(wchar_t);
hClipboardData = GlobalAlloc(GMEM_DDESHARE, bytes*2);
wchar_t * pchData = (wchar_t*)GlobalLock(hClipboardData);
wcscpy(pchData, text.c_str());
GlobalUnlock(hClipboardData);
SetClipboardData(CF_UNICODETEXT,hClipboardData);
CloseClipboard();
ok = true;
}
return ok;
}
std::string getTextFromPasteboard()
{
std::string clipBoardText="";
if (OpenClipboard(NULL))
{
HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT);
if(IsClipboardFormatAvailable(CF_UNICODETEXT))
{
wchar_t * pszText =NULL;
pszText = (wchar_t *)GlobalLock(hClipboardData);
if (pszText == NULL)
{
}
else
{
std::wstring pchData = pszText;
char * mbstr2 = new char[pchData.size()*4];
size_t bytes = pchData.length()+1 * sizeof(wchar_t);
WideCharToMultiByte(CP_UTF8,0,pchData.c_str(),bytes*2,mbstr2,bytes*2,NULL,NULL);
clipBoardText.append(mbstr2);
delete [] mbstr2;
}
GlobalUnlock(hClipboardData);
CloseClipboard();
}
}
return clipBoardText;
}
#elif defined(__APPLE__)
#include <Carbon/Carbon.h>
//AUTOFRAMEWORK(Carbon)
bool setTextToPasteboard(std::string str)
{
const char * byteArrayIndex = str.c_str();
OSStatus err = noErr;
static PasteboardRef pasteboard = NULL;
PasteboardCreate( kPasteboardClipboard, &pasteboard );
err = PasteboardClear( pasteboard );
//require_noerr( err, PasteboardClear_FAILED );
CFDataRef data;
data = CFDataCreate(kCFAllocatorDefault, (UInt8*)byteArrayIndex, strlen(byteArrayIndex)+1);
err = PasteboardPutItemFlavor( pasteboard, (PasteboardItemID)1, kUTTypeUTF8PlainText, data, 0);
//require_noerr( err, PasteboardPutItemFlavor_FAILED );
PasteboardPutItemFlavor_FAILED:
PasteboardClear_FAILED:
return err == noErr;
}
std::string getTextFromPasteboard()
{
std::string clipBoard = "";
OSStatus err = noErr;
ItemCount itemCount;
PasteboardSyncFlags syncFlags;
static PasteboardRef inPasteboard = NULL;
PasteboardCreate( kPasteboardClipboard, &inPasteboard );
char* data = NULL;
syncFlags = PasteboardSynchronize( inPasteboard );
err = badPasteboardSyncErr;
err = PasteboardGetItemCount( inPasteboard, &itemCount );
//require_noerr( err, CantGetPasteboardItemCount );
for( int itemIndex = 1; itemIndex <= itemCount; itemIndex++ )
{
PasteboardItemID itemID;
CFDataRef flavorData;
err = PasteboardGetItemIdentifier( inPasteboard, itemIndex, &itemID );
//require_noerr( err, CantGetPasteboardItemIdentifier );
err = PasteboardCopyItemFlavorData( inPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData );
if(err==noErr)data = (char*)CFDataGetBytePtr(flavorData);
if( data!=NULL && err==noErr )
clipBoard.append(data);
else
return "Error Pasting";
CantGetPasteboardItemIdentifier:
;
}
CantGetPasteboardItemCount:
return clipBoard;
}
#else
bool setTextToPasteboard(std::string str) {(void)str; return false;}
std::string getTextFromPasteboard() {return "";}
#endif
#ifndef _CLIPBOARD_H
#define _CLIPBOARD_H
#include <string>
bool setTextToPasteboard(std::string str);
std::string getTextFromPasteboard();
#endif
This diff is collapsed.
#ifndef _CLIPPER_H
#define _CLIPPER_H
#include "inmost.h"
#include "face2gl.h"
namespace INMOST
{
class kdtree
{
public:
struct entry
{
HandleType e;
float xyz[3];
entry(){}
entry(const entry & other);
entry & operator =(const entry & other);
} *set;
private:
int marked;
Mesh * m;
INMOST_DATA_ENUM_TYPE size;
float bbox[6];
kdtree * children;
void radix_sort(int dim, struct entry * temp);
void kdtree_build(int dim, int & done, int total, struct entry * temp);
kdtree();
inline int plane_bbox(Storage::real p[3], Storage::real n[3]) const;
bool sub_intersect_plane_edge(Tag clip_point, Tag clip_state, ElementArray<Cell> & cells, MarkerType mrk, Storage::real p[3], Storage::real n[3]);
void sub_intersect_plane_faces(Tag clip_state, Storage::real p[3], Storage::real n[3]);
void unmark_old_edges(Tag clip_state);
void clear_children();
public:
kdtree(Mesh * m);
kdtree(Mesh * m, HandleType * eset, INMOST_DATA_ENUM_TYPE size);
void intersect_plane_edge(Tag clip_point, Tag clip_state, ElementArray<Cell> & cells, MarkerType mark_cells, Storage::real p[3], Storage::real n[3]);
void intersect_plane_face(Tag clip_state, Storage::real p[3], Storage::real n[3]);
~kdtree();
};
class clipper
{
public:
struct edge_point
{
Storage::real val;
Storage::real xyz[3];
Storage::integer edge;
edge_point();
edge_point(Storage::real _xyz[3], Storage::integer n, float v);
bool operator ==(const edge_point& b) const;
bool operator !=(const edge_point& b) const;
void print();
};
private:
Tag clip_point, clip_state;
kdtree * tree;
Tag clips, clipsv, clipsn;
MarkerType marker;
ElementArray<Cell> cells;
Mesh * mm;
public:
~clipper();
clipper(Mesh * m);
Storage::real compute_value(Edge e, Storage::real * pnt);
void clip_plane(Storage::real p[3], Storage::real n[3]);
void gen_clip(std::vector<face2gl> & out, Storage::real n[3],bool elevation);
void draw_clip(INMOST_DATA_ENUM_TYPE pace, Storage::real n[3], bool elevation);
void draw_clip_edges(INMOST_DATA_ENUM_TYPE pace, Storage::real n[3], bool elevation);
INMOST_DATA_ENUM_TYPE size();
};
class bnd_clipper
{
Tag clip_state;
kdtree * tree; Mesh * mm;
HandleType * faces;
INMOST_DATA_ENUM_TYPE nfaces;
public:
~bnd_clipper();
bnd_clipper(Mesh * m, HandleType * _faces, INMOST_DATA_ENUM_TYPE size);
Storage::real compute_value(Node n1, Node n2, Storage::real * c1, Storage::real * c2, Storage::real * pnt);
void clip_plane(Storage::real p[3], Storage::real n[3]);
void gen_clip(std::vector<face2gl> & out, Storage::real p[3], Storage::real n[3], bool elevation);
void draw_clip(INMOST_DATA_ENUM_TYPE pace, Storage::real p[3], Storage::real n[3]);
void draw_clip_edges(INMOST_DATA_ENUM_TYPE pace);
INMOST_DATA_ENUM_TYPE size();
};
}
#endif
#ifndef _COLOR_H
#define _COLOR_H
#include "inc_glut.h"
#include <iostream>
#include <sstream>
struct color_t
{
float c[4];
color_t() { memset(c, 0, sizeof(float)* 4); }
color_t(float r, float g, float b)
{
c[0] = r;
c[1] = g;
c[2] = b;
c[3] = 1.0;
}
color_t(float r, float g, float b, float a)
{
c[0] = r;
c[1] = g;
c[2] = b;
c[3] = a;
}
color_t(const color_t & other) { memcpy(c, other.c, sizeof(float)* 4); }
color_t & operator =(color_t const & other)
{
memmove(c, other.c, sizeof(float)* 4);
return *this;
}
void set_color() const { glColor4fv(c); }
float & r() { return c[0]; }
float & g() { return c[1]; }
float & b() { return c[2]; }
float & a() { return c[3]; }
float r() const { return c[0]; }
float g() const { return c[1]; }
float b() const { return c[2]; }
float a() const { return c[3]; }
color_t operator *(float mult)const { return color_t(c[0] * mult, c[1] * mult, c[2] * mult, c[3] * mult); }
color_t operator +(color_t other)const{ return color_t(c[0] + other.c[0], c[1] + other.c[1], c[2] + other.c[2], c[3] + other.c[3]); }
color_t operator -(color_t other)const { return color_t(c[0] - other.c[0], c[1] - other.c[1], c[2] - other.c[2], other.c[3]); }
std::string svg_rgb() const
{
std::stringstream out;
out << "rgb(" << floor(r() * 255) << ", " << floor(g() * 255) << ", " << floor(b() * 255) << ")";
return out.str();
}
std::string svg_rgba_fill() const
{
std::stringstream out;
out << "fill=\"" << svg_rgb() << "\" fill-opacity=\"" << a() << "\"";
return out.str();
}
std::string svg_rgba_stroke() const
{
std::stringstream out;
out << "stroke=\"" << svg_rgb() << "\" stroke-opacity=\"" << a() << "\"";
return out.str();
}
};
#endif
\ No newline at end of file
#include "color_bar.h"
#include "inc_glut.h"
#include "svg_line.h"
#include <algorithm>
namespace INMOST
{
color_bar * color_bar::CommonColorBar = NULL;
Tag color_bar::vtag = Tag();
ElementType color_bar::vtype = NONE;
bool color_bar::smooth = false;
ElementType GetVisualizationType()
{
return color_bar::GetVisualizationType();
}
bool isVisualizationSmooth()
{
return color_bar::isVisualizationSmooth();
}
void color_bar::InitColorBar()
{
if (CommonColorBar)
delete CommonColorBar;
CommonColorBar = new color_bar;
}
void color_bar::DestroyColorBar()
{
delete CommonColorBar;
}
color_bar * color_bar::GetColorBar()
{
return CommonColorBar;
}
color_bar::~color_bar()
{
if (glIsTexture(texture))
glDeleteTextures(1, &texture);
}
color_bar::color_bar()
{
min = 0;
max = 1;
comment = "";
/*
ticks.push_back(0.f);
ticks.push_back(0.2f);
ticks.push_back(0.4f);
ticks.push_back(0.6f);
ticks.push_back(0.8f);
ticks.push_back(1.f);
//colors.push_back(color_t(1,0,0));
//colors.push_back(color_t(1,1,0));
//colors.push_back(color_t(0,1,0));
//colors.push_back(color_t(0,1,1));
//colors.push_back(color_t(0,0,1));
//colors.push_back(color_t(1,0,1));
colors.push_back(color_t(1,0,1));
colors.push_back(color_t(0,0,1));
colors.push_back(color_t(0,1,1));
colors.push_back(color_t(0,1,0));
colors.push_back(color_t(1,1,0));
colors.push_back(color_t(1,0,0));
*/
//inversed gnuplot color scheme
ticks.push_back(0.f);
ticks.push_back(0.05f);
ticks.push_back(0.5f);
ticks.push_back(0.75f);
ticks.push_back(0.95f);
ticks.push_back(1.f);
colors.push_back(color_t(1, 1, 1));
colors.push_back(color_t(1, 1, 0));
colors.push_back(color_t(0.85, 0, 0));
colors.push_back(color_t(0.65, 0.25, 0.85));
colors.push_back(color_t(0.45, 0, 0.55));
colors.push_back(color_t(0, 0, 0));
//colors.push_back(color_t(1,0,0));
}
color_t color_bar::pick_color(float value) const
{
if (value < min)
return color_t(0.4, 1.0, 0.4);
if (value > max)
return color_t(0, 0.6, 0);
float t = (value - min) / (max - min);
std::vector<float>::const_iterator it = std::lower_bound(ticks.begin(), ticks.end(), t);
size_t pos = it - ticks.begin();
if (it == ticks.end() || pos >= ticks.size())
{
return colors.back();
}
if (pos == 0)
{
return colors[0];
}
float interp = (t - ticks[pos - 1]) / (ticks[pos] - ticks[pos - 1]);
return (colors[pos] * interp + colors[pos - 1] * (1 - interp));
}
void color_bar::InitTexture()
{
samples = 512 ;
float * pixel_array = new float[(samples + 2) * 4];
for (int q = 0; q < samples + 2; ++q)
{
float t = 1.0f*q / static_cast<float>(samples + 1);
color_t c = pick_color(t*(max-min)+min);
//countour lines
//if( ((q+1) % 128 == 0 || (q+1) % 128 == 127) && (q+1) < samples )
// c = pick_color(1-t) + color_t(0,2*t*(1-t),0);
pixel_array[(q)* 4 + 0] = c.r();
pixel_array[(q)* 4 + 1] = c.g();
pixel_array[(q)* 4 + 2] = c.b();
pixel_array[(q)* 4 + 3] = c.a();
}
pixel_array[0] = 0;
pixel_array[1] = 1;
pixel_array[2] = 0;
pixel_array[3] = 1;
pixel_array[(samples + 1) * 4 + 0] = 0;
pixel_array[(samples + 1) * 4 + 1] = 1;
pixel_array[(samples + 1) * 4 + 2] = 0;
pixel_array[(samples + 1) * 4 + 3] = 1;
glPrintError();
//glEnable(GL_TEXTURE);
//glPrintError();
glEnable(GL_TEXTURE_1D);
glPrintError();
glGenTextures(1, &texture);
glPrintError();
glBindTexture(GL_TEXTURE_1D, texture);
glPrintError();
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage1D(GL_TEXTURE_1D, 0, 4, samples + 2, 1, GL_RGBA, GL_FLOAT, pixel_array);
glPrintError();
std::cout << "Created texture " << texture << std::endl;
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glPrintError();
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glPrintError();
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glPrintError();
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glPrintError();
UnbindTexture();
delete[] pixel_array;
}
void color_bar::BindTexture()
{
//glDisable(GL_TEXTURE_GEN_S );
//glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_1D);
glPrintError();
glBindTexture(GL_TEXTURE_1D, texture);
glPrintError();
}
void color_bar::UnbindTexture()
{
//glDisable(GL_TEXTURE_1D);
glDisable(GL_TEXTURE_1D);
glPrintError();
}
double color_bar::pick_texture(double value) const
{
double eps = 1.0 / static_cast<double>(samples);
return (value - min) / (max - min)*(1 - 2 * eps) + eps;
//return std::max(std::min((value-min)/(max-min),0.99),0.01);
}
void color_bar::Draw()
{
float text_pos = -0.89;
float left = -0.95;
float right = -0.9;
float bottom = -0.75;
float top = 0.75;
BindTexture();
glBegin(GL_QUADS);
glTexCoord1d(1.0 / 1024.0);
glVertex2f(left, bottom);
glVertex2f(right, bottom);
glTexCoord1d(1.0);
glVertex2f(right, top);
glVertex2f(left, top);
/*
for(int i = 0; i < ticks.size()-1; ++i)
{
colors[i].set_color();
glVertex2f(left,bottom+ticks[i]*(top-bottom));