Commit f23b08df by Kirill Terekhov

Some fixes and updates

Matrix of integers in inmost_dense.h.

Fix some warnings in grdecl reader in mesh_ecl_file.cpp.

Fix for mean value calculation over faces in geometry.cpp.

Added base64 encoding/decoding for future binary vtu reader.

Some improvements for input handling on mac in OldDrawGrid example.
parent 54f75cbe
#ifndef _INC_GLUT_H
#define _INC_GLUT_H
#if defined (__APPLE__) || defined(MAXOSX)
#if defined (__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#endif
#if defined(_WIN32)
......
#include "input.h"
#include "inc_glut.h"
#include <stdlib.h>
#include "clipboard.h"
#include <iostream>
/*
#if defined(__APPLE__) || defined(MACOSX)
#include <Carbon/Carbon.h>
KeyMap keyStates;
bool IS_KEYDOWN( uint16_t vKey )
{
uint8_t index = vKey / 32 ;
uint8_t shift = vKey % 32 ;
return keyStates[index].bigEndianValue & (1 << shift) ;
}
bool getGetCommandModifier()
{
// This grabs all key states, then checks if you were holding down command or not
GetKeys(keyStates) ;
if( IS_KEYDOWN( kVK_Command ) )
return true;
return false;
}
#endif
*/
Input::Input(int * val, std::string comment) : comment(comment)
{
input_link = val;
type = Integer;
canceled = false;
done = false;
done = false;
noctrl = false;
str = "";
}
Input::Input(double * val, std::string comment) : comment(comment)
......@@ -15,7 +39,8 @@ Input::Input(double * val, std::string comment) : comment(comment)
input_link = val;
type = Double;
canceled = false;
done = false;
done = false;
noctrl = false;
str = "";
}
Input::Input(char * val, std::string comment) : comment(comment)
......@@ -23,16 +48,18 @@ Input::Input(char * val, std::string comment) : comment(comment)
input_link = val;
type = String;
canceled = false;
done = false;
done = false;
noctrl = false;
str = "";
}
Input::Input(void * link, InputType type, std::string comment) : comment(comment), input_link(link), type(type)
{
canceled = false;
done = false;
done = false;
noctrl = false;
str = "";
}
Input::Input(const Input & other) :str(other.str), comment(other.comment), input_link(other.input_link), type(other.type), done(other.done), canceled(other.canceled)
Input::Input(const Input & other) :str(other.str), comment(other.comment), input_link(other.input_link), type(other.type), done(other.done), canceled(other.canceled), noctrl(other.noctrl)
{
}
Input & Input::operator = (Input const & other)
......@@ -42,14 +69,38 @@ Input & Input::operator = (Input const & other)
str = other.str;
type = other.type;
canceled = other.canceled;
done = other.done;
done = other.done;
noctrl = other.noctrl;
return *this;
}
void Input::KeyPress(char c)
{
if (c == 13)
bool ctrl = false;
//#if defined(__APPLE__) || defined(MACOSX)
// ctrl = getGetCommandModifier();
//#else
ctrl = glutGetModifiers() & (GLUT_ACTIVE_CTRL);
//#endif
if( (c == 'v' || c == 'V' || c == 22) && ctrl && !noctrl ) //paste
{
std::string paste = getTextFromPasteboard();
std::cout << "paste: " << paste << std::endl;
if( !paste.empty() )
{
noctrl = true;
for(int k = 0; k < paste.length(); ++k) KeyPress(paste[k]);
noctrl = false;
}
}
else if( (c == 'c' || c == 'C' || c == 3) && ctrl ) //copy
{
std::string copy = GetString();
std::cout << "copy: " << copy << std::endl;
setTextToPasteboard(copy);
}
else if (c == 13)
{
done = true;
......@@ -58,7 +109,11 @@ void Input::KeyPress(char c)
else if (type == String) strcpy((char *)input_link, str.c_str());
glutPostRedisplay();
}
#if defined(__APPLE__) || defined(MACOSX)
else if (c == 127 || c == 8)
#else
else if (c == 8)
#endif
{
if (!str.empty()) str.erase(str.size() - 1);
glutPostRedisplay();
......
......@@ -17,7 +17,7 @@ private:
InputType type;
bool done;
bool canceled;
bool noctrl;
public:
Input(int * val, std::string comment);
Input(double * val, std::string comment);
......
......@@ -12,7 +12,7 @@
#include <stdarg.h>
#include "inc_glut.h"
#include <iomanip>
#include "clipboard.h"
#include "color.h"
#include "coord.h"
#include "octree.h"
......@@ -405,27 +405,12 @@ void keyboard(unsigned char key, int x, int y)
{
(void) x;
(void) y;
printf("%d %d\n",(int)key,(int)glutGetModifiers());
if( glutGetModifiers() & (GLUT_ACTIVE_CTRL) )
std::cout << "pressed " << ((char)(key)) << " int " << ((int)key) << " ctrl " << (glutGetModifiers() & GLUT_ACTIVE_CTRL ? "yes" : "no") << " shift " << (glutGetModifiers() & GLUT_ACTIVE_SHIFT ? "yes" : "no") << " alt " << (glutGetModifiers() & GLUT_ACTIVE_ALT ? "yes" : "no") << std::endl;
if( CommonInput != NULL )
{
if( (key == 'v' || key == 'V' || key == 22) && (glutGetModifiers() & GLUT_ACTIVE_CTRL) ) //paste
{
std::string paste = getTextFromPasteboard();
std::cout << "paste: " << paste << std::endl;
if( !paste.empty() )
{
for(int k = 0; k < paste.length(); ++k)
CommonInput->KeyPress(paste[k]);
}
}
else if( (key == 'c' || key == 'C' || key == 3) && (glutGetModifiers() & GLUT_ACTIVE_CTRL) ) //copy
{
std::string copy = CommonInput->GetString();
std::cout << "copy: " << copy << std::endl;
setTextToPasteboard(copy);
}
else CommonInput->KeyPress(key);
CommonInput->KeyPress(key);
return;
}
if( key == 27 )
......@@ -737,6 +722,7 @@ void keyboard(unsigned char key, int x, int y)
mesh->Save("mesh.vtk");
mesh->Save("mesh.pmf");
mesh->Save("mesh.xml");
mesh->Save("mesh.gmv");
}
else if( key == 't' )
{
......
......@@ -88,6 +88,27 @@ namespace INMOST
#endif //USE_SOLVER
#if defined(USE_MESH)
///
/*
class BlockEntry :public AbstractEntry
{
INMOST_DATA_ENUM_TYPE reg_index;
std::vector<Tag> unknown_tags;
std::vector<Tag> bitmask_tags;
std::vector<INMOST_DATA_ENUM_TYPE> comp;
std::vector<INMOST_DATA_ENUM_TYPE> eqn_pos;
std::vector<INMOST_DATA_ENUM_TYPE> unk_pos;
Tag index_tag;
MarkerType mask;
ElementType etype;
public:
BlockEntry() : reg_index(ENUMUNDEF) {}
void AddTag(ElementType etype, Tag value, Tag bitmask = Tag(), MarkerType mask = 0, int eqn = -1, int unk = -1);
rMatrix Value(const Storage & e) const;
iMatrix Index(const Storage & e) const;
vMatrix operator [](const Storage & e) const;
};
*/
/// The Automatizator class helps in defining primary unknowns of the model and
/// enhances user experience in interaction with automatic differentiation functionality.
/// User may declare real-typed mesh data as primary unknowns on the mesh with the
......
......@@ -10,14 +10,21 @@ namespace INMOST
/// Structure that selects desired class, depending on the operation.
template<class A, class B> struct Promote;
template<> struct Promote<INMOST_DATA_INTEGER_TYPE, INMOST_DATA_INTEGER_TYPE> {typedef INMOST_DATA_INTEGER_TYPE type;};
template<> struct Promote<INMOST_DATA_INTEGER_TYPE, INMOST_DATA_REAL_TYPE> {typedef INMOST_DATA_REAL_TYPE type;};
template<> struct Promote<INMOST_DATA_REAL_TYPE, INMOST_DATA_INTEGER_TYPE> {typedef INMOST_DATA_REAL_TYPE type;};
template<> struct Promote<INMOST_DATA_REAL_TYPE, INMOST_DATA_REAL_TYPE> {typedef INMOST_DATA_REAL_TYPE type;};
#if defined(USE_AUTODIFF)
template<> struct Promote<INMOST_DATA_INTEGER_TYPE, variable> {typedef variable type;};
template<> struct Promote<INMOST_DATA_REAL_TYPE, variable> {typedef variable type;};
template<> struct Promote<variable, INMOST_DATA_INTEGER_TYPE> {typedef variable type;};
template<> struct Promote<variable, INMOST_DATA_REAL_TYPE> {typedef variable type;};
template<> struct Promote<variable, variable> {typedef variable type;};
template<> struct Promote<INMOST_DATA_INTEGER_TYPE, hessian_variable> {typedef hessian_variable type;};
template<> struct Promote<INMOST_DATA_REAL_TYPE, hessian_variable> {typedef hessian_variable type;};
template<> struct Promote<hessian_variable, INMOST_DATA_REAL_TYPE> {typedef hessian_variable type;};
template<> struct Promote<variable, hessian_variable> {typedef hessian_variable type;};
template<> struct Promote<hessian_variable, INMOST_DATA_INTEGER_TYPE> {typedef hessian_variable type;};
template<> struct Promote<hessian_variable, INMOST_DATA_REAL_TYPE> {typedef hessian_variable type;};
template<> struct Promote<hessian_variable, variable> {typedef hessian_variable type;};
template<> struct Promote<hessian_variable, hessian_variable> {typedef hessian_variable type;};
#endif
......@@ -94,6 +101,16 @@ namespace INMOST
assign((*this)(i,j),other(i,j));
return *this;
}
/// Assign value to all entries of the matrix.
/// @param b Assigned value.
/// @return Reference to matrix.
AbstractMatrix & operator =(Var const & b)
{
for(enumerator i = 0; i < Rows(); ++i)
for(enumerator j = 0; j < Cols(); ++j)
assign((*this)(i,j),b);
return *this;
}
/// Obtain number of rows.
/// @return Number of rows.
virtual enumerator Rows() const = 0;
......@@ -1783,6 +1800,8 @@ namespace INMOST
{
return ::INMOST::SubMatrix<Var, storage_type>(*this, first_row, last_row, first_col, last_col);
}
/// shortcut for matrix of integer values.
typedef Matrix<INMOST_DATA_INTEGER_TYPE> iMatrix;
/// shortcut for matrix of real values.
typedef Matrix<INMOST_DATA_REAL_TYPE> rMatrix;
#if defined(USE_AUTODIFF)
......
......@@ -2290,7 +2290,7 @@ namespace INMOST
throw BadFile;
}
//may end after this record, the rest is defaulted
if (state != ECL_WELSPECS_PHASE && *(pend - 1) == '/' || *p == '/')
if ((state != ECL_WELSPECS_PHASE && *(pend - 1) == '/') || *p == '/')
{
wells_sched[welspecs_cur.first].wspec = welspecs_cur.second;
//welspecs[welspecs_cur.first] = welspecs_cur.second;
......@@ -2415,7 +2415,7 @@ namespace INMOST
}
if (p == pend) break;
//may end after this record, the rest is defaulted
if (compdat_cur.second.WI > 0 && *(pend - 1) == '/' || *p == '/')
if ((compdat_cur.second.WI > 0 && *(pend - 1) == '/') || *p == '/')
{
//compdat[compdat_cur.first].push_back(compdat_cur.second);
wells_sched[compdat_cur.first].compdat[(int)tsteps.size()].push_back(compdat_cur.second);
......
......@@ -906,8 +906,6 @@ namespace INMOST
*ret = fabs(*ret);
faces.RemPrivateMarker(rev);
mesh->ReleasePrivateMarker(rev);
//std::cout << "volume is " << *ret/3.0 << " was " << was << " for " << me->LocalID() << std::endl;
}
*ret /= 3.0;
......@@ -1426,9 +1424,7 @@ namespace INMOST
{
integer dim = m->GetDimensions();
real val = 0, vol = 0, tvol,tval;
real normal[3];
real v1[3] = {0,0,0},v2[3] = {0,0,0}, product[3] = {0,0,0};
m->GetGeometricData(GetHandle(),NORMAL,normal);
ElementArray<Node> nodes = getNodes();
real_array av0 = nodes.front().Coords();
for(ElementArray<Node>::iterator it = ++nodes.begin(); it != nodes.end(); it++)
......@@ -1441,7 +1437,7 @@ namespace INMOST
vec_diff(av1.data(),av0.data(),v1,dim);
vec_diff(av2.data(),av0.data(),v2,dim);
vec_cross_product(v1,v2,product);
tvol = vec_dot_product(product,normal,dim)*0.5;
tvol = sqrt(vec_dot_product(product,product,dim))*0.5;
val += tval*tvol;
vol += tvol;
it = jt;
......
......@@ -3,11 +3,13 @@ set(SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/timer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/xml.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/base64.cpp
PARENT_SCOPE
)
set(HEADER
${HEADER}
${CMAKE_CURRENT_SOURCE_DIR}/utils.h
${CMAKE_CURRENT_SOURCE_DIR}/base64.h
PARENT_SCOPE
)
\ No newline at end of file
#include "base64.h"
#include <string>
#include <iostream>
namespace INMOST
{
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static inline bool is_base64(BYTE c)
{
return (isalnum(c) || (c == '+') || (c == '/'));
}
std::string base64_encode(BYTE const* buf, unsigned int bufLen)
{
std::string ret;
int i = 0;
int j = 0;
BYTE char_array_3[3];
BYTE char_array_4[4];
while (bufLen--)
{
char_array_3[i++] = *(buf++);
if (i == 3)
{
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i <4) ; i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}
if (i)
{
for(j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
while((i++ < 3))
ret += '=';
}
return ret;
}
std::vector<BYTE> base64_decode(std::string const& encoded_string)
{
int in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
BYTE char_array_4[4], char_array_3[3];
std::vector<BYTE> ret;
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
{
char_array_4[i++] = encoded_string[in_]; in_++;
if (i ==4)
{
for (i = 0; i <4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; (i < 3); i++)
ret.push_back(char_array_3[i]);
i = 0;
}
}
if (i)
{
for (j = i; j <4; j++)
char_array_4[j] = 0;
for (j = 0; j <4; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]);
}
return ret;
}
}
\ No newline at end of file
//from https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c
#ifndef _BASE64_H_
#define _BASE64_H_
#include <vector>
#include <string>
typedef unsigned char BYTE;
std::string base64_encode(BYTE const* buf, unsigned int bufLen);
std::vector<BYTE> base64_decode(std::string const&);
#endif //_BASE64_H_
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment