Merge remote-tracking branch 'origin/master' into boundarylayer_fixes

This commit is contained in:
Matthias Hochsteger 2024-12-12 17:46:37 +01:00
commit 8101aa14d9
86 changed files with 868 additions and 13550 deletions

View File

@ -687,6 +687,7 @@ namespace ngcore
size_t allocsize;
/// that's the data we have to delete, nullptr for not owning the memory
T * mem_to_delete;
MemoryTracer mt;
using FlatArray<T,IndexType>::size;
@ -708,6 +709,7 @@ namespace ngcore
{
allocsize = asize;
mem_to_delete = data;
mt.Alloc(sizeof(T)*asize);
}
@ -717,7 +719,10 @@ namespace ngcore
{
allocsize = asize;
if(ownMemory)
{
mem_to_delete = adata;
mt.Alloc(sizeof(T)*asize);
}
else
mem_to_delete = nullptr;
}
@ -733,8 +738,7 @@ namespace ngcore
NETGEN_INLINE Array (Array && a2)
{
mt.Swap(0., a2.mt, sizeof(T) * a2.allocsize);
mt = std::move(a2.mt);
size = a2.size;
data = a2.data;
allocsize = a2.allocsize;
@ -753,6 +757,7 @@ namespace ngcore
{
allocsize = size;
mem_to_delete = data;
mt.Alloc(sizeof(T)*size);
for (size_t i = 0; i < size; i++)
data[i] = a2.data[i];
}
@ -772,6 +777,7 @@ namespace ngcore
{
allocsize = size;
mem_to_delete = data;
mt.Alloc(sizeof(T)*size);
/*
for (size_t i = 0; i < size; i++)
data[i] = a2[i];
@ -788,6 +794,7 @@ namespace ngcore
{
allocsize = size;
mem_to_delete = data;
mt.Alloc(sizeof(T)*size);
size_t cnt = 0;
for (auto val : list)
data[cnt++] = val;
@ -800,6 +807,7 @@ namespace ngcore
{
allocsize = size;
mem_to_delete = data;
mt.Alloc(sizeof(T)*size);
for(size_t i = 0; i < a2.Size(); i++)
data[i] = a2[i];
for (size_t i = a2.Size(), j=0; i < size; i++,j++)
@ -834,6 +842,9 @@ namespace ngcore
NETGEN_INLINE void NothingToDelete ()
{
mem_to_delete = nullptr;
// this memory is not managed by the Array anymore, so set the memory usage to 0
mt.Free(sizeof(T)*allocsize);
}
/// Change logical size. If necessary, do reallocation. Keeps contents.
@ -959,7 +970,7 @@ namespace ngcore
NETGEN_INLINE void RemoveElement (size_t i)
{
NETGEN_CHECK_RANGE(i, BASE, BASE+size);
for(size_t j = i; j < this->size-1; j++)
for(size_t j = i; j+1 < this->size; j++)
this->data[j] = this->data[j+1];
this->size--;
}
@ -1011,8 +1022,7 @@ namespace ngcore
/// steal array
NETGEN_INLINE Array & operator= (Array && a2)
{
mt.Swap(sizeof(T)*allocsize, a2.mt, sizeof(T)*a2.allocsize);
mt = std::move(a2.mt);
ngcore::Swap (size, a2.size);
ngcore::Swap (data, a2.data);
ngcore::Swap (allocsize, a2.allocsize);
@ -1086,8 +1096,7 @@ namespace ngcore
NETGEN_INLINE void Swap (Array & b)
{
mt.Swap(sizeof(T) * allocsize, b.mt, sizeof(T) * b.allocsize);
mt = std::move(b.mt);
ngcore::Swap (size, b.size);
ngcore::Swap (data, b.data);
ngcore::Swap (allocsize, b.allocsize);
@ -1096,6 +1105,7 @@ namespace ngcore
NETGEN_INLINE void StartMemoryTracing () const
{
if(mem_to_delete)
mt.Alloc(sizeof(T) * allocsize);
}
@ -1105,7 +1115,6 @@ namespace ngcore
/// resize array, at least to size minsize. copy contents
NETGEN_INLINE void ReSize (size_t minsize);
MemoryTracer mt;
};
@ -1158,6 +1167,7 @@ namespace ngcore
using Array<T>::allocsize;
using Array<T>::data;
using Array<T>::mem_to_delete;
using Array<T>::mt;
// using Array<T>::ownmem;
public:
@ -1171,6 +1181,7 @@ namespace ngcore
data = new T[asize];
allocsize = size;
mem_to_delete = data;
mt.Alloc(sizeof(T)*asize);
}
}
@ -1191,6 +1202,7 @@ namespace ngcore
ArrayMem(ArrayMem && a2)
: Array<T> (a2.Size(), (T*)mem)
{
mt = std::move(a2.mt);
if (a2.mem_to_delete)
{
mem_to_delete = a2.mem_to_delete;
@ -1233,6 +1245,7 @@ namespace ngcore
ArrayMem & operator= (ArrayMem && a2)
{
mt = std::move(a2.mt);
ngcore::Swap (mem_to_delete, a2.mem_to_delete);
ngcore::Swap (allocsize, a2.allocsize);
ngcore::Swap (size, a2.size);

View File

@ -40,12 +40,13 @@ namespace ngcore
if (owns_data)
{
delete [] data;
mt.Free(Addr(size)+1);
mt.Free(GetMemoryUsage());
}
size = asize;
data = new unsigned char [Addr (size)+1];
mt.Alloc(Addr(size)+1);
owns_data = true;
mt.Alloc(GetMemoryUsage());
}
BitArray & BitArray :: Set () throw()

View File

@ -49,6 +49,7 @@ public:
{
ba2.owns_data = false;
ba2.data = nullptr;
mt = std::move(ba2.mt);
}
template <typename T>
@ -59,13 +60,17 @@ public:
int cnt = 0;
for (auto i = list.begin(); i < list.end(); i++, cnt++)
if (*i) SetBit(cnt);
StartMemoryTracing();
}
/// delete data
~BitArray ()
{
if (owns_data)
{
delete [] data;
mt.Free(GetMemoryUsage());
}
}
/// Set size, loose values
@ -150,11 +155,11 @@ public:
NGCORE_API auto * Data() const { return data; }
const size_t GetMemoryUsage() const { return owns_data ? (size+CHAR_BIT-1)/CHAR_BIT : 0; }
const MemoryTracer& GetMemoryTracer() const { return mt; }
void StartMemoryTracing() const
{
if(owns_data)
mt.Alloc(Addr(size)+1);
mt.Alloc(GetMemoryUsage());
}
private:

View File

@ -50,7 +50,7 @@ namespace ngcore
RangeException :: RangeException (// const std::string & where,
const char * where,
int ind, int imin, int imax) : Exception("")
ptrdiff_t ind, ptrdiff_t imin, ptrdiff_t imax) : Exception("")
{
std::stringstream str;
str << where << ": index " << ind << " out of range [" << imin << "," << imax << ")\n";
@ -59,7 +59,7 @@ namespace ngcore
}
void ThrowRangeException(const char * s, int ind, int imin, int imax)
void ThrowRangeException(const char * s, ptrdiff_t ind, ptrdiff_t imin, ptrdiff_t imax)
{
throw RangeException(s, ind, imin, imax);
}
@ -75,7 +75,7 @@ namespace ngcore
}
void ThrowNotTheSameException(const char * s, long int a, long int b)
void ThrowNotTheSameException(const char * s, ptrdiff_t a, ptrdiff_t b)
{
throw ngcore::Exception(std::string(s) + ", a="+ToString(a) + ", b="+ToString(b) + GetBackTrace());
}

View File

@ -1,11 +1,13 @@
#ifndef NETGEN_CORE_EXCEPTION_HPP
#define NETGEN_CORE_EXCEPTION_HPP
#include <cstddef>
#include <sstream> // for stringstream
#include <stdexcept> // for exception
#include <string> // for string
#include "ngcore_api.hpp" // for NGCORE_API
#include "utils.hpp" // for ToString
namespace ngcore
@ -65,7 +67,7 @@ namespace ngcore
/// where it occurs, index, minimal and maximal indices
RangeException (// const std::string & where,
const char * where,
int ind, int imin, int imax);
ptrdiff_t ind, ptrdiff_t imin, ptrdiff_t imax);
/*
: Exception("")
{
@ -84,13 +86,40 @@ namespace ngcore
}
};
[[noreturn]] NGCORE_API void ThrowRangeException(const char * s, int ind, int imin, int imax);
[[noreturn]] NGCORE_API void ThrowNotTheSameException(const char * s, long int a, long int b);
[[noreturn]] NGCORE_API void ThrowRangeException(const char * s, ptrdiff_t ind, ptrdiff_t imin, ptrdiff_t imax);
[[noreturn]] NGCORE_API void ThrowNotTheSameException(const char * s, ptrdiff_t a, ptrdiff_t b);
// Exception used if no simd implementation is available to fall back to standard evaluation
class NGCORE_API ExceptionNOSIMD : public Exception
{ public: using Exception::Exception; };
template <typename T>
struct IsSafe {
constexpr operator bool() const { return false; } };
namespace detail {
template <typename T, typename Tmin, typename Tmax>
inline static constexpr void CheckRange(const char * s, const T& n, Tmin first, Tmax next)
{
if constexpr (!IsSafe<decltype(n)>())
if (n<first || n>=next)
ThrowRangeException(s, ptrdiff_t(n), ptrdiff_t(first), ptrdiff_t(next));
}
template <typename Ta, typename Tb>
inline static constexpr void CheckSame(const char * s, const Ta& a, const Tb& b)
{
if constexpr (!IsSafe<decltype(a)>() || !IsSafe<decltype(b)>())
if(a != b)
{
if constexpr(std::is_integral_v<decltype(a)> && std::is_same_v<decltype(a),decltype(b)>)
ThrowNotTheSameException(s, long(a), long(b)); \
else
throw Exception(std::string(s) + "\t: not the same, a="+ToString(a) + ", b="+ngcore::ToString(b) + GetBackTrace());
}
}
} // namespace detail
} // namespace ngcore
#define NETGEN_CORE_NGEXEPTION_STR_HELPER(x) #x
@ -99,24 +128,10 @@ namespace ngcore
// Convenience macro to append file name and line of exception origin to the string
#define NG_EXCEPTION(s) ngcore::Exception(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t"+std::string(s))
template <typename T>
struct IsSafe {
constexpr operator bool() const { return false; } };
#if defined(NETGEN_ENABLE_CHECK_RANGE) && !defined(__CUDA_ARCH__)
#define NETGEN_CHECK_RANGE(value, min, max_plus_one) \
{ if constexpr (!IsSafe<decltype(value)>()) { \
if ((value)<(min) || (value)>=(max_plus_one)) \
ThrowRangeException(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t", int(value), int(min), int(max_plus_one)); } }
#define NETGEN_CHECK_RANGE(value, min, max_plus_one) ngcore::detail::CheckRange(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t", value, min, max_plus_one);
#define NETGEN_CHECK_SAME(a,b) ngcore::detail::CheckSame(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t", a, b);
#define NETGEN_CHECK_SAME(a,b) \
{ if(a != b) { \
if constexpr(std::is_same<decltype(a),size_t>() && std::is_same<decltype(b),size_t>()) \
ThrowNotTheSameException(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t: not the same, a=", long(a), long(b)); \
else \
throw ngcore::Exception(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t: not the same, a="+ToString(a) + ", b="+ToString(b) + GetBackTrace()); \
} }
#define NETGEN_NOEXCEPT
#else // defined(NETGEN_ENABLE_CHECK_RANGE) && !defined(__CUDA_ARCH__)
#define NETGEN_CHECK_RANGE(value, min, max)

View File

@ -5,6 +5,7 @@ functions = [
("int", "MPI_Alltoall", "void*", "int", "MPI_Datatype", "void*", "int", "MPI_Datatype", "MPI_Comm"),
("int", "MPI_Barrier", "MPI_Comm"),
("int", "MPI_Bcast", "void*", "int", "MPI_Datatype", "int", "MPI_Comm"),
("int", "MPI_Ibcast", "void*", "int", "MPI_Datatype", "int", "MPI_Comm", "MPI_Request*"),
("int", "MPI_Comm_c2f", "MPI_Comm"),
("int", "MPI_Comm_create", "MPI_Comm", "MPI_Group", "MPI_Comm*"),
("int", "MPI_Comm_create_group", "MPI_Comm", "MPI_Group", "int", "MPI_Comm*"),
@ -105,13 +106,13 @@ def generate_declarations():
name = f[1]
args = ", ".join(get_args(f))
code += f"NGCORE_API extern {ret} (*NG_{name})({args});\n"
nowrapper_code += f"static const auto NG_{name} = {name};\n"
nowrapper_code += f"#define NG_{name} {name}\n"
for typ, name in constants:
if typ.startswith("MPI_"):
typ = "NG_" + typ
code += f"NGCORE_API extern {typ} NG_{name};\n"
nowrapper_code += f"static const decltype({name}) NG_{name} = {name};\n"
nowrapper_code += f"#define NG_{name} {name}\n"
with open("ng_mpi_generated_declarations.hpp", "w") as f:
f.write("#ifdef NG_MPI_WRAPPER\n")

View File

@ -35,11 +35,16 @@ namespace ngcore
class MemoryTracer
{
#if defined(NETGEN_TRACE_MEMORY) && !defined(__CUDA_ARCH__)
#if defined(NETGEN_TRACE_MEMORY) && !defined(__CUDA_ARCH__)
NGCORE_API static std::vector<std::string> names;
NGCORE_API static std::vector<int> parents;
static int CreateId(const std::string& name)
#if defined(NETGEN_CHECK_RANGE)
NGCORE_API static std::atomic<size_t> total_memory;
mutable size_t allocated_memory = 0;
#endif // NETGEN_CHECK_RANGE
static int CreateId(const std::string& name = "")
{
int id = names.size();
names.push_back(name);
@ -48,7 +53,7 @@ namespace ngcore
std::cerr << "Allocated " << id << " MemoryTracer objects" << std::endl;
return id;
}
int id;
mutable int id = 0;
public:
@ -57,8 +62,33 @@ namespace ngcore
id = CreateId(name);
}
// not tracing
MemoryTracer() : id(0) {}
MemoryTracer() { }
MemoryTracer(const MemoryTracer & tracer)
{
(*this) = tracer;
}
MemoryTracer(MemoryTracer && tracer)
{
(*this) = std::move(tracer);
}
MemoryTracer & operator=(const MemoryTracer & tracer) {
if(tracer.id)
id = CreateId(names[tracer.id]);
return *this;
}
MemoryTracer & operator=(MemoryTracer && tracer) {
ngcore::Swap(id, tracer.id);
#if defined(NETGEN_CHECK_RANGE)
ngcore::Swap(allocated_memory, tracer.allocated_memory);
#endif // NETGEN_CHECK_RANGE
return *this;
}
template <typename... TRest>
MemoryTracer( std::string name, TRest & ... rest )
@ -67,37 +97,47 @@ namespace ngcore
Track(rest...);
}
#if defined(NETGEN_CHECK_RANGE)
// check if all memory was freed when object is destroyed
~MemoryTracer()
{
NETGEN_CHECK_SAME(allocated_memory, 0);
}
#endif // NETGEN_CHECK_RANGE
NETGEN_INLINE void Alloc(size_t size) const
{
#if defined(NETGEN_CHECK_RANGE)
// Trace also nameless Memtracer objects if range checks are active
if(!id && size)
id = CreateId();
#endif // NETGEN_CHECK_RANGE
if(id && trace)
trace->AllocMemory(id, size);
#if defined(NETGEN_CHECK_RANGE)
if(id)
{
allocated_memory += size;
total_memory += size;
}
#endif // NETGEN_CHECK_RANGE
}
void Free(size_t size) const
{
if(id && trace)
trace->FreeMemory(id, size);
}
void Swap(size_t mysize, MemoryTracer& other, size_t other_size) const
#if defined(NETGEN_CHECK_RANGE)
if(id)
{
if(!trace || (id == 0 && other.id == 0))
return;
if(id == 0)
return trace->ChangeMemory(other.id, mysize - other_size);
if(other.id == 0)
return trace->ChangeMemory(id, other_size - mysize);
// first decrease memory, otherwise have artificial/wrong high peak memory usage
if(mysize<other_size)
{
trace->ChangeMemory(other.id, mysize-other_size);
trace->ChangeMemory(id, other_size-mysize);
}
else
{
trace->ChangeMemory(id, other_size-mysize);
trace->ChangeMemory(other.id, mysize-other_size);
// check if we have at least size bytes of memory currently allocated (such that allocated_memory doesn't get negative)
NETGEN_CHECK_RANGE(allocated_memory, static_cast<ptrdiff_t>(size), std::numeric_limits<ptrdiff_t>::max());
allocated_memory -= size;
total_memory -= size;
#endif // NETGEN_CHECK_RANGE
}
}
@ -148,6 +188,14 @@ namespace ngcore
static const std::vector<std::string> & GetNames() { return names; }
static const std::vector<int> & GetParents() { return parents; }
static size_t GetTotalMemory()
{
#if defined(NETGEN_CHECK_RANGE)
return total_memory;
#else
return 0;
#endif // NETGEN_CHECK_RANGE
}
#else // defined(NETGEN_TRACE_MEMORY) && !defined(__CUDA_ARCH__)
public:
MemoryTracer() {}
@ -157,7 +205,6 @@ namespace ngcore
void Alloc(size_t /* size */) const {}
void Free(size_t /* size */) const {}
void Swap(...) const {}
int GetId() const { return 0; }
template <typename... TRest>
@ -166,6 +213,7 @@ namespace ngcore
static std::string GetName(int /* id */) { return ""; }
std::string GetName() const { return ""; }
void SetName(std::string /* name */) const {}
static size_t GetTotalMemory() { return 0; }
#endif // NETGEN_TRACE_MEMORY
};
} // namespace ngcore

View File

@ -72,7 +72,60 @@ namespace ngcore
return GetMPIType<T>();
}
class NgMPI_Request
{
NG_MPI_Request request;
public:
NgMPI_Request (NG_MPI_Request requ) : request{requ} { }
NgMPI_Request (const NgMPI_Request&) = delete;
NgMPI_Request (NgMPI_Request&&) = default;
~NgMPI_Request () { NG_MPI_Wait (&request, NG_MPI_STATUS_IGNORE); }
void Wait() { NG_MPI_Wait (&request, NG_MPI_STATUS_IGNORE); }
operator NG_MPI_Request() &&
{
auto tmp = request;
request = NG_MPI_REQUEST_NULL;
return tmp;
}
};
class NgMPI_Requests
{
Array<NG_MPI_Request> requests;
public:
NgMPI_Requests() = default;
~NgMPI_Requests() { WaitAll(); }
void Reset() { requests.SetSize0(); }
NgMPI_Requests & operator+= (NgMPI_Request && r)
{
requests += NG_MPI_Request(std::move(r));
return *this;
}
NgMPI_Requests & operator+= (NG_MPI_Request r)
{
requests += r;
return *this;
}
void WaitAll()
{
static Timer t("NgMPI - WaitAll"); RegionTimer reg(t);
if (!requests.Size()) return;
NG_MPI_Waitall (requests.Size(), requests.Data(), NG_MPI_STATUSES_IGNORE);
}
int WaitAny ()
{
int nr;
NG_MPI_Waitany (requests.Size(), requests.Data(), &nr, NG_MPI_STATUS_IGNORE);
return nr;
}
};
[[deprecated("use requests.WaitAll instread")]]
inline void MyMPI_WaitAll (FlatArray<NG_MPI_Request> requests)
{
static Timer t("MPI - WaitAll"); RegionTimer reg(t);
@ -80,6 +133,7 @@ namespace ngcore
NG_MPI_Waitall (requests.Size(), requests.Data(), NG_MPI_STATUSES_IGNORE);
}
[[deprecated("use requests.WaitAny instread")]]
inline int MyMPI_WaitAny (FlatArray<NG_MPI_Request> requests)
{
int nr;
@ -235,7 +289,7 @@ namespace ngcore
/** --- non-blocking P2P --- **/
template<typename T, typename T2 = decltype(GetMPIType<T>())>
NG_MPI_Request ISend (T & val, int dest, int tag) const
[[nodiscard]] NG_MPI_Request ISend (T & val, int dest, int tag) const
{
NG_MPI_Request request;
NG_MPI_Isend (&val, 1, GetMPIType<T>(), dest, tag, comm, &request);
@ -243,7 +297,7 @@ namespace ngcore
}
template<typename T, typename T2 = decltype(GetMPIType<T>())>
NG_MPI_Request ISend (FlatArray<T> s, int dest, int tag) const
[[nodiscard]] NG_MPI_Request ISend (FlatArray<T> s, int dest, int tag) const
{
NG_MPI_Request request;
NG_MPI_Isend (s.Data(), s.Size(), GetMPIType<T>(), dest, tag, comm, &request);
@ -251,7 +305,7 @@ namespace ngcore
}
template<typename T, typename T2 = decltype(GetMPIType<T>())>
NG_MPI_Request IRecv (T & val, int dest, int tag) const
[[nodiscard]] NG_MPI_Request IRecv (T & val, int dest, int tag) const
{
NG_MPI_Request request;
NG_MPI_Irecv (&val, 1, GetMPIType<T>(), dest, tag, comm, &request);
@ -259,7 +313,7 @@ namespace ngcore
}
template<typename T, typename T2 = decltype(GetMPIType<T>())>
NG_MPI_Request IRecv (FlatArray<T> s, int src, int tag) const
[[nodiscard]] NG_MPI_Request IRecv (FlatArray<T> s, int src, int tag) const
{
NG_MPI_Request request;
NG_MPI_Irecv (s.Data(), s.Size(), GetMPIType<T>(), src, tag, comm, &request);
@ -308,8 +362,17 @@ namespace ngcore
}
template <class T, size_t S>
void Bcast (std::array<T,S> & d, int root = 0) const
{
if (size == 1) return;
if (S != 0)
NG_MPI_Bcast (&d[0], S, GetMPIType<T>(), root, comm);
}
template <class T>
void Bcast (Array<T> & d, int root = 0)
void Bcast (Array<T> & d, int root = 0) const
{
if (size == 1) return;
@ -330,6 +393,26 @@ namespace ngcore
NG_MPI_Bcast (&s[0], len, NG_MPI_CHAR, root, comm);
}
template <class T, size_t S>
[[nodiscard]] NgMPI_Request IBcast (std::array<T,S> & d, int root = 0) const
{
NG_MPI_Request request;
NG_MPI_Ibcast (&d[0], S, GetMPIType<T>(), root, comm, &request);
return request;
}
template <class T>
[[nodiscard]] NgMPI_Request IBcast (FlatArray<T> d, int root = 0) const
{
NG_MPI_Request request;
int ds = d.Size();
NG_MPI_Ibcast (d.Data(), ds, GetMPIType<T>(), root, comm, &request);
return request;
}
template <typename T>
void AllToAll (FlatArray<T> send, FlatArray<T> recv) const
{
@ -401,16 +484,16 @@ namespace ngcore
recv_data = DynamicTable<T> (recv_sizes, true);
Array<NG_MPI_Request> requests;
NgMPI_Requests requests;
for (int dest = 0; dest < size; dest++)
if (dest != rank && send_data[dest].Size())
requests.Append (ISend (FlatArray<T>(send_data[dest]), dest, tag));
requests += ISend (FlatArray<T>(send_data[dest]), dest, tag);
for (int dest = 0; dest < size; dest++)
if (dest != rank && recv_data[dest].Size())
requests.Append (IRecv (FlatArray<T>(recv_data[dest]), dest, tag));
requests += IRecv (FlatArray<T>(recv_data[dest]), dest, tag);
MyMPI_WaitAll (requests);
requests.WaitAll();
}
@ -454,6 +537,22 @@ namespace ngcore
template <class T, class T2=void>
inline NG_MPI_Datatype GetMPIType () { return -1; }
class NgMPI_Request {
public:
NgMPI_Request() = default;
NgMPI_Request(NgMPI_Request &&) { ; }
NgMPI_Request(NG_MPI_Request &&) { ; }
};
class NgMPI_Requests
{
public:
NgMPI_Requests & operator+= (NgMPI_Request &&) { return *this; }
NgMPI_Requests & operator+= (NG_MPI_Request r) { return *this; }
void Reset() { ; }
void WaitAll() { ; }
int WaitAny() { return 0; }
};
class NgMPI_Comm
{
@ -506,8 +605,17 @@ namespace ngcore
template <typename T>
void Bcast (T & s, int root = 0) const { ; }
template <class T, size_t S>
void Bcast (std::array<T,S> & d, int root = 0) const {}
template <class T>
void Bcast (Array<T> & d, int root = 0) { ; }
void Bcast (Array<T> & d, int root = 0) const { ; }
template <class T, size_t S>
NG_MPI_Request IBcast (std::array<T,S> & d, int root = 0) const { return 0; }
template <class T>
NG_MPI_Request IBcast (FlatArray<T> d, int root = 0) const { return 0; }
template <typename T>
void AllGather (T val, FlatArray<T> recv) const

View File

@ -5,6 +5,7 @@ NGCORE_API extern int (*NG_MPI_Allreduce)(void*, void*, int, NG_MPI_Datatype, NG
NGCORE_API extern int (*NG_MPI_Alltoall)(void*, int, NG_MPI_Datatype, void*, int, NG_MPI_Datatype, NG_MPI_Comm);
NGCORE_API extern int (*NG_MPI_Barrier)(NG_MPI_Comm);
NGCORE_API extern int (*NG_MPI_Bcast)(void*, int, NG_MPI_Datatype, int, NG_MPI_Comm);
NGCORE_API extern int (*NG_MPI_Ibcast)(void*, int, NG_MPI_Datatype, int, NG_MPI_Comm, NG_MPI_Request*);
NGCORE_API extern int (*NG_MPI_Comm_c2f)(NG_MPI_Comm);
NGCORE_API extern int (*NG_MPI_Comm_create)(NG_MPI_Comm, NG_MPI_Group, NG_MPI_Comm*);
NGCORE_API extern int (*NG_MPI_Comm_create_group)(NG_MPI_Comm, NG_MPI_Group, int, NG_MPI_Comm*);
@ -75,79 +76,80 @@ NGCORE_API extern int NG_MPI_THREAD_SINGLE;
NGCORE_API extern int NG_MPI_VERSION;
NGCORE_API extern void* NG_MPI_IN_PLACE;
#else // NG_MPI_WRAPPER
static const auto NG_MPI_Wtime = MPI_Wtime;
static const auto NG_MPI_Allgather = MPI_Allgather;
static const auto NG_MPI_Allreduce = MPI_Allreduce;
static const auto NG_MPI_Alltoall = MPI_Alltoall;
static const auto NG_MPI_Barrier = MPI_Barrier;
static const auto NG_MPI_Bcast = MPI_Bcast;
static const auto NG_MPI_Comm_c2f = MPI_Comm_c2f;
static const auto NG_MPI_Comm_create = MPI_Comm_create;
static const auto NG_MPI_Comm_create_group = MPI_Comm_create_group;
static const auto NG_MPI_Comm_free = MPI_Comm_free;
static const auto NG_MPI_Comm_group = MPI_Comm_group;
static const auto NG_MPI_Comm_rank = MPI_Comm_rank;
static const auto NG_MPI_Comm_size = MPI_Comm_size;
static const auto NG_MPI_Finalize = MPI_Finalize;
static const auto NG_MPI_Gather = MPI_Gather;
static const auto NG_MPI_Gatherv = MPI_Gatherv;
static const auto NG_MPI_Get_count = MPI_Get_count;
static const auto NG_MPI_Get_processor_name = MPI_Get_processor_name;
static const auto NG_MPI_Group_incl = MPI_Group_incl;
static const auto NG_MPI_Init = MPI_Init;
static const auto NG_MPI_Init_thread = MPI_Init_thread;
static const auto NG_MPI_Initialized = MPI_Initialized;
static const auto NG_MPI_Iprobe = MPI_Iprobe;
static const auto NG_MPI_Irecv = MPI_Irecv;
static const auto NG_MPI_Isend = MPI_Isend;
static const auto NG_MPI_Probe = MPI_Probe;
static const auto NG_MPI_Query_thread = MPI_Query_thread;
static const auto NG_MPI_Recv = MPI_Recv;
static const auto NG_MPI_Recv_init = MPI_Recv_init;
static const auto NG_MPI_Reduce = MPI_Reduce;
static const auto NG_MPI_Reduce_local = MPI_Reduce_local;
static const auto NG_MPI_Request_free = MPI_Request_free;
static const auto NG_MPI_Scatter = MPI_Scatter;
static const auto NG_MPI_Send = MPI_Send;
static const auto NG_MPI_Send_init = MPI_Send_init;
static const auto NG_MPI_Startall = MPI_Startall;
static const auto NG_MPI_Type_commit = MPI_Type_commit;
static const auto NG_MPI_Type_contiguous = MPI_Type_contiguous;
static const auto NG_MPI_Type_create_resized = MPI_Type_create_resized;
static const auto NG_MPI_Type_create_struct = MPI_Type_create_struct;
static const auto NG_MPI_Type_free = MPI_Type_free;
static const auto NG_MPI_Type_get_extent = MPI_Type_get_extent;
static const auto NG_MPI_Type_indexed = MPI_Type_indexed;
static const auto NG_MPI_Type_size = MPI_Type_size;
static const auto NG_MPI_Wait = MPI_Wait;
static const auto NG_MPI_Waitall = MPI_Waitall;
static const auto NG_MPI_Waitany = MPI_Waitany;
static const decltype(MPI_COMM_NULL) NG_MPI_COMM_NULL = MPI_COMM_NULL;
static const decltype(MPI_COMM_WORLD) NG_MPI_COMM_WORLD = MPI_COMM_WORLD;
static const decltype(MPI_CHAR) NG_MPI_CHAR = MPI_CHAR;
static const decltype(MPI_CXX_DOUBLE_COMPLEX) NG_MPI_CXX_DOUBLE_COMPLEX = MPI_CXX_DOUBLE_COMPLEX;
static const decltype(MPI_C_BOOL) NG_MPI_C_BOOL = MPI_C_BOOL;
static const decltype(MPI_DATATYPE_NULL) NG_MPI_DATATYPE_NULL = MPI_DATATYPE_NULL;
static const decltype(MPI_DOUBLE) NG_MPI_DOUBLE = MPI_DOUBLE;
static const decltype(MPI_FLOAT) NG_MPI_FLOAT = MPI_FLOAT;
static const decltype(MPI_INT) NG_MPI_INT = MPI_INT;
static const decltype(MPI_SHORT) NG_MPI_SHORT = MPI_SHORT;
static const decltype(MPI_UINT64_T) NG_MPI_UINT64_T = MPI_UINT64_T;
static const decltype(MPI_LOR) NG_MPI_LOR = MPI_LOR;
static const decltype(MPI_MAX) NG_MPI_MAX = MPI_MAX;
static const decltype(MPI_MIN) NG_MPI_MIN = MPI_MIN;
static const decltype(MPI_SUM) NG_MPI_SUM = MPI_SUM;
static const decltype(MPI_REQUEST_NULL) NG_MPI_REQUEST_NULL = MPI_REQUEST_NULL;
static const decltype(MPI_STATUSES_IGNORE) NG_MPI_STATUSES_IGNORE = MPI_STATUSES_IGNORE;
static const decltype(MPI_STATUS_IGNORE) NG_MPI_STATUS_IGNORE = MPI_STATUS_IGNORE;
static const decltype(MPI_ANY_SOURCE) NG_MPI_ANY_SOURCE = MPI_ANY_SOURCE;
static const decltype(MPI_ANY_TAG) NG_MPI_ANY_TAG = MPI_ANY_TAG;
static const decltype(MPI_MAX_PROCESSOR_NAME) NG_MPI_MAX_PROCESSOR_NAME = MPI_MAX_PROCESSOR_NAME;
static const decltype(MPI_PROC_NULL) NG_MPI_PROC_NULL = MPI_PROC_NULL;
static const decltype(MPI_ROOT) NG_MPI_ROOT = MPI_ROOT;
static const decltype(MPI_SUBVERSION) NG_MPI_SUBVERSION = MPI_SUBVERSION;
static const decltype(MPI_THREAD_MULTIPLE) NG_MPI_THREAD_MULTIPLE = MPI_THREAD_MULTIPLE;
static const decltype(MPI_THREAD_SINGLE) NG_MPI_THREAD_SINGLE = MPI_THREAD_SINGLE;
static const decltype(MPI_VERSION) NG_MPI_VERSION = MPI_VERSION;
static const decltype(MPI_IN_PLACE) NG_MPI_IN_PLACE = MPI_IN_PLACE;
#define NG_MPI_Wtime MPI_Wtime
#define NG_MPI_Allgather MPI_Allgather
#define NG_MPI_Allreduce MPI_Allreduce
#define NG_MPI_Alltoall MPI_Alltoall
#define NG_MPI_Barrier MPI_Barrier
#define NG_MPI_Bcast MPI_Bcast
#define NG_MPI_Ibcast MPI_Ibcast
#define NG_MPI_Comm_c2f MPI_Comm_c2f
#define NG_MPI_Comm_create MPI_Comm_create
#define NG_MPI_Comm_create_group MPI_Comm_create_group
#define NG_MPI_Comm_free MPI_Comm_free
#define NG_MPI_Comm_group MPI_Comm_group
#define NG_MPI_Comm_rank MPI_Comm_rank
#define NG_MPI_Comm_size MPI_Comm_size
#define NG_MPI_Finalize MPI_Finalize
#define NG_MPI_Gather MPI_Gather
#define NG_MPI_Gatherv MPI_Gatherv
#define NG_MPI_Get_count MPI_Get_count
#define NG_MPI_Get_processor_name MPI_Get_processor_name
#define NG_MPI_Group_incl MPI_Group_incl
#define NG_MPI_Init MPI_Init
#define NG_MPI_Init_thread MPI_Init_thread
#define NG_MPI_Initialized MPI_Initialized
#define NG_MPI_Iprobe MPI_Iprobe
#define NG_MPI_Irecv MPI_Irecv
#define NG_MPI_Isend MPI_Isend
#define NG_MPI_Probe MPI_Probe
#define NG_MPI_Query_thread MPI_Query_thread
#define NG_MPI_Recv MPI_Recv
#define NG_MPI_Recv_init MPI_Recv_init
#define NG_MPI_Reduce MPI_Reduce
#define NG_MPI_Reduce_local MPI_Reduce_local
#define NG_MPI_Request_free MPI_Request_free
#define NG_MPI_Scatter MPI_Scatter
#define NG_MPI_Send MPI_Send
#define NG_MPI_Send_init MPI_Send_init
#define NG_MPI_Startall MPI_Startall
#define NG_MPI_Type_commit MPI_Type_commit
#define NG_MPI_Type_contiguous MPI_Type_contiguous
#define NG_MPI_Type_create_resized MPI_Type_create_resized
#define NG_MPI_Type_create_struct MPI_Type_create_struct
#define NG_MPI_Type_free MPI_Type_free
#define NG_MPI_Type_get_extent MPI_Type_get_extent
#define NG_MPI_Type_indexed MPI_Type_indexed
#define NG_MPI_Type_size MPI_Type_size
#define NG_MPI_Wait MPI_Wait
#define NG_MPI_Waitall MPI_Waitall
#define NG_MPI_Waitany MPI_Waitany
#define NG_MPI_COMM_NULL MPI_COMM_NULL
#define NG_MPI_COMM_WORLD MPI_COMM_WORLD
#define NG_MPI_CHAR MPI_CHAR
#define NG_MPI_CXX_DOUBLE_COMPLEX MPI_CXX_DOUBLE_COMPLEX
#define NG_MPI_C_BOOL MPI_C_BOOL
#define NG_MPI_DATATYPE_NULL MPI_DATATYPE_NULL
#define NG_MPI_DOUBLE MPI_DOUBLE
#define NG_MPI_FLOAT MPI_FLOAT
#define NG_MPI_INT MPI_INT
#define NG_MPI_SHORT MPI_SHORT
#define NG_MPI_UINT64_T MPI_UINT64_T
#define NG_MPI_LOR MPI_LOR
#define NG_MPI_MAX MPI_MAX
#define NG_MPI_MIN MPI_MIN
#define NG_MPI_SUM MPI_SUM
#define NG_MPI_REQUEST_NULL MPI_REQUEST_NULL
#define NG_MPI_STATUSES_IGNORE MPI_STATUSES_IGNORE
#define NG_MPI_STATUS_IGNORE MPI_STATUS_IGNORE
#define NG_MPI_ANY_SOURCE MPI_ANY_SOURCE
#define NG_MPI_ANY_TAG MPI_ANY_TAG
#define NG_MPI_MAX_PROCESSOR_NAME MPI_MAX_PROCESSOR_NAME
#define NG_MPI_PROC_NULL MPI_PROC_NULL
#define NG_MPI_ROOT MPI_ROOT
#define NG_MPI_SUBVERSION MPI_SUBVERSION
#define NG_MPI_THREAD_MULTIPLE MPI_THREAD_MULTIPLE
#define NG_MPI_THREAD_SINGLE MPI_THREAD_SINGLE
#define NG_MPI_VERSION MPI_VERSION
#define NG_MPI_IN_PLACE MPI_IN_PLACE
#endif // NG_MPI_WRAPPER

View File

@ -4,6 +4,7 @@ decltype(NG_MPI_Allreduce) NG_MPI_Allreduce = [](void*, void*, int, NG_MPI_Datat
decltype(NG_MPI_Alltoall) NG_MPI_Alltoall = [](void*, int, NG_MPI_Datatype, void*, int, NG_MPI_Datatype, NG_MPI_Comm)->int { throw no_mpi(); };
decltype(NG_MPI_Barrier) NG_MPI_Barrier = [](NG_MPI_Comm)->int { throw no_mpi(); };
decltype(NG_MPI_Bcast) NG_MPI_Bcast = [](void*, int, NG_MPI_Datatype, int, NG_MPI_Comm)->int { throw no_mpi(); };
decltype(NG_MPI_Ibcast) NG_MPI_Ibcast = [](void*, int, NG_MPI_Datatype, int, NG_MPI_Comm, NG_MPI_Request*)->int { throw no_mpi(); };
decltype(NG_MPI_Comm_c2f) NG_MPI_Comm_c2f = [](NG_MPI_Comm)->int { throw no_mpi(); };
decltype(NG_MPI_Comm_create) NG_MPI_Comm_create = [](NG_MPI_Comm, NG_MPI_Group, NG_MPI_Comm*)->int { throw no_mpi(); };
decltype(NG_MPI_Comm_create_group) NG_MPI_Comm_create_group = [](NG_MPI_Comm, NG_MPI_Group, int, NG_MPI_Comm*)->int { throw no_mpi(); };

View File

@ -4,6 +4,7 @@ NG_MPI_Allreduce = [](void* arg0, void* arg1, int arg2, NG_MPI_Datatype arg3, NG
NG_MPI_Alltoall = [](void* arg0, int arg1, NG_MPI_Datatype arg2, void* arg3, int arg4, NG_MPI_Datatype arg5, NG_MPI_Comm arg6)->int { return MPI_Alltoall( arg0, arg1, ng2mpi(arg2), arg3, arg4, ng2mpi(arg5), ng2mpi(arg6)); };
NG_MPI_Barrier = [](NG_MPI_Comm arg0)->int { return MPI_Barrier( ng2mpi(arg0)); };
NG_MPI_Bcast = [](void* arg0, int arg1, NG_MPI_Datatype arg2, int arg3, NG_MPI_Comm arg4)->int { return MPI_Bcast( arg0, arg1, ng2mpi(arg2), arg3, ng2mpi(arg4)); };
NG_MPI_Ibcast = [](void* arg0, int arg1, NG_MPI_Datatype arg2, int arg3, NG_MPI_Comm arg4, NG_MPI_Request* arg5)->int { return MPI_Ibcast( arg0, arg1, ng2mpi(arg2), arg3, ng2mpi(arg4), ng2mpi(arg5)); };
NG_MPI_Comm_c2f = [](NG_MPI_Comm arg0)->int { return MPI_Comm_c2f( ng2mpi(arg0)); };
NG_MPI_Comm_create = [](NG_MPI_Comm arg0, NG_MPI_Group arg1, NG_MPI_Comm* arg2)->int { return MPI_Comm_create( ng2mpi(arg0), ng2mpi(arg1), ng2mpi(arg2)); };
NG_MPI_Comm_create_group = [](NG_MPI_Comm arg0, NG_MPI_Group arg1, int arg2, NG_MPI_Comm* arg3)->int { return MPI_Comm_create_group( ng2mpi(arg0), ng2mpi(arg1), arg2, ng2mpi(arg3)); };

View File

@ -22,5 +22,6 @@
#include "xbool.hpp"
#include "ngstream.hpp"
#include "utils.hpp"
#include "ranges.hpp"
#endif // NETGEN_CORE_NGCORE_HPP

View File

@ -116,6 +116,7 @@ namespace ngcore
#ifdef NETGEN_TRACE_MEMORY
std::vector<std::string> MemoryTracer::names{"all"};
std::vector<int> MemoryTracer::parents{-1};
std::atomic<size_t> MemoryTracer::total_memory{0};
#endif // NETGEN_TRACE_MEMORY
} // namespace ngcore

View File

@ -324,6 +324,8 @@ threads : int
#endif // NETGEN_TRACE_MEMORY
;
m.def("GetTotalMemory", MemoryTracer::GetTotalMemory);
py::class_<Timer<>> (m, "Timer")
.def(py::init<const string&>())
.def("Start", static_cast<void (Timer<>::*)()const>(&Timer<>::Start), "start timer")

View File

@ -130,6 +130,7 @@ namespace ngcore
{
for (size_t i : IntRange(size+1))
index[i] = i*entrysize;
mt.Alloc(GetMemUsage());
}
/// Construct table of variable entrysize
@ -141,6 +142,7 @@ namespace ngcore
index = TablePrefixSum (FlatArray<TI> (entrysize.Size(), entrysize.Data()));
size_t cnt = index[size];
data = new T[cnt];
mt.Alloc(GetMemUsage());
}
explicit NETGEN_INLINE Table (const FlatTable<T,IndexType> & tab2)
@ -157,6 +159,7 @@ namespace ngcore
size_t cnt = index[size];
data = new T[cnt];
this->AsArray() = tab2.AsArray();
mt.Alloc(GetMemUsage());
/*
for (size_t i = 0; i < cnt; i++)
data[i] = tab2.data[i];
@ -177,12 +180,14 @@ namespace ngcore
data = new T[cnt];
for (size_t i = 0; i < cnt; i++)
data[i] = tab2.data[i];
mt.Alloc(GetMemUsage());
}
NETGEN_INLINE Table (Table && tab2)
: FlatTable<T,IndexType>(0, nullptr, nullptr)
{
tab2.mt.Free(tab2.GetMemUsage());
mt = std::move(tab2.mt);
Swap (size, tab2.size);
Swap (index, tab2.index);
Swap (data, tab2.data);
@ -210,7 +215,7 @@ namespace ngcore
NETGEN_INLINE Table & operator= (Table && tab2)
{
mt.Swap(GetMemUsage(), tab2.mt, tab2.GetMemUsage());
mt = std::move(tab2.mt);
Swap (size, tab2.size);
Swap (index, tab2.index);
Swap (data, tab2.data);

View File

@ -1211,7 +1211,7 @@ namespace netgen
PrintMessage (2, "Object ", i, " has ", tams->GetNT(), " triangles");
}
}
catch (exception)
catch (const std::exception &)
{
cerr << "*************************************************************" << endl
<< "**** out of memory problem in CSG visualization ****" << endl

View File

@ -223,6 +223,16 @@ MyStr::MyStr(const string & st)
strcpy (str, st.c_str());
}
MyStr::MyStr(string_view sv)
{
length = unsigned(sv.length());
if (length > SHORTLEN)
str = new char[length + 1];
else
str = shortstr;
strcpy (str, sv.data());
}
MyStr::MyStr(const filesystem::path & path)
: MyStr(path.string())
{ }

View File

@ -60,6 +60,7 @@ public:
MyStr(const Point3d& p);
MyStr(const Vec3d& p);
MyStr(const string & st);
MyStr(string_view sv);
MyStr(const filesystem::path & st);
~MyStr();

View File

@ -109,6 +109,7 @@ namespace netgen
{
void * p = new char [(line.maxsize+5) * elsize];
if (line.maxsize && elsize)
memcpy (p, line.col, line.maxsize * elsize);
delete [] (char*)line.col;

View File

@ -128,7 +128,7 @@ Point2d CrossPoint (const Line2d & l1, const Line2d & l2)
int CrossPointBarycentric (const Line2d & l1, const Line2d & l2,
double & lam1, double & lam2)
double & lam1, double & lam2, double eps)
{
// p = l1.1 + lam1 (l1.2-l1.1) = l2.1 + lam2 (l2.2-l2.1)
double a11 = l1.p2.X() - l1.p1.X();
@ -140,8 +140,11 @@ int CrossPointBarycentric (const Line2d & l1, const Line2d & l2,
double b2 = l2.p1.Y() - l1.p1.Y();
double det = a11*a22 - a12 * a21;
/*
if (det == 0)
return 1;
*/
if (fabs (det) < eps * (fabs(a11*a22)+fabs(a12*a21))) return 1;
lam1 = (a22 * b1 - a12 * b2) / det;
lam2 = (a11 * b2 - a21 * b1) / det;

View File

@ -365,7 +365,7 @@ namespace netgen
friend DLL_HEADER Point2d CrossPoint (const Line2d & l1, const Line2d & l2);
/// returns 1 iff parallel
friend int CrossPointBarycentric (const Line2d & l1, const Line2d & l2,
double & lam1, double & lam2);
double & lam1, double & lam2, double eps);
///
friend int Parallel (const Line2d & l1, const Line2d & l2, double peps);

View File

@ -2246,11 +2246,8 @@ int Ng_GetClosureNodes (int nt, int nodenr, int nodeset, int * nodes)
if (nodeset & 2) // Edges
{
int edges[12];
// int ned;
// ned = mesh->GetTopology().GetElementEdges (nodenr+1, edges, 0);
int ned = mesh->GetTopology().GetEdges (ElementIndex(nodenr)).Size();
for (int i = 0; i < ned; i++)
auto edges = mesh->GetTopology().GetEdges (ElementIndex(nodenr));
for (int i = 0; i < edges.Size(); i++)
{
nodes[cnt++] = 1;
nodes[cnt++] = edges[i]-1;

View File

@ -1041,7 +1041,7 @@ namespace netgen
build_searchtree);
return ind - 1;
}
catch(NgException e) // quads not implemented curved yet
catch(const NgException & e) // quads not implemented curved yet
{
for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
{

View File

@ -301,7 +301,7 @@ namespace netgen
in >> name;
cout << IM(3) << len << " element are in group " << name << endl;
int hi, index;
int fdnr, ednr;
int fdnr=-1, ednr=-1;
in >> hi >> index >> hi >> hi;
int codim = get<1>(element_map[index]);
@ -712,7 +712,7 @@ namespace netgen
if(!UserFormatRegister::HaveFormat(format))
throw Exception("Unknown format: " + format);
const auto & entry = UserFormatRegister::Get(format);
const auto entry = UserFormatRegister::Get(format);
if(!entry.read)
throw Exception("Reading format " + format + " is not implemented");

View File

@ -15,15 +15,103 @@
namespace netgen
{
using std::vector;
struct AbaqusElementType
{
const char * name;
const vector<int> permutation;
AbaqusElementType(const char * name, const vector<int> & permutation)
: name(name), permutation(permutation)
{}
};
static inline const AbaqusElementType & GetAbaqusType(int dim, int num_nodes)
{
// maps num_nodes to AbaqusElementType for each dimension
typedef std::map<int, AbaqusElementType> AbaqusElementTypes;
static const std::map<int, AbaqusElementType> abaqus_eltypes[3] =
{
// 1D
AbaqusElementTypes{
{2, AbaqusElementType{"T2D2", vector{0,1}}},
},
// 2D
AbaqusElementTypes{
{3, AbaqusElementType{"CPS3", vector{0,1,2}}},
},
// 3D
AbaqusElementTypes{
{4, AbaqusElementType{"C3D4", vector{0,1,3,2}}},
{10, AbaqusElementType{"C3D10", vector{0,1,3,2,4,8,6,5,7,9}}},
}
};
const auto & eltypes = abaqus_eltypes[dim-1];
if (eltypes.count(num_nodes) > 0)
return eltypes.at(num_nodes);
else
throw Exception("unsupported " + ToString(dim)+"d Element type with " + ToString(num_nodes) + " nodes");
}
static void WritePoints ( const Mesh & mesh, ostream & out )
{
out << "*Node" << endl;
for(auto pi : mesh.Points().Range() )
{
out << pi+1-PointIndex::BASE << ", ";
auto p = mesh[pi];
out << p[0] << ", " << p[1] << ", " << p[2] << '\n';
}
}
template <typename ElIndex>
static void WriteElement(ostream & out, const Mesh& mesh, ElIndex ei, const vector<int> & permutation, int & el_counter)
{
el_counter++;
auto el = mesh[ei];
out << el_counter;
for(auto i : Range(el.PNums()))
out << ", " << el[permutation[i]]+1-PointIndex::BASE;
out << '\n';
}
template <typename ElIndex, typename Elements>
static void WriteElements ( ostream & out, const Mesh & mesh, int dim, const Elements & el_range, int & el_counter)
{
// map index, num_nodes to elements
std::map<std::tuple<int, int>, Array<ElIndex>> elset_map;
for(auto ei : el_range)
{
const auto & el = mesh[ei];
int index = 0;
if constexpr(std::is_same_v<ElIndex,SegmentIndex>)
index = el.edgenr;
else
index = el.GetIndex();
elset_map[{index, el.GetNP()}].Append(ei);
}
for(auto & [key, elems] : elset_map)
{
auto [index, num_nodes] = key;
auto name = mesh.GetRegionName(elems[0]);
if (name == "") name = "default";
PrintMessage (5, index, ": ", name);
const auto & eltype = GetAbaqusType(dim, num_nodes) ;
out << "*Element, type=" << eltype.name << ", ELSET=" << name << endl;
for(auto ei : elems)
WriteElement(out, mesh, ei, eltype.permutation, el_counter);
}
}
void WriteAbaqusFormat (const Mesh & mesh,
const filesystem::path & filename)
{
cout << "\nWrite Abaqus Volume Mesh" << endl;
PrintMessage (1, "Write Abaqus Mesh");
ofstream outfile (filename);
@ -32,96 +120,17 @@ void WriteAbaqusFormat (const Mesh & mesh,
outfile.precision(8);
outfile << "*Node" << endl;
int np = mesh.GetNP();
int ne = mesh.GetNE();
int i, j, k;
for (i = 1; i <= np; i++)
{
outfile << i << ", ";
outfile << mesh.Point(i)(0) << ", ";
outfile << mesh.Point(i)(1) << ", ";
outfile << mesh.Point(i)(2) << "\n";
}
int elemcnt = 0; //element counter
int finished = 0;
int indcnt = 1; //index counter
while (!finished)
{
int actcnt = 0;
const Element & el1 = mesh.VolumeElement(1);
int non = el1.GetNP();
if (non == 4)
{
outfile << "*Element, type=C3D4, ELSET=PART" << indcnt << endl;
}
else if (non == 10)
{
outfile << "*Element, type=C3D10, ELSET=PART" << indcnt << endl;
}
else
{
cout << "unsupported Element type!!!" << endl;
}
for (i = 1; i <= ne; i++)
{
const Element & el = mesh.VolumeElement(i);
if (el.GetIndex() == indcnt)
{
actcnt++;
if (el.GetNP() != non)
{
cout << "different element-types in a subdomain are not possible!!!" << endl;
continue;
}
elemcnt++;
outfile << elemcnt << ", ";
if (non == 4)
{
outfile << el.PNum(1) << ", ";
outfile << el.PNum(2) << ", ";
outfile << el.PNum(4) << ", ";
outfile << el.PNum(3) << "\n";
}
else if (non == 10)
{
outfile << el.PNum(1) << ", ";
outfile << el.PNum(2) << ", ";
outfile << el.PNum(4) << ", ";
outfile << el.PNum(3) << ", ";
outfile << el.PNum(5) << ", ";
outfile << el.PNum(9) << ", ";
outfile << el.PNum(7) << ", " << "\n";
outfile << el.PNum(6) << ", ";
outfile << el.PNum(8) << ", ";
outfile << el.PNum(10) << "\n";
}
else
{
cout << "unsupported Element type!!!" << endl;
for (j = 1; j <= el.GetNP(); j++)
{
outfile << el.PNum(j);
if (j != el.GetNP()) outfile << ", ";
}
outfile << "\n";
}
}
}
indcnt++;
if (elemcnt == ne) {finished = 1; cout << "all elements found by Index!" << endl;}
if (actcnt == 0) {finished = 1;}
}
int element_counter = 0;
WritePoints(mesh, outfile);
if(mesh.GetDimension() < 3)
WriteElements<SegmentIndex>(outfile, mesh, 1, mesh.LineSegments().Range(), element_counter);
WriteElements<SurfaceElementIndex>(outfile, mesh, 2, mesh.SurfaceElements().Range(), element_counter);
WriteElements<ElementIndex>(outfile, mesh, 3, mesh.VolumeElements().Range(), element_counter);
// Write identifications (untested!)
if (mesh.GetIdentifications().GetMaxNr())
{
const auto np = mesh.GetNP();
// periodic identification, implementation for
// Helmut J. Boehm, TU Vienna
@ -138,27 +147,27 @@ void WriteAbaqusFormat (const Mesh & mesh,
NgArray<INDEX_2> pairs;
NgBitArray master(np), help(np);
master.Set();
for (i = 1; i <= 3; i++)
for (int i = 1; i <= 3; i++)
{
mesh.GetIdentifications().GetPairs (i, pairs);
help.Clear();
for (j = 1; j <= pairs.Size(); j++)
for (int j = 1; j <= pairs.Size(); j++)
{
help.Set (pairs.Get(j).I1());
}
master.And (help);
}
for (i = 1; i <= np; i++)
for (int i = 1; i <= np; i++)
if (master.Test(i))
masternode = i;
cout << "masternode = " << masternode << " = "
<< mesh.Point(masternode) << endl;
NgArray<int> minions(3);
for (i = 1; i <= 3; i++)
for (int i = 1; i <= 3; i++)
{
mesh.GetIdentifications().GetPairs (i, pairs);
for (j = 1; j <= pairs.Size(); j++)
for (int j = 1; j <= pairs.Size(); j++)
{
if (pairs.Get(j).I1() == masternode)
minions.Elem(i) = pairs.Get(j).I2();
@ -179,12 +188,12 @@ void WriteAbaqusFormat (const Mesh & mesh,
<< "**POINT_fixed\n"
<< "**\n"
<< "*BOUNDARY, OP=NEW\n";
for (j = 1; j <= 3; j++)
for (int j = 1; j <= 3; j++)
outfile << masternode << ", " << j << ",, 0.\n";
outfile << "**\n"
<< "*BOUNDARY, OP=NEW\n";
for (j = 1; j <= 3; j++)
for (int j = 1; j <= 3; j++)
{
Vec3d v(mesh.Point(masternode), mesh.Point(minions.Get(j)));
double vlen = v.Length();
@ -203,18 +212,18 @@ void WriteAbaqusFormat (const Mesh & mesh,
NgBitArray eliminated(np);
eliminated.Clear();
for (i = 1; i <= mesh.GetIdentifications().GetMaxNr(); i++)
for (int i = 1; i <= mesh.GetIdentifications().GetMaxNr(); i++)
{
mesh.GetIdentifications().GetPairs (i, pairs);
if (!pairs.Size())
continue;
for (j = 1; j <= pairs.Size(); j++)
for (int j = 1; j <= pairs.Size(); j++)
if (pairs.Get(j).I1() != masternode &&
!eliminated.Test(pairs.Get(j).I2()))
{
eliminated.Set (pairs.Get(j).I2());
for (k = 1; k <= 3; k++)
for (int k = 1; k <= 3; k++)
{
mpc << "4" << "\n";
mpc << pairs.Get(j).I2() << "," << k << ", -1.0, ";
@ -227,7 +236,7 @@ void WriteAbaqusFormat (const Mesh & mesh,
}
cout << "done" << endl;
PrintMessage(1, "done");
}
static RegisterUserFormat reg_abaqus ("Abaqus Format", {".mesh"}, nullopt, WriteAbaqusFormat);

View File

@ -39,7 +39,7 @@ bool WriteUserFormat (const string & format,
if(!UserFormatRegister::HaveFormat(format))
return true;
const auto & entry = UserFormatRegister::Get(format);
const auto entry = UserFormatRegister::Get(format);
if(!entry.write)
return true;

View File

@ -49,7 +49,8 @@ namespace netgen
{
data = NULL; height = width = 0;
SetSize (m2.Height(), m2.Width());
memcpy (data, m2.data, sizeof(double) * Height() * Width());
if (Height() && Width())
memcpy (data, m2.data, sizeof(double) * (Height() * Width()));
}
DenseMatrix :: ~DenseMatrix ()
@ -69,7 +70,7 @@ namespace netgen
delete[] data;
if (h*w)
if (h && w)
data = new double[h*w];
else
data = NULL;

View File

@ -214,6 +214,7 @@ namespace netgen
}
}
namespace {
struct Line
{
Point<3> p0, p1;
@ -230,6 +231,7 @@ namespace netgen
return 1e99;
}
};
}
void NetgenGeometry :: Clear()
{

View File

@ -86,6 +86,9 @@ namespace netgen
protected:
GeometryVertex *start, *end;
public:
// Neighboring domains in 2d
// In 3d unused, EXCEPT for free floating edges in a domain,
// then both are pointing to the containing domain
int domin=-1, domout=-1;
GeometryEdge( GeometryVertex &start_, GeometryVertex &end_ )
@ -187,7 +190,10 @@ namespace netgen
};
class DLL_HEADER GeometrySolid : public GeometryShape
{ };
{
public:
Array<GeometryEdge*> free_edges; // edges with no adjacent face
};
class DLL_HEADER NetgenGeometry
{

View File

@ -20,8 +20,8 @@ struct SpecialPointException : public Exception
std::tuple<int, int> FindCloseVectors (FlatArray<Vec<3>> ns,
bool find_max = true)
{
int maxpos1;
int maxpos2;
int maxpos1 = 0;
int maxpos2 = 0;
double val = find_max ? -1e99 : 1e99;
for (auto i : Range(ns))

View File

@ -405,18 +405,24 @@ namespace netgen
}
}
static NgArray<shared_ptr<RecPol>> jacpols2;
void CurvedElements::buildJacPols()
struct JacobiRecPols
{
if (!jacpols2.Size())
static constexpr size_t N = 100;
ArrayMem<unique_ptr<JacobiRecPol>, N> jacpols;
JacobiRecPols()
{
jacpols2.SetSize (100);
for (int i = 0; i < 100; i++)
jacpols2[i] = make_shared<JacobiRecPol> (100, i, 2);
jacpols.SetSize (N);
for (int i = 0; i < N; i++)
jacpols[i] = make_unique<JacobiRecPol>(N, i, 2);
}
const unique_ptr<JacobiRecPol> & operator[] (int i) {
return jacpols[i];
}
};
static JacobiRecPols jacpols2;
// compute face bubbles up to order n, 0 < y, y-x < 1, x+y < 1
template <class Tx, class Ty, class Ts>
@ -710,7 +716,6 @@ namespace netgen
ComputeGaussRule (aorder+4, xi, weight); // on (0,1)
buildJacPols();
PrintMessage (3, "Curving edges");
if (mesh.GetDimension() == 3 || rational)

View File

@ -38,7 +38,6 @@ class CurvedElements
bool rational;
bool ishighorder;
void buildJacPols();
public:
DLL_HEADER CurvedElements (const Mesh & amesh);
@ -56,8 +55,6 @@ public:
void DoArchive(Archive& ar)
{
if(ar.Input())
buildJacPols();
ar & edgeorder & faceorder & edgecoeffsindex & facecoeffsindex & edgecoeffs & facecoeffs
& edgeweight & order & rational & ishighorder;
}

View File

@ -564,7 +564,7 @@ namespace netgen
void Delaunay1 (Mesh & mesh, const MeshingParameters & mp, AdFront3 * adfront,
void Delaunay1 (Mesh & mesh, int domainnr, const MeshingParameters & mp, AdFront3 * adfront,
NgArray<DelaunayTet> & tempels,
int oldnp, DelaunayTet & startel, Point3d & pmin, Point3d & pmax)
{
@ -623,6 +623,13 @@ namespace netgen
for (PointIndex pi : mesh.LockedPoints())
usep[pi] = true;
// mark points of free edge segments (no adjacent face)
for (auto & seg : mesh.LineSegments())
if(seg.domin == domainnr && seg.domout == domainnr)
{
usep[seg[0]] = true;
usep[seg[1]] = true;
}
NgArray<int> freelist;
@ -1554,7 +1561,7 @@ namespace netgen
int np = mesh.GetNP();
Delaunay1 (mesh, mp, adfront, tempels, oldnp, startel, pmin, pmax);
Delaunay1 (mesh, domainnr, mp, adfront, tempels, oldnp, startel, pmin, pmax);
{
// improve delaunay - mesh by swapping !!!!

View File

@ -14,6 +14,11 @@
namespace netgen
{
static constexpr int tetedges[6][2] =
{ { 0, 1 }, { 0, 2 }, { 0, 3 },
{ 1, 2 }, { 1, 3 }, { 2, 3 } };
static constexpr int IMPROVEMENT_CONFORMING_EDGE = -1e6;
static inline bool NotTooBad(double bad1, double bad2)
@ -258,6 +263,26 @@ double MeshOptimize3d :: CombineImproveEdge (
for (auto ei : has_both_points)
badness_old += mesh[ei].GetBadness();
if (goal == OPT_CONFORM && p0.Type() <= EDGEPOINT) {
// check if the optimization improves conformity with free segments
std::set<PointIndex> edges_before, edges_after;
for (auto ei : has_one_point) {
const auto el = mesh[ei];
for(auto i : Range(6)) {
auto e0 = el[tetedges[i][0]];
auto e1 = el[tetedges[i][1]];
if(e0 == pi0 || e1 == pi0) edges_before.insert(e0 == pi0 ? e1 : e0);
if(e0 == pi1 || e1 == pi1) edges_after.insert(e0 == pi1 ? e1 : e0);
}
}
for(auto new_edge : edges_after) {
if (edges_before.count(new_edge) == 0 && mesh[new_edge].Type() <= EDGEPOINT && mesh.BoundaryEdge (new_edge, pi0))
badness_old += GetLegalPenalty();
}
}
MeshPoint pnew = p0;
if (p0.Type() == INNERPOINT)
pnew = Center (p0, p1);
@ -1041,7 +1066,8 @@ double MeshOptimize3d :: SwapImproveEdge (
bad3 += GetLegalPenalty();
}
bool swap2, swap3;
bool swap2=false;
bool swap3=false;
if (goal == OPT_CONFORM)
{
@ -1548,10 +1574,6 @@ void MeshOptimize3d :: SwapImproveSurface (
// loop over edges
static const int tetedges[6][2] =
{ { 0, 1 }, { 0, 2 }, { 0, 3 },
{ 1, 2 }, { 1, 3 }, { 2, 3 } };
pi1 = elemi[tetedges[j][0]];
pi2 = elemi[tetedges[j][1]];
@ -2406,6 +2428,8 @@ double MeshOptimize3d :: SwapImprove2 ( ElementIndex eli1, int face,
!mesh.LegalTet(elem2))
bad1 += GetLegalPenalty();
if(mesh.BoundaryEdge (pi4, pi5))
bad1 += GetLegalPenalty();
el31.PNum(1) = pi1;
el31.PNum(2) = pi2;
@ -2583,13 +2607,9 @@ double MeshOptimize3d :: SplitImprove2Element (
return false;
// search for very flat tets, with two disjoint edges nearly crossing, like a rectangle with diagonals
static constexpr int tetedges[6][2] =
{ { 0, 1 }, { 0, 2 }, { 0, 3 },
{ 1, 2 }, { 1, 3 }, { 2, 3 } };
int minedge = -1;
double mindist = 1e99;
double minlam0, minlam1;
double minlam0=0, minlam1=0;
for (int i : Range(3))
{

View File

@ -196,8 +196,8 @@ namespace netgen
auto& el = mesh.SurfaceElement(velement);
if(el.GetType() == TRIG)
{
double seg_lam;
double lam;
double seg_lam=-1;
double lam=-1;
auto seg = mesh.LineSegment(segs[i]);
for(auto k : Range(3))
{
@ -7529,6 +7529,21 @@ namespace netgen
}
std::string_view Mesh :: GetRegionName (const Segment & el) const
{
return *const_cast<Mesh&>(*this).GetRegionNamesCD(GetDimension()-1)[el.edgenr-1];
}
std::string_view Mesh :: GetRegionName (const Element2d & el) const
{
return *const_cast<Mesh&>(*this).GetRegionNamesCD(GetDimension()-2)[GetFaceDescriptor(el).BCProperty()-1];
}
std::string_view Mesh :: GetRegionName (const Element & el) const
{
return *const_cast<Mesh&>(*this).GetRegionNamesCD(GetDimension()-3)[el.GetIndex()-1];
}
void Mesh :: SetUserData(const char * id, NgArray<int> & data)
{

View File

@ -750,6 +750,14 @@ namespace netgen
DLL_HEADER NgArray<string*> & GetRegionNamesCD (int codim);
DLL_HEADER std::string_view GetRegionName(const Segment & el) const;
DLL_HEADER std::string_view GetRegionName(const Element2d & el) const;
DLL_HEADER std::string_view GetRegionName(const Element & el) const;
std::string_view GetRegionName(SegmentIndex ei) const { return GetRegionName((*this)[ei]); }
std::string_view GetRegionName(SurfaceElementIndex ei) const { return GetRegionName((*this)[ei]); }
std::string_view GetRegionName(ElementIndex ei) const { return GetRegionName((*this)[ei]); }
///
void ClearFaceDescriptors()
{ facedecoding.SetSize(0); }

View File

@ -81,6 +81,16 @@ namespace netgen
m.AddFaceDescriptor( mesh.GetFaceDescriptor(i) );
}
// mark interior edge points
for(const auto& seg : mesh.LineSegments())
{
if(seg.domin > 0 && seg.domin == seg.domout)
{
ipmap[seg.domin-1][seg[0]] = 1;
ipmap[seg.domin-1][seg[1]] = 1;
}
}
// mark used points for each domain, add surface elements (with wrong point numbers) to domain mesh
for(const auto & sel : mesh.SurfaceElements())
{
@ -509,7 +519,6 @@ namespace netgen
}
while (!meshed);
{
PrintMessage (3, "Check subdomain ", domain, " / ", mesh.GetNDomains());
mesh.FindOpenElements(domain);
@ -522,8 +531,8 @@ namespace netgen
PrintError ("Surface mesh not consistent");
throw NgException ("Stop meshing since surface mesh not consistent");
}
}
RemoveIllegalElements (mesh, domain);
ConformToFreeSegments (mesh, domain);
}
void MergeMeshes( Mesh & mesh, Array<MeshingData> & md )
@ -617,6 +626,7 @@ namespace netgen
{
ParallelFor( md.Range(), [&](int i)
{
try {
if (mp.checkoverlappingboundary)
if (md[i].mesh->CheckOverlappingBoundary())
{
@ -629,6 +639,11 @@ namespace netgen
FillCloseSurface( md[i] );
CloseOpenQuads( md[i] );
MeshDomain(md[i]);
}
catch (const Exception & e) {
cerr << "Meshing of domain " << i+1 << " failed with error: " << e.what() << endl;
throw e;
}
}, md.Size());
}
catch(...)
@ -736,6 +751,65 @@ namespace netgen
}
void ConformToFreeSegments (Mesh & mesh, int domain)
{
auto geo = mesh.GetGeometry();
if(!geo) return;
auto n_solids = geo->GetNSolids();
if(!n_solids) return;
if(geo->GetSolid(domain-1).free_edges.Size() == 0)
return;
Segment bad_seg;
Array<Segment> free_segs;
for (auto seg : mesh.LineSegments())
if(seg.domin == domain && seg.domout == domain)
free_segs.Append(seg);
auto num_nonconforming = [&] () {
size_t count = 0;
auto p2el = mesh.CreatePoint2ElementTable();
for (auto seg : free_segs) {
auto has_p0 = p2el[seg[0]];
bool has_both = false;
for(auto ei : has_p0) {
if(mesh[ei].PNums().Contains(seg[1]))
has_both = true;
}
if(!has_both) {
bad_seg = seg;
count++;
}
}
return count;
};
for ([[maybe_unused]] auto i : Range(5)) {
auto num_bad_segs = num_nonconforming();
PrintMessage(1, "Non-conforming free segments in domain ", domain, ": ", num_bad_segs);
if(num_bad_segs == 0)
return;
MeshingParameters dummymp;
MeshOptimize3d optmesh(mesh, dummymp, OPT_CONFORM);
for ([[maybe_unused]] auto i : Range(3)) {
optmesh.SwapImprove2 ();
optmesh.SwapImprove();
optmesh.CombineImprove();
}
}
if(debugparam.write_mesh_on_error)
mesh.Save("free_segment_not_conformed_dom_"+ToString(domain)+"_seg_"+ToString(bad_seg[0])+"_"+ToString(bad_seg[1])+".vol.gz");
throw Exception("Segment not resolved in volume mesh in domain " + ToString(domain)+ ", seg: " + ToString(bad_seg));
}
void RemoveIllegalElements (Mesh & mesh3d, int domain)

View File

@ -31,6 +31,7 @@ DLL_HEADER MESHING3_RESULT OptimizeVolume (const MeshingParameters & mp, Mesh& m
// const CSGeometry * geometry = NULL);
DLL_HEADER void RemoveIllegalElements (Mesh & mesh3d, int domain = 0);
DLL_HEADER void ConformToFreeSegments (Mesh & mesh3d, int domain);
enum MESHING_STEP {

View File

@ -175,7 +175,8 @@ namespace netgen
}
constexpr PointIndex (t_invalid inv) : i(PointIndex::BASE-1) { ; }
// PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; }
constexpr operator int () const { return i; }
constexpr operator const int& () const { return i; }
explicit constexpr operator int& () { return i; }
PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; }
PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; }
PointIndex & operator++ () { i++; return *this; }

View File

@ -222,8 +222,8 @@ namespace netgen
int dim = GetDimension();
comm.Bcast(dim);
Array<NG_MPI_Request> sendrequests(8*(ntasks-1));
sendrequests.SetSize0();
NgMPI_Requests sendrequests; // (8*(ntasks-1));
// sendrequests.SetSize0();
// If the topology is not already updated, we do not need to
// build edges/faces.
@ -457,7 +457,7 @@ namespace netgen
{
NgFlatArray<PointIndex> verts = verts_of_proc[dest];
// sendrequests.Append (MyMPI_ISend (verts, dest, NG_MPI_TAG_MESH+1, comm));
sendrequests.Append (comm.ISend (FlatArray<PointIndex>(verts), dest, NG_MPI_TAG_MESH+1));
sendrequests += comm.ISend (FlatArray<PointIndex>(verts), dest, NG_MPI_TAG_MESH+1);
NG_MPI_Datatype mptype = MeshPoint::MyGetMPIType();
@ -473,7 +473,7 @@ namespace netgen
NG_MPI_Request request;
NG_MPI_Isend( points.Data(), 1, point_types[dest-1], dest, NG_MPI_TAG_MESH+1, comm, &request);
sendrequests.Append (request);
sendrequests += request;
}
@ -533,11 +533,11 @@ namespace netgen
}
}
}
Array<NG_MPI_Request> req_per;
NgMPI_Requests req_per;
for(int dest = 1; dest < ntasks; dest++)
// req_per.Append(MyMPI_ISend(pp_data[dest], dest, NG_MPI_TAG_MESH+1, comm));
req_per.Append(comm.ISend(FlatArray<int>(pp_data[dest]), dest, NG_MPI_TAG_MESH+1));
MyMPI_WaitAll(req_per);
req_per += comm.ISend(FlatArray<int>(pp_data[dest]), dest, NG_MPI_TAG_MESH+1);
req_per.WaitAll();
PrintMessage ( 3, "Sending Vertices - distprocs");
@ -570,7 +570,7 @@ namespace netgen
tbuilddistpnums.Stop();
for ( int dest = 1; dest < ntasks; dest ++ )
sendrequests.Append (comm.ISend (distpnums[dest], dest, NG_MPI_TAG_MESH+1));
sendrequests += comm.ISend (distpnums[dest], dest, NG_MPI_TAG_MESH+1);
@ -604,7 +604,7 @@ namespace netgen
tbuildelementtable.Stop();
for (int dest = 1; dest < ntasks; dest ++ )
sendrequests.Append (comm.ISend (elementarrays[dest], dest, NG_MPI_TAG_MESH+2));
sendrequests += comm.ISend (elementarrays[dest], dest, NG_MPI_TAG_MESH+2);
PrintMessage ( 3, "Sending Face Descriptors" );
@ -621,7 +621,7 @@ namespace netgen
}
for (int dest = 1; dest < ntasks; dest++)
sendrequests.Append (comm.ISend (fddata, dest, NG_MPI_TAG_MESH+3));
sendrequests += comm.ISend (fddata, dest, NG_MPI_TAG_MESH+3);
/** Surface Elements **/
@ -697,7 +697,7 @@ namespace netgen
});
// distribute sel data
for (int dest = 1; dest < ntasks; dest++)
sendrequests.Append (comm.ISend(selbuf[dest], dest, NG_MPI_TAG_MESH+4));
sendrequests += comm.ISend(selbuf[dest], dest, NG_MPI_TAG_MESH+4);
/** Segments **/
@ -849,7 +849,7 @@ namespace netgen
});
// distribute segment data
for (int dest = 1; dest < ntasks; dest++)
sendrequests.Append (comm.ISend(segm_buf[dest], dest, NG_MPI_TAG_MESH+5));
sendrequests += comm.ISend(segm_buf[dest], dest, NG_MPI_TAG_MESH+5);
/** Point-Elements **/
PrintMessage ( 3, "Point-Elements ...");
@ -870,11 +870,11 @@ namespace netgen
iterate_zdes([&](const auto & pack, auto dest) { zde_buf.Add(dest, pack); });
for (int dest = 1; dest < ntasks; dest++)
{ sendrequests.Append (comm.ISend(zde_buf[dest], dest, NG_MPI_TAG_MESH+6)); }
sendrequests += comm.ISend(zde_buf[dest], dest, NG_MPI_TAG_MESH+6);
PrintMessage ( 3, "now wait ...");
MyMPI_WaitAll (sendrequests);
sendrequests.WaitAll();
// clean up MPI-datatypes we allocated earlier
for (auto t : point_types)
@ -885,18 +885,18 @@ namespace netgen
paralleltop -> EnumeratePointsGlobally();
PrintMessage ( 3, "Sending names");
sendrequests.SetSize(3*ntasks);
/** Send bc/mat/cd*-names **/
// nr of names
ArrayMem<int,4> nnames{0,0,0,0};
std::array<int,4> nnames{0,0,0,0};
nnames[0] = materials.Size();
nnames[1] = bcnames.Size();
nnames[2] = GetNCD2Names();
nnames[3] = GetNCD3Names();
int tot_nn = nnames[0] + nnames[1] + nnames[2] + nnames[3];
for( int k = 1; k < ntasks; k++)
sendrequests[k] = comm.ISend(nnames, k, NG_MPI_TAG_MESH+7);
// (void) NG_MPI_Isend(nnames, 4, NG_MPI_INT, k, NG_MPI_TAG_MESH+6, comm, &sendrequests[k]);
NgMPI_Requests requ;
requ += comm.IBcast (nnames);
auto iterate_names = [&](auto func) {
for (int k = 0; k < nnames[0]; k++) func(materials[k]);
for (int k = 0; k < nnames[1]; k++) func(bcnames[k]);
@ -904,27 +904,27 @@ namespace netgen
for (int k = 0; k < nnames[3]; k++) func(cd3names[k]);
};
// sizes of names
NgArray<int> name_sizes(tot_nn);
Array<int> name_sizes(tot_nn);
tot_nn = 0;
iterate_names([&](auto ptr) { name_sizes[tot_nn++] = (ptr==NULL) ? 0 : ptr->size(); });
for( int k = 1; k < ntasks; k++)
(void) NG_MPI_Isend(&name_sizes[0], tot_nn, NG_MPI_INT, k, NG_MPI_TAG_MESH+7, comm, &sendrequests[ntasks+k]);
requ += comm.IBcast (name_sizes);
// names
int strs = 0;
iterate_names([&](auto ptr) { strs += (ptr==NULL) ? 0 : ptr->size(); });
NgArray<char> compiled_names(strs);
Array<char> compiled_names(strs);
strs = 0;
iterate_names([&](auto ptr) {
if (ptr==NULL) return;
auto& name = *ptr;
for (int j=0; j < name.size(); j++) compiled_names[strs++] = name[j];
});
for( int k = 1; k < ntasks; k++)
(void) NG_MPI_Isend(&(compiled_names[0]), strs, NG_MPI_CHAR, k, NG_MPI_TAG_MESH+7, comm, &sendrequests[2*ntasks+k]);
requ += comm.IBcast (compiled_names);
PrintMessage ( 3, "wait for names");
MyMPI_WaitAll (sendrequests);
requ.WaitAll();
comm.Barrier();
@ -1182,9 +1182,20 @@ namespace netgen
// paralleltop -> SetNV_Loc2Glob (0);
paralleltop -> EnumeratePointsGlobally();
/** Recv bc-names **/
/*
ArrayMem<int,4> nnames{0,0,0,0};
// NG_MPI_Recv(nnames, 4, NG_MPI_INT, 0, NG_MPI_TAG_MESH+6, comm, NG_MPI_STATUS_IGNORE);
comm.Recv(nnames, 0, NG_MPI_TAG_MESH+7);
*/
// Array<NG_MPI_Request> recvrequests(1);
std::array<int,4> nnames;
/*
recvrequests[0] = comm.IBcast (nnames);
MyMPI_WaitAll (recvrequests);
*/
comm.IBcast (nnames).Wait();
// cout << "nnames = " << FlatArray(nnames) << endl;
materials.SetSize(nnames[0]);
bcnames.SetSize(nnames[1]);
@ -1192,19 +1203,29 @@ namespace netgen
cd3names.SetSize(nnames[3]);
int tot_nn = nnames[0] + nnames[1] + nnames[2] + nnames[3];
NgArray<int> name_sizes(tot_nn);
NG_MPI_Recv(&name_sizes[0], tot_nn, NG_MPI_INT, 0, NG_MPI_TAG_MESH+7, comm, NG_MPI_STATUS_IGNORE);
Array<int> name_sizes(tot_nn);
// NG_MPI_Recv(&name_sizes[0], tot_nn, NG_MPI_INT, 0, NG_MPI_TAG_MESH+7, comm, NG_MPI_STATUS_IGNORE);
/*
recvrequests[0] = comm.IBcast (name_sizes);
MyMPI_WaitAll (recvrequests);
*/
comm.IBcast (name_sizes).Wait();
int tot_size = 0;
for (int k = 0; k < tot_nn; k++) tot_size += name_sizes[k];
NgArray<char> compiled_names(tot_size);
NG_MPI_Recv(&(compiled_names[0]), tot_size, NG_MPI_CHAR, 0, NG_MPI_TAG_MESH+7, comm, NG_MPI_STATUS_IGNORE);
// NgArray<char> compiled_names(tot_size);
// NG_MPI_Recv(&(compiled_names[0]), tot_size, NG_MPI_CHAR, 0, NG_MPI_TAG_MESH+7, comm, NG_MPI_STATUS_IGNORE);
Array<char> compiled_names(tot_size);
// recvrequests[0] = comm.IBcast (compiled_names);
// MyMPI_WaitAll (recvrequests);
comm.IBcast (compiled_names).Wait();
tot_nn = tot_size = 0;
auto write_names = [&] (auto & array) {
for (int k = 0; k < array.Size(); k++) {
int s = name_sizes[tot_nn];
array[k] = new string(&compiled_names[tot_size], s);
array[k] = s ? new string(&compiled_names[tot_size], s) : nullptr;
tot_nn++;
tot_size += s;
}

View File

@ -1,6 +1,3 @@
// #ifdef PARALLEL
#include <meshing.hpp>
#include "paralleltop.hpp"
@ -138,16 +135,17 @@ namespace netgen
for (auto p : dps)
send_data[p][nsend[p]++] = L2G(pi);
Array<NG_MPI_Request> requests;
NgMPI_Requests requests;
for (int i = 0; i < comm.Size(); i++)
{
if (nsend[i])
requests.Append (comm.ISend (send_data[i], i, 200));
requests += comm.ISend (send_data[i], i, 200);
if (nrecv[i])
requests.Append (comm.IRecv (recv_data[i], i, 200));
requests += comm.IRecv (recv_data[i], i, 200);
}
MyMPI_WaitAll (requests);
// MyMPI_WaitAll (requests);
requests.WaitAll();
Array<int> cnt(comm.Size());
cnt = 0;
@ -501,7 +499,6 @@ namespace netgen
}
DynamicTable<int> recv_verts(ntasks);
// MyMPI_ExchangeTable (send_verts, recv_verts, NG_MPI_TAG_MESH+9, comm);
comm.ExchangeTable (send_verts, recv_verts, NG_MPI_TAG_MESH+9);
for (int dest = 0; dest < ntasks; dest++)
@ -694,12 +691,8 @@ namespace netgen
}
}
// cout << "UpdateCoarseGrid - edges mpi-exchange" << endl;
// TABLE<int> recv_edges(ntasks);
DynamicTable<int> recv_edges(ntasks);
// MyMPI_ExchangeTable (send_edges, recv_edges, NG_MPI_TAG_MESH+9, comm);
comm.ExchangeTable (send_edges, recv_edges, NG_MPI_TAG_MESH+9);
// cout << "UpdateCoarseGrid - edges mpi-exchange done" << endl;
for (int dest = 0; dest < ntasks; dest++)
{
@ -804,12 +797,8 @@ namespace netgen
}
}
// cout << "UpdateCoarseGrid - faces mpi-exchange" << endl;
// TABLE<int> recv_faces(ntasks);
DynamicTable<int> recv_faces(ntasks);
// MyMPI_ExchangeTable (send_faces, recv_faces, NG_MPI_TAG_MESH+9, comm);
comm.ExchangeTable (send_faces, recv_faces, NG_MPI_TAG_MESH+9);
// cout << "UpdateCoarseGrid - faces mpi-exchange done" << endl;
for (int dest = 0; dest < ntasks; dest++)
{
@ -846,4 +835,3 @@ namespace netgen
}
// #endif

View File

@ -268,7 +268,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
.def(py::init<int>())
.def("__repr__", &ToString<PointIndex>)
.def("__str__", &ToString<PointIndex>)
.def_property_readonly("nr", &PointIndex::operator int)
.def_property_readonly("nr", &PointIndex::operator const int&)
.def("__eq__" , FunctionPointer( [](PointIndex &self, PointIndex &other)
{ return static_cast<int>(self)==static_cast<int>(other); }) )
.def("__hash__" , FunctionPointer( [](PointIndex &self ) { return static_cast<int>(self); }) )

View File

@ -1132,6 +1132,21 @@ namespace netgen
}
}
*/
std::map<int, ArrayMem<int, 10>> free_edges_in_solid;
for(auto i1 : Range(1, somap.Extent()+1))
{
auto s = somap(i1);
for (auto edge : MyExplorer(s, TopAbs_EDGE, TopAbs_WIRE))
if (!emap.Contains(edge))
{
free_edges_in_solid[i1].Append(emap.Add (edge));
for (auto vertex : MyExplorer(edge, TopAbs_VERTEX))
if (!vmap.Contains(vertex))
vmap.Add (vertex);
}
}
for (auto edge : MyExplorer(shape, TopAbs_EDGE, TopAbs_WIRE))
if (!emap.Contains(edge))
{
@ -1256,6 +1271,16 @@ namespace netgen
if(face.Shape().Orientation() == TopAbs_INTERNAL)
face.domout = k;
}
if(free_edges_in_solid.count(i1))
for(auto ei : free_edges_in_solid[i1])
{
auto & edge = GetEdge(emap(ei));
edge.properties.maxh = min(edge.properties.maxh, occ_solid->properties.maxh);
edge.domin = k;
edge.domout = k;
occ_solid->free_edges.Append(&GetEdge(emap(ei)));
}
solids.Append(std::move(occ_solid));
}

View File

@ -167,12 +167,9 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m)
py::class_<gp_Pnt2d>(m, "gp_Pnt2d", "2d OCC point")
.def(py::init([] (py::tuple pnt)
.def(py::init([] (std::tuple<double,double> pnt)
{
if (py::len(pnt) != 2)
throw Exception("need 2-tuple to create gp_Pnt2d");
return gp_Pnt2d(py::cast<double>(pnt[0]),
py::cast<double>(pnt[1]));
return gp_Pnt2d(get<0>(pnt), get<1>(pnt));
}))
.def(py::init([] (double x, double y) {
return gp_Pnt2d(x, y);

View File

@ -610,11 +610,11 @@ public:
return Circle (pos.X(), pos.Y(), r);
}
shared_ptr<WorkPlane> Close ()
shared_ptr<WorkPlane> Close (optional<string> name = nullopt)
{
if (startpnt.Distance(localpos.Location()) > 1e-10)
{
LineTo (startpnt.X(), startpnt.Y());
LineTo (startpnt.X(), startpnt.Y(), name);
return shared_from_this();
}
@ -2635,7 +2635,8 @@ degen_tol : double
.def("NameVertex", &WorkPlane::NameVertex, py::arg("name"), "name vertex at current position")
.def("Offset", &WorkPlane::Offset, py::arg("d"), "replace current wire by offset curve of distance 'd'")
.def("Reverse", &WorkPlane::Reverse, "revert orientation of current wire")
.def("Close", &WorkPlane::Close, "draw line to start point of wire, and finish wire")
.def("Close", &WorkPlane::Close, py::arg("name")=nullopt,
"draw line to start point of wire, and finish wire")
.def("Finish", &WorkPlane::Finish, "finish current wire without closing")
.def("Last", &WorkPlane::Last, "(deprecated) returns current wire")
.def("Wire", &WorkPlane::Last, "returns current wire")

View File

@ -224,7 +224,7 @@ NGCORE_API_EXPORT void ExportSTL(py::module & m)
.def("GetVicinity", [] (shared_ptr<STLGeometry> self, int node, int size, string type) {
NgArray<int> vic;
int trig;
int trig=-1;
if(type == "trig")
trig = node;

View File

@ -1369,7 +1369,7 @@ bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
Line2d l2 (sp1, sp2);
double lam1, lam2;
int err = CrossPointBarycentric (l1, l2, lam1, lam2);
int err = CrossPointBarycentric (l1, l2, lam1, lam2, eps);
bool in1 = (lam1 > eps) && (lam1 < 1-eps);
bool on1 = (lam1 > -eps) && (lam1 < 1 + eps);
bool in2 = (lam2 > eps) && (lam2 < 1-eps);

View File

@ -266,7 +266,7 @@ namespace netgen
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
// cout << "don't have a mesh to visualize" << endl;
VisualScene::DrawScene();
@ -865,10 +865,10 @@ namespace netgen
for (int j = 1; j <= idpts.GetBagSize(i); j++)
{
INDEX_3 pts;
int dummy, val;
int dummy; // , val;
idpts.GetData (i, j, pts, dummy);
val = pts[2];
// val = pts[2];
const Point3d & p1 = mesh->Point(pts.I1());
const Point3d & p2 = mesh->Point(pts.I2());
@ -895,7 +895,7 @@ namespace netgen
vstimestamp = meshtimestamp;
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
PrintMessage (3, "vsmesh::buildscene: don't have a mesh to visualize");
VisualScene::BuildScene (zoomall);

View File

@ -641,7 +641,7 @@ namespace netgen
// delete lock;
// mem_lock.UnLock();
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
// cout << "don't have a mesh to visualize" << endl;
VisualScene::DrawScene();
@ -1120,7 +1120,7 @@ namespace netgen
clipplanetimestamp = max2 (vispar.clipping.timestamp, solutiontimestamp);
}
catch (bad_weak_ptr e)
catch (const bad_weak_ptr & e)
{
PrintMessage (3, "vssolution::buildscene: don't have a mesh to visualize");
VisualScene::BuildScene (zoomall);

View File

@ -1,72 +0,0 @@
--blank-before-sizeof
--blank-lines-after-declarations
--blank-lines-after-procedures
--blank-lines-before-block-comments
--braces-after-struct-decl-line
--braces-on-if-line
--break-before-boolean-operator
--case-brace-indentation0
--case-indentation2
--comment-line-length80
--continuation-indentation8
--cuddle-do-while
--cuddle-else
--declaration-indentation8
--dont-line-up-parentheses
--format-all-comments
--format-first-column-comments
--indent-level4
--leave-optional-blank-lines
--line-length80
--no-space-after-function-call-names
--no-space-after-parentheses
--no-tabs
--parameter-indentation8
--preprocessor-indentation2
--procnames-start-lines
--space-after-cast
--space-after-for
--space-after-if
--space-after-while
--space-special-semicolon
--start-left-side-of-comments
--struct-brace-indentation0
--tab-size8
-T AGLContext
-T CALLBACK
-T ClientData
-T Colormap
-T Display
-T GLXContext
-T GLbitfield
-T GLboolean
-T GLenum
-T GLfloat
-T GLint
-T GLuint
-T HDC
-T HGLRC
-T HWND
-T LPARAM
-T PIXELFORMATDESCRIPTOR
-T Tcl_Command
-T Tcl_Interp
-T TkClassCreateProc
-T TkClassGeometryProc
-T TkClassModalProc
-T TkClassProcs
-T TkWinColormap
-T Tk_ConfigSpec
-T Tk_Cursor
-T Tk_Window
-T Togl_Callback
-T Togl_CmdProc
-T UINT
-T WPARAM
-T WinFont
-T Window
-T XColor
-T XEvent
-T XVisualInfo
-T TOGL_EXTERN
-T Togl

View File

@ -1,19 +0,0 @@
add_definitions("-DPACKAGE_NAME=\"Togl\" -DPACKAGE_TARNAME=\"togl\" -DPACKAGE_VERSION=\"1.7\" -DPACKAGE_STRING=\"Togl\ 1.7\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_PARAM_H=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DTCL_THREADS=1 -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_IS_LONG=1 -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1")
# include_directories("/usr/include/tcl8.5" "/usr/include/tcl8.5/tk-private/generic" "/usr/include/tcl8.5/tk-private/unix")
# SET(CMAKE_CXX_FLAGS "-O2 -fomit-frame-pointer -Wall -Wno-implicit-int -fPIC -c")
include_directories("${TCL_INCLUDE_PATH}/tk-private/generic" "${TCL_INCLUDE_PATH}/tk-private/unix")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fomit-frame-pointer -Wall -Wno-implicit-int")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fomit-frame-pointer -Wall -Wno-implicit-int")
add_library(togl togl.c)
target_link_libraries(togl ${OPENGL_LIBRARIES})
set_target_properties(togl PROPERTIES POSITION_INDEPENDENT_CODE ON )
#
# gcc -DPACKAGE_NAME=\"Togl\" -DPACKAGE_TARNAME=\"togl\" -DPACKAGE_VERSION=\"1.7\" -DPACKAGE_STRING=\"Togl\ 1.7\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIMITS_H=1 -DHAVE_SYS_PARAM_H=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DTCL_THREADS=1 -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_IS_LONG=1 -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1
# -I"/usr/include/tcl8.6" -I"/usr/include/tcl8.6/tk-private/generic" -I"/usr/include/tcl8.6/tk-private/unix"
# -O2 -fomit-frame-pointer -Wall -Wno-implicit-int -fPIC -c `echo togl.c` -o togl.o
# rm -f libTogl1.7.so
# gcc -pipe -shared -o libTogl1.7.so togl.o -lX11 -lGL -lXmu -L/usr/lib/x86_64-linux-gnu -ltclstub8.6 -L/usr/lib/x86_64-linux-gnu -ltkstub8.6
# : libTogl1.7.so

View File

@ -1,27 +0,0 @@
This software is copyrighted by Brian Paul (brian@mesa3d.org)
and Benjamin Bederson (bederson@cs.umd.edu). The following
terms apply to all files associated with the software unless explicitly
disclaimed in individual files.
The authors hereby grant permission to use, copy, modify, distribute,
and license this software and its documentation for any purpose, provided
that existing copyright notices are retained in all copies and that this
notice is included verbatim in any distributions. No written agreement,
license, or royalty fee is required for any of the authorized uses.
Modifications to this software may be copyrighted by their authors
and need not follow the licensing terms described here, provided that
the new terms are clearly indicated on the first page of each file where
they apply.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
MODIFICATIONS.

View File

@ -1,21 +0,0 @@
This version of Togl is entirely free from
dependencies on Tcl/Tk's internal functions. It uses the public stubs
interface, witch means that the same binary works with any stubs-aware
wish (i.e. version >= 8.1)
It has been tested on Windows NT/2000 and Linux for several Tcl/Tk versions up
to 8.4a3. I haven't been able to test the Mac port, it probably needs mending
but I can't see why it shouldn't work in principle.
Implementation wise, what differs from Togl 1.5 is that Togl_MakeWindowExist()
is replaced by Togl_CreateWindow(), a function that gets registered in Tk as a callback for window creation. In Tk/Tk 8.4a3, there is a new public API call
Tk_SetClassProcs() to register this callback, but for earlier versions of Tk
one needs to do this using some pointer magic.
There is a run-time check to determine which method to use, hence the
same binary runs on all versions of Wish from 8.1 and up. For this to
work you need to compile against the headers from Tcl/Tk 8.4a3 or later, or
the binary will only work for Tcl/Tk 8.1-8.4a2.
The tk8.4a3 public headers (tk8.4a3.h + tkDecls.h) are included for
convenience, and they are used if the flag -DUSE_LOCAL_TK_H is specified.
Jonas Beskow, December 2001

View File

@ -1,20 +0,0 @@
In no particular order:
-----------------------
stubify C API.
replace EPS support with TK photo image support
Add command arguments for create, destroy, etc. so there would be a
-createcommand option to the togl command (etc.) (and phase out
Togl_*Func from the C API)
multisampling support (can be worked-around by passing in a pixelformat)
add vertical sync control
update documentation
- update build instructions
- update stereo documentation
- separate Tcl API from C API
- say togl hides window system dependent (glX/wgl/agl) calls

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +0,0 @@
#
# Include the TEA standard macro set
#
builtin(include,tclconfig/tcl.m4)
#
# Add here whatever m4 macros you want to define for your package
#

Binary file not shown.

View File

@ -1,222 +0,0 @@
#!/bin/bash -norc
dnl This file is an input file used by the GNU "autoconf" program to
dnl generate the file "configure", which is run during Tcl installation
dnl to configure the system for the local environment.
#
# RCS: @(#) $Id: configure.in,v 1.6 2006/01/06 00:09:00 gregcouch Exp $
#-----------------------------------------------------------------------
# Sample configure.in for Tcl Extensions. The only places you should
# need to modify this file are marked by the string __CHANGE__
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# __CHANGE__
# Set your package name and version numbers here.
#
# This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION
# set as provided. These will also be added as -D defs in your Makefile
# so you can encode the package version directly into the source files.
#-----------------------------------------------------------------------
AC_INIT([Togl], [1.7])
#--------------------------------------------------------------------
# Call TEA_INIT as the first TEA_ macro to set up initial vars.
# This will define a ${TEA_PLATFORM} variable == "unix" or "windows"
# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE.
#--------------------------------------------------------------------
TEA_INIT([3.4])
AC_CONFIG_AUX_DIR(tclconfig)
#--------------------------------------------------------------------
# Load the tclConfig.sh file
#--------------------------------------------------------------------
TEA_PATH_TCLCONFIG
TEA_LOAD_TCLCONFIG
#--------------------------------------------------------------------
# Load the tkConfig.sh file if necessary (Tk extension)
#--------------------------------------------------------------------
TEA_PATH_TKCONFIG
TEA_LOAD_TKCONFIG
#-----------------------------------------------------------------------
# Handle the --prefix=... option by defaulting to what Tcl gave.
# Must be called after TEA_LOAD_TCLCONFIG and before TEA_SETUP_COMPILER.
#-----------------------------------------------------------------------
TEA_PREFIX
#-----------------------------------------------------------------------
# Standard compiler checks.
# This sets up CC by using the CC env var, or looks for gcc otherwise.
# This also calls AC_PROG_CC, AC_PROG_INSTALL and a few others to create
# the basic setup necessary to compile executables.
#-----------------------------------------------------------------------
TEA_SETUP_COMPILER
#-----------------------------------------------------------------------
# __CHANGE__
# Specify the C source files to compile in TEA_ADD_SOURCES,
# public headers that need to be installed in TEA_ADD_HEADERS,
# stub library C source files to compile in TEA_ADD_STUB_SOURCES,
# and runtime Tcl library files in TEA_ADD_TCL_SOURCES.
# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS
# and PKG_TCL_SOURCES.
#-----------------------------------------------------------------------
TEA_ADD_SOURCES([togl.c])
# togl_ws.h is added in Makefile.in because it is generated
TEA_ADD_HEADERS([togl.h])
TEA_ADD_INCLUDES([])
TEA_ADD_LIBS([])
TEA_ADD_CFLAGS([])
TEA_ADD_STUB_SOURCES([])
TEA_ADD_TCL_SOURCES([])
#--------------------------------------------------------------------
# __CHANGE__
# A few miscellaneous platform-specific items:
#
# Define a special symbol for Windows (BUILD_sample in this case) so
# that we create the export library with the dll.
#
# Windows creates a few extra files that need to be cleaned up.
# You can add more files to clean if your extension creates any extra
# files.
#
# TEA_ADD_* any platform specific compiler/build info here.
#--------------------------------------------------------------------
if test "${TEA_PLATFORM}" = "windows" ; then
AC_DEFINE(BUILD_togl, 1, [Build windows export dll])
CLEANFILES="pkgIndex.tcl togl_ws.h *.lib *.dll *.exp *.ilk *.pdb vc*.pch"
#TEA_ADD_SOURCES([win/winFile.c])
#TEA_ADD_INCLUDES([-I\"$(${CYGPATH} ${srcdir}/win)\"])
else
CLEANFILES="pkgIndex.tcl togl_ws.h so_locations"
#TEA_ADD_SOURCES([unix/unixFile.c])
#TEA_ADD_LIBS([-lsuperfly])
fi
AC_SUBST(CLEANFILES)
#--------------------------------------------------------------------
# __CHANGE__
# Choose which headers you need. Extension authors should try very
# hard to only rely on the Tcl public header files. Internal headers
# contain private data structures and are subject to change without
# notice.
# This MUST be called after TEA_LOAD_TCLCONFIG / TEA_LOAD_TKCONFIG
#--------------------------------------------------------------------
TEA_PUBLIC_TCL_HEADERS
#TEA_PRIVATE_TCL_HEADERS
#TEA_PUBLIC_TK_HEADERS
TEA_PRIVATE_TK_HEADERS
TEA_PATH_X
#--------------------------------------------------------------------
# __CHANGE__
# Choose OpenGL platform
#--------------------------------------------------------------------
case "${TEA_WINDOWINGSYSTEM}" in
aqua)
AC_SUBST(TOGL_WINDOWINGSYSTEM,TOGL_AGL)
TEA_ADD_LIBS([-framework AGL -framework OpenGL -framework ApplicationServices])
# libGLU is implicit in OpenGL framework
LIBGLU=
;;
x11)
AC_SUBST(TOGL_WINDOWINGSYSTEM,TOGL_X11)
TEA_ADD_LIBS([-lGL -lXmu])
LIBGLU=-lGLU
;;
win32)
AC_SUBST(TOGL_WINDOWINGSYSTEM,TOGL_WGL)
TEA_ADD_LIBS([opengl32.lib user32.lib gdi32.lib])
if test "$GCC" = "yes" ; then
LIBGLU=-lglu32
else
LIBGLU=glu32.lib
fi
;;
*)
AC_MSG_ERROR([Unsupported windowing system: ${TEA_WINDOWINGSYSTEM}])
;;
esac
AC_SUBST(LIBGLU)
#--------------------------------------------------------------------
# Check whether --enable-threads or --disable-threads was given.
# This auto-enables if Tcl was compiled threaded.
#--------------------------------------------------------------------
TEA_ENABLE_THREADS
#--------------------------------------------------------------------
# The statement below defines a collection of symbols related to
# building as a shared library instead of a static library.
#--------------------------------------------------------------------
TEA_ENABLE_SHARED
#--------------------------------------------------------------------
# This macro figures out what flags to use with the compiler/linker
# when building shared/static debug/optimized objects. This information
# can be taken from the tclConfig.sh file, but this figures it all out.
#--------------------------------------------------------------------
TEA_CONFIG_CFLAGS
# should be part of TEA_CONFIG_CFLAGS, but more visible modification here
AC_SUBST(SHLIB_SUFFIX)
#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols option.
#--------------------------------------------------------------------
TEA_ENABLE_SYMBOLS
#--------------------------------------------------------------------
# Everyone should be linking against the Tcl stub library. If you
# can't for some reason, remove this definition. If you aren't using
# stubs, you also need to modify the SHLIB_LD_LIBS setting below to
# link against the non-stubbed Tcl library. Add Tk too if necessary.
#--------------------------------------------------------------------
AC_DEFINE(USE_TCL_STUBS, 1, [Use Tcl stubs])
AC_DEFINE(USE_TK_STUBS, 1, [Use Tk stubs])
#--------------------------------------------------------------------
# This macro generates a line to use when building a library. It
# depends on values set by the TEA_ENABLE_SHARED, TEA_ENABLE_SYMBOLS,
# and TEA_LOAD_TCLCONFIG macros above.
#--------------------------------------------------------------------
TEA_MAKE_LIB
#--------------------------------------------------------------------
# Determine the name of the tclsh and/or wish executables in the
# Tcl and Tk build directories or the location they were installed
# into. These paths are used to support running test cases only,
# the Makefile should not be making use of these paths to generate
# a pkgIndex.tcl file or anything else at extension build time.
#--------------------------------------------------------------------
TEA_PROG_TCLSH
TEA_PROG_WISH
#--------------------------------------------------------------------
# Finally, substitute all of the various values into the Makefile.
# You may alternatively have a special pkgIndex.tcl.in or other files
# which require substituting th AC variables in. Include these here.
#--------------------------------------------------------------------
AC_OUTPUT([Makefile pkgIndex.tcl togl_ws.h])

View File

@ -1,280 +0,0 @@
/* $Id: double.c,v 1.14 2005/04/23 07:49:13 gregcouch Exp $ */
/*
* Togl - a Tk OpenGL widget
* Copyright (C) 1996-1997 Brian Paul and Ben Bederson
* See the LICENSE file for copyright details.
*/
#include "togl.h"
#include <stdlib.h>
#include <string.h>
/*
* The following variable is a special hack that is needed in order for
* Sun shared libraries to be used for Tcl.
*/
#ifdef SUN
extern int matherr();
int *tclDummyMathPtr = (int *) matherr;
#endif
static GLuint FontBase;
static float xAngle = 0.0, yAngle = 0.0, zAngle = 0.0;
static GLfloat CornerX, CornerY, CornerZ; /* where to print strings */
/*
* Togl widget create callback. This is called by Tcl/Tk when the widget has
* been realized. Here's where one may do some one-time context setup or
* initializations.
*/
void
create_cb(Togl *togl)
{
FontBase = Togl_LoadBitmapFont(togl, TOGL_BITMAP_8_BY_13);
if (!FontBase) {
printf("Couldn't load font!\n");
exit(1);
}
}
/*
* Togl widget reshape callback. This is called by Tcl/Tk when the widget
* has been resized. Typically, we call glViewport and perhaps setup the
* projection matrix.
*/
void
reshape_cb(Togl *togl)
{
int width = Togl_Width(togl);
int height = Togl_Height(togl);
float aspect = (float) width / (float) height;
glViewport(0, 0, width, height);
/* Set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-aspect, aspect, -1.0, 1.0, 1.0, 10.0);
CornerX = -aspect;
CornerY = -1.0;
CornerZ = -1.1;
/* Change back to model view transform for rendering */
glMatrixMode(GL_MODELVIEW);
}
static void
print_string(const char *s)
{
glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);
}
/*
* Togl widget display callback. This is called by Tcl/Tk when the widget's
* contents have to be redrawn. Typically, we clear the color and depth
* buffers, render our objects, then swap the front/back color buffers.
*/
void
display_cb(Togl *togl)
{
static GLuint cubeList = 0;
const char *ident;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); /* Reset modelview matrix to the identity
* matrix */
glTranslatef(0.0, 0.0, -3.0); /* Move the camera back three units */
glRotatef(xAngle, 1.0, 0.0, 0.0); /* Rotate by X, Y, and Z angles */
glRotatef(yAngle, 0.0, 1.0, 0.0);
glRotatef(zAngle, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
if (!cubeList) {
cubeList = glGenLists(1);
glNewList(cubeList, GL_COMPILE);
/* Front face */
glBegin(GL_QUADS);
glColor3f(0.0, 0.7, 0.1); /* Green */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(-1.0, -1.0, 1.0);
/* Back face */
glColor3f(0.9, 1.0, 0.0); /* Yellow */
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
/* Top side face */
glColor3f(0.2, 0.2, 1.0); /* Blue */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);
/* Bottom side face */
glColor3f(0.7, 0.0, 0.1); /* Red */
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glEnd();
glEndList();
}
glCallList(cubeList);
glDisable(GL_DEPTH_TEST);
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glRasterPos3f(CornerX, CornerY, CornerZ);
glListBase(FontBase);
ident = Togl_Ident(togl);
if (strcmp(ident, "Single") == 0) {
print_string("Single buffered");
} else {
print_string("Double buffered");
}
Togl_SwapBuffers(togl);
}
int
setXrot_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName setXrot ?angle?\"",
TCL_STATIC);
return TCL_ERROR;
}
xAngle = atof(argv[2]);
/* printf( "before %f ", xAngle ); */
if (xAngle < 0.0) {
xAngle += 360.0;
} else if (xAngle > 360.0) {
xAngle -= 360.0;
}
/* printf( "after %f \n", xAngle ); */
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
int
setYrot_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName setYrot ?angle?\"",
TCL_STATIC);
return TCL_ERROR;
}
yAngle = atof(argv[2]);
if (yAngle < 0.0) {
yAngle += 360.0;
} else if (yAngle > 360.0) {
yAngle -= 360.0;
}
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
int
getXrot_cb(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
sprintf(interp->result, "%d", (int) xAngle);
return TCL_OK;
}
int
getYrot_cb(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
sprintf(interp->result, "%d", (int) yAngle);
return TCL_OK;
}
/*
* Called by Tk_Main() to let me initialize the modules (Togl) I will need.
*/
TOGL_EXTERN int
Double_Init(Tcl_Interp *interp)
{
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
if (Tk_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
if (Togl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
#ifdef macintosh
Togl_MacSetupMainInterp(interp);
#endif
/*
* Specify the C callback functions for widget creation, display,
* and reshape.
*/
Togl_CreateFunc(create_cb);
Togl_DisplayFunc(display_cb);
Togl_ReshapeFunc(reshape_cb);
/*
* Make a new Togl widget command so the Tcl code can set a C variable.
*/
Togl_CreateCommand("setXrot", setXrot_cb);
Togl_CreateCommand("setYrot", setYrot_cb);
/*
* Call Tcl_CreateCommand for application-specific commands, if
* they weren't already created by the init procedures called above.
*/
Tcl_CreateCommand(interp, "getXrot", (Tcl_CmdProc *) getXrot_cb,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(interp, "getYrot", (Tcl_CmdProc *) getYrot_cb,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}

View File

@ -1,103 +0,0 @@
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
# $Id: double.tcl,v 1.5 2001/12/20 13:59:31 beskow Exp $
# Togl - a Tk OpenGL widget
# Copyright (C) 1996 Brian Paul and Ben Bederson
# See the LICENSE file for copyright details.
# $Log: double.tcl,v $
# Revision 1.5 2001/12/20 13:59:31 beskow
# Improved error-handling in togl.c in case of window creation failure
# Added pkgIndex target to makefile
# Updated documentation to reflect stubs-interface (Togl.html + new README.stubs)
# Added tk8.4a3 headers
# Removed obsolete Tk internal headers
#
# Revision 1.4 2001/01/29 18:11:53 brianp
# Jonas Beskow's changes to use Tcl/Tk stub interface
#
# Revision 1.3 1998/03/12 03:52:31 brianp
# now sharing display lists between the widgets
#
# Revision 1.2 1996/10/23 23:31:56 brianp
# added -ident options to togl calls
#
# Revision 1.1 1996/10/23 23:17:22 brianp
# Initial revision
#
# An Tk/OpenGL widget demo with two windows, one single buffered and the
# other double buffered.
load [file dirname [info script]]/double[info sharedlibextension]
proc setup {} {
wm title . "Single vs Double Buffering"
frame .f1
# create first Togl widget
togl .f1.o1 -width 200 -height 200 -rgba true -double false -depth true -ident Single
# create second Togl widget, share display lists with first widget
togl .f1.o2 -width 200 -height 200 -rgba true -double true -depth true -ident Double -sharelist Single
scale .sx -label {X Axis} -from 0 -to 360 -command {setAngle x} -orient horizontal
scale .sy -label {Y Axis} -from 0 -to 360 -command {setAngle y} -orient horizontal
button .btn -text Quit -command exit
bind .f1.o1 <B1-Motion> {
motion_event [lindex [%W config -width] 4] \
[lindex [%W config -height] 4] \
%x %y
}
bind .f1.o2 <B1-Motion> {
motion_event [lindex [%W config -width] 4] \
[lindex [%W config -height] 4] \
%x %y
}
pack .f1.o1 .f1.o2 -side left -padx 3 -pady 3 -fill both -expand t
pack .f1 -fill both -expand t
pack .sx -fill x
pack .sy -fill x
pack .btn -fill x
}
# This is called when mouse button 1 is pressed and moved in either of
# the OpenGL windows.
proc motion_event { width height x y } {
.f1.o1 setXrot [expr 360.0 * $y / $height]
.f1.o2 setXrot [expr 360.0 * $y / $height]
.f1.o1 setYrot [expr 360.0 * ($width - $x) / $width]
.f1.o2 setYrot [expr 360.0 * ($width - $x) / $width]
# .sx set [expr 360.0 * $y / $height]
# .sy set [expr 360.0 * ($width - $x) / $width]
.sx set [getXrot]
.sy set [getYrot]
}
# This is called when a slider is changed.
proc setAngle {axis value} {
global xAngle yAngle zAngle
switch -exact $axis {
x {.f1.o1 setXrot $value
.f1.o2 setXrot $value}
y {.f1.o1 setYrot $value
.f1.o2 setYrot $value}
}
}
# Execution starts here!
setup

View File

@ -1,402 +0,0 @@
/* gears.c */
/*
* 3-D gear wheels. This program is in the public domain.
*
* Brian Paul
*
*
* Modified to work under Togl as a widget for TK 1997
*
* Philip Quaife
*
*/
#include "togl.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#ifndef M_PI
# define M_PI 3.14159265
#endif
struct WHIRLYGIZMO
{
GLint Gear1, Gear2, Gear3;
GLfloat Rotx, Roty, Rotz;
GLfloat Angle;
int Height, Width;
};
/*
* Draw a gear wheel. You'll probably want to call this function when
* building a display list since we do a lot of trig here.
*
* Input: inner_radius - radius of hole at center
* outer_radius - radius at center of teeth
* width - width of gear
* teeth - number of teeth
* tooth_depth - depth of tooth
*/
static void
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
GLint teeth, GLfloat tooth_depth)
{
GLint i;
GLfloat r0, r1, r2;
GLfloat angle, da;
GLfloat u, v, len;
r0 = inner_radius;
r1 = outer_radius - tooth_depth / 2.0;
r2 = outer_radius + tooth_depth / 2.0;
da = 2.0 * M_PI / teeth / 4.0;
glShadeModel(GL_FLAT);
glNormal3f(0.0, 0.0, 1.0);
/* draw front face */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
width * 0.5);
}
glEnd();
/* draw front sides of teeth */
glBegin(GL_QUADS);
da = 2.0 * M_PI / teeth / 4.0;
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
width * 0.5);
}
glEnd();
glNormal3f(0.0, 0.0, -1.0);
/* draw back face */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
-width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
}
glEnd();
/* draw back sides of teeth */
glBegin(GL_QUADS);
da = 2.0 * M_PI / teeth / 4.0;
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
-width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
-width * 0.5);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
}
glEnd();
/* draw outward faces of teeth */
glBegin(GL_QUAD_STRIP);
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
u = r2 * cos(angle + da) - r1 * cos(angle);
v = r2 * sin(angle + da) - r1 * sin(angle);
len = sqrt(u * u + v * v);
u /= len;
v /= len;
glNormal3f(v, -u, 0.0);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
glNormal3f(cos(angle), sin(angle), 0.0);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
-width * 0.5);
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
glNormal3f(v, -u, 0.0);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
-width * 0.5);
glNormal3f(cos(angle), sin(angle), 0.0);
}
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
glEnd();
glShadeModel(GL_SMOOTH);
/* draw inside radius cylinder */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glNormal3f(-cos(angle), -sin(angle), 0.0);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
}
glEnd();
}
/*
* static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0; static GLint
* gear1, gear2, gear3; static GLfloat angle = 0.0; */
static GLuint limit;
static GLuint count = 1;
static GLubyte polycolor[4] = { 255, 255, 255, 255 };
static void
draw(Togl *togl)
{
struct WHIRLYGIZMO *Wg;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Wg = Togl_GetClientData(togl);
glDisable(GL_TEXTURE_2D);
glPushMatrix();
glRotatef(Wg->Rotx, 1.0, 0.0, 0.0);
glRotatef(Wg->Roty, 0.0, 1.0, 0.0);
glRotatef(Wg->Rotz, 0.0, 0.0, 1.0);
glPushMatrix();
glTranslatef(-3.0, -2.0, 0.0);
glRotatef(Wg->Angle, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glCallList(Wg->Gear1);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
glPushMatrix();
glTranslatef(3.1, -2.0, 0.0);
glRotatef(-2.0 * Wg->Angle - 9.0, 0.0, 0.0, 1.0);
glCallList(Wg->Gear2);
glPopMatrix();
glPushMatrix();
glTranslatef(-3.1, 4.2, 0.0);
glRotatef(-2.0 * Wg->Angle - 25.0, 0.0, 0.0, 1.0);
glCallList(Wg->Gear3);
glPopMatrix();
glPopMatrix();
Togl_SwapBuffers(togl);
}
static void
zap(Togl *togl)
{
struct WHIRLYGIZMO *Wg;
Wg = Togl_GetClientData(togl);
free(Wg);
}
static void
idle(Togl *togl)
{
struct WHIRLYGIZMO *Wg;
Wg = Togl_GetClientData(togl);
Wg->Angle += 2.0;
Togl_PostRedisplay(togl);
}
/* change view angle, exit upon ESC */
/*
* static GLenum key(int k, GLenum mask) { switch (k) { case TK_UP: view_rotx
* += 5.0; return GL_TRUE; case TK_DOWN: view_rotx -= 5.0; return GL_TRUE; case
* TK_LEFT: view_roty += 5.0; return GL_TRUE; case TK_RIGHT: view_roty -= 5.0;
* return GL_TRUE; case TK_z: view_rotz += 5.0; return GL_TRUE; case TK_Z:
* view_rotz -= 5.0; return GL_TRUE; } return GL_FALSE; } */
/* new window size or exposure */
static void
reshape(Togl *togl)
{
int width, height;
width = Togl_Width(togl);
height = Togl_Height(togl);
glViewport(0, 0, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width > height) {
GLfloat w = (GLfloat) width / (GLfloat) height;
glFrustum(-w, w, -1.0, 1.0, 5.0, 60.0);
} else {
GLfloat h = (GLfloat) height / (GLfloat) width;
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -40.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
static void
init(Togl *togl)
{
struct WHIRLYGIZMO *Wg;
static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
/* make the gears */
Wg = malloc(sizeof (*Wg));
if (!Wg) {
Tcl_SetResult(Togl_Interp(togl),
"\"Cannot allocate client data for widget\"", TCL_STATIC);
}
Wg->Gear1 = glGenLists(1);
glNewList(Wg->Gear1, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
gear(1.0, 4.0, 1.0, 20, 0.7);
glEndList();
Wg->Gear2 = glGenLists(1);
glNewList(Wg->Gear2, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
gear(0.5, 2.0, 2.0, 10, 0.7);
glEndList();
Wg->Gear3 = glGenLists(1);
glNewList(Wg->Gear3, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
gear(1.3, 2.0, 0.5, 10, 0.7);
glEndList();
glEnable(GL_NORMALIZE);
Wg->Height = Togl_Height(togl);
Wg->Width = Togl_Width(togl);
Wg->Angle = 0.0;
Wg->Rotx = 0.0;
Wg->Roty = 0.0;
Wg->Rotz = 0.0;
Togl_SetClientData(togl, (ClientData) Wg);
}
int
position(Togl *togl, int argc, CONST84 char *argv[])
{
struct WHIRLYGIZMO *Wg;
Tcl_Interp *interp = Togl_Interp(togl);
char Result[100];
Wg = Togl_GetClientData(togl);
/* error checking */
if (argc != 2) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName \"", TCL_STATIC);
return TCL_ERROR;
}
/* Let result string equal value */
sprintf(Result, "%g %g", Wg->Roty, Wg->Rotx);
Tcl_SetResult(interp, Result, TCL_VOLATILE);
return TCL_OK;
}
int
rotate(Togl *togl, int argc, CONST84 char *argv[])
{
struct WHIRLYGIZMO *Wg;
Tcl_Interp *interp = Togl_Interp(togl);
Wg = Togl_GetClientData(togl);
/* error checking */
if (argc != 4) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName xrot yrot\"", TCL_STATIC);
return TCL_ERROR;
}
Wg->Roty = atof(argv[2]);
Wg->Rotx = atof(argv[3]);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
TOGL_EXTERN int
Gears_Init(Tcl_Interp *interp)
{
/*
* Initialize Tcl, Tk, and the Togl widget module.
*/
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
if (Tk_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
if (Togl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
/*
* Specify the C callback functions for widget creation, display,
* and reshape.
*/
Togl_CreateFunc(init);
Togl_DestroyFunc(zap);
Togl_DisplayFunc(draw);
Togl_ReshapeFunc(reshape);
Togl_TimerFunc(idle);
Togl_CreateCommand("rotate", rotate);
Togl_CreateCommand("position", position);
return TCL_OK;
}

View File

@ -1,76 +0,0 @@
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
# Togl - a Tk OpenGL widget
# Copyright (C) 1996-1997 Brian Paul and Ben Bederson
# See the LICENSE file for copyright details.
#
# Test Togl using GL Gears Demo
#
# Copyright (C) 1997 Philip Quaife
#
load [file dirname [info script]]/gears[info sharedlibextension]
proc setup {} {
global startx starty xangle0 yangle0 xangle yangle RotCnt
global vTime
set RotCnt 1
set xangle 0.0
set yangle 0.0
set vTime 100
wm title . "Rotating Gear Widget Test"
label .t -text "Click and drag to rotate image"
pack .t -side top -padx 2 -pady 10
frame .f
pack .f -side top
button .f.n1 -text " Add " -command AutoRot
button .f.r1 -text "Remove" -command DelRot
button .f.b1 -text " Quit " -command exit
entry .f.t -width 4 -textvariable vTime
pack .f.n1 .f.t .f.r1 .f.b1 -side left -anchor w -padx 5
newRot .w0 10
}
proc AutoRot {} {
global RotCnt vTime
newRot .w$RotCnt $vTime
set RotCnt [expr $RotCnt + 1]
}
proc DelRot {} {
global RotCnt vTime
if { $RotCnt != 0 } {
set RotCnt [expr $RotCnt - 1]
destroy .w$RotCnt
}
}
proc newRot {win {tick 100} } {
togl $win -width 200 -height 200 -rgba true -double true -depth true -privatecmap false -time $tick
bind $win <ButtonPress-1> {RotStart %x %y %W}
bind $win <B1-Motion> {RotMove %x %y %W}
pack $win -expand true -fill both
}
proc RotStart {x y W } {
global startx starty xangle0 yangle0 xangle yangle
set startx $x
set starty $y
set vPos [$W position]
set xangle0 [lindex $vPos 0]
set yangle0 [lindex $vPos 1]
}
proc RotMove {x y W} {
global startx starty xangle0 yangle0 xangle yangle
set xangle [expr $xangle0 + ($x - $startx) ]
set yangle [expr $yangle0 + ($y - $starty) ]
$W rotate $xangle $yangle
}
setup

View File

@ -1,249 +0,0 @@
/*
* SGI rgb file reader borrowed from gltk library
*/
#include "togl.h" /* added by GG to include windows.h */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "image.h"
#ifndef SEEK_SET
# define SEEK_SET 0
#endif
static void
tkQuit(void)
{
exit(0);
}
/******************************************************************************/
typedef struct _rawImageRec
{
unsigned short imagic;
unsigned short type;
unsigned short dim;
unsigned short sizeX, sizeY, sizeZ;
unsigned long min, max;
unsigned long wasteBytes;
char name[80];
unsigned long colorMap;
FILE *file;
unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA;
unsigned long rleEnd;
GLuint *rowStart;
GLint *rowSize;
} rawImageRec;
/******************************************************************************/
static void
ConvertShort(unsigned short *array, long length)
{
unsigned long b1, b2;
unsigned char *ptr;
ptr = (unsigned char *) array;
while (length--) {
b1 = *ptr++;
b2 = *ptr++;
*array++ = (b1 << 8) | (b2);
}
}
static void
ConvertLong(GLuint *array, long length)
{
unsigned long b1, b2, b3, b4;
unsigned char *ptr;
ptr = (unsigned char *) array;
while (length--) {
b1 = *ptr++;
b2 = *ptr++;
b3 = *ptr++;
b4 = *ptr++;
*array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4);
}
}
static rawImageRec *
RawImageOpen(char *fileName)
{
union
{
int testWord;
char testByte[4];
} endianTest;
rawImageRec *raw;
GLenum swapFlag;
int x;
endianTest.testWord = 1;
if (endianTest.testByte[0] == 1) {
swapFlag = GL_TRUE;
} else {
swapFlag = GL_FALSE;
}
raw = (rawImageRec *) malloc(sizeof (rawImageRec));
if (raw == NULL) {
fprintf(stderr, "Out of memory!\n");
tkQuit();
}
if ((raw->file = fopen(fileName, "rb")) == NULL) {
perror(fileName);
tkQuit();
}
fread(raw, 1, 12, raw->file);
if (swapFlag) {
ConvertShort(&raw->imagic, 6);
}
raw->tmp = (unsigned char *) malloc(raw->sizeX * 256);
raw->tmpR = (unsigned char *) malloc(raw->sizeX * 256);
raw->tmpG = (unsigned char *) malloc(raw->sizeX * 256);
raw->tmpB = (unsigned char *) malloc(raw->sizeX * 256);
raw->tmpA = (unsigned char *) malloc(raw->sizeX * 256);
if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL ||
raw->tmpB == NULL || raw->tmpA == NULL) {
fprintf(stderr, "Out of memory!\n");
tkQuit();
}
if ((raw->type & 0xFF00) == 0x0100) {
x = raw->sizeY * raw->sizeZ * sizeof (GLuint);
raw->rowStart = (GLuint *) malloc(x);
raw->rowSize = (GLint *) malloc(x);
if (raw->rowStart == NULL || raw->rowSize == NULL) {
fprintf(stderr, "Out of memory!\n");
tkQuit();
}
raw->rleEnd = 512 + (2 * x);
fseek(raw->file, 512, SEEK_SET);
fread(raw->rowStart, 1, x, raw->file);
fread(raw->rowSize, 1, x, raw->file);
if (swapFlag) {
ConvertLong(raw->rowStart, x / sizeof (GLuint));
ConvertLong((GLuint *) raw->rowSize, x / sizeof (GLint));
}
}
return raw;
}
static void
RawImageClose(rawImageRec * raw)
{
fclose(raw->file);
free(raw->tmp);
free(raw->tmpR);
free(raw->tmpG);
free(raw->tmpB);
free(raw->tmpA);
free(raw);
}
static void
RawImageGetRow(rawImageRec * raw, unsigned char *buf, int y, int z)
{
unsigned char *iPtr, *oPtr, pixel;
int count;
if ((raw->type & 0xFF00) == 0x0100) {
fseek(raw->file, raw->rowStart[y + z * raw->sizeY], SEEK_SET);
fread(raw->tmp, 1, (unsigned int) raw->rowSize[y + z * raw->sizeY],
raw->file);
iPtr = raw->tmp;
oPtr = buf;
while (1) {
pixel = *iPtr++;
count = (int) (pixel & 0x7F);
if (!count) {
return;
}
if (pixel & 0x80) {
while (count--) {
*oPtr++ = *iPtr++;
}
} else {
pixel = *iPtr++;
while (count--) {
*oPtr++ = pixel;
}
}
}
} else {
fseek(raw->file, 512 + (y * raw->sizeX) + (z * raw->sizeX * raw->sizeY),
SEEK_SET);
fread(buf, 1, raw->sizeX, raw->file);
}
}
static void
RawImageGetData(rawImageRec * raw, TK_RGBImageRec * final)
{
unsigned char *ptr;
int i, j;
final->data =
(unsigned char *) malloc((raw->sizeX + 1) * (raw->sizeY + 1) * 4);
if (final->data == NULL) {
fprintf(stderr, "Out of memory!\n");
tkQuit();
}
ptr = final->data;
for (i = 0; i < (int) (raw->sizeY); i++) {
RawImageGetRow(raw, raw->tmpR, i, 0);
RawImageGetRow(raw, raw->tmpG, i, 1);
RawImageGetRow(raw, raw->tmpB, i, 2);
if (raw->sizeZ == 4) {
/* 4 components */
RawImageGetRow(raw, raw->tmpA, i, 3);
for (j = 0; j < (int) (raw->sizeX); j++) {
*ptr++ = *(raw->tmpR + j);
*ptr++ = *(raw->tmpG + j);
*ptr++ = *(raw->tmpB + j);
*ptr++ = *(raw->tmpA + j);
}
} else {
/* 3 components */
for (j = 0; j < (int) (raw->sizeX); j++) {
*ptr++ = *(raw->tmpR + j);
*ptr++ = *(raw->tmpG + j);
*ptr++ = *(raw->tmpB + j);
}
}
}
}
TK_RGBImageRec *
tkRGBImageLoad(char *fileName)
{
rawImageRec *raw;
TK_RGBImageRec *final;
raw = RawImageOpen(fileName);
final = (TK_RGBImageRec *) malloc(sizeof (TK_RGBImageRec));
if (final == NULL) {
fprintf(stderr, "Out of memory!\n");
tkQuit();
}
final->sizeX = raw->sizeX;
final->sizeY = raw->sizeY;
final->sizeZ = raw->sizeZ;
RawImageGetData(raw, final);
RawImageClose(raw);
return final;
}
/******************************************************************************/

View File

@ -1,14 +0,0 @@
/* image.h */
#ifndef IMAGE_H
# define IMAGE_H
typedef struct _TK_RGBImageRec
{
int sizeX, sizeY, sizeZ;
unsigned char *data;
} TK_RGBImageRec;
extern TK_RGBImageRec *tkRGBImageLoad(char *fileName);
#endif

View File

@ -1,184 +0,0 @@
/* $Id: index.c,v 1.10 2005/04/23 07:49:13 gregcouch Exp $ */
/*
* Togl - a Tk OpenGL widget
* Copyright (C) 1996-1997 Brian Paul and Ben Bederson
* See the LICENSE file for copyright details.
*/
/*
* An example Togl program using color-index mode.
*/
#include "togl.h"
#include <stdlib.h>
#include <string.h>
/*
* The following variable is a special hack that is needed in order for
* Sun shared libraries to be used for Tcl.
*/
#ifdef SUN
extern int matherr();
int *tclDummyMathPtr = (int *) matherr;
#endif
/* Our color indexes: */
static unsigned long black, red, green, blue;
/* Rotation angle */
static float Angle = 0.0;
/*
* Togl widget create callback. This is called by Tcl/Tk when the widget has
* been realized. Here's where one may do some one-time context setup or
* initializations.
*/
void
create_cb(Togl *togl)
{
/* allocate color indexes */
black = Togl_AllocColor(togl, 0.0, 0.0, 0.0);
red = Togl_AllocColor(togl, 1.0, 0.0, 0.0);
green = Togl_AllocColor(togl, 0.0, 1.0, 0.0);
blue = Togl_AllocColor(togl, 0.0, 0.0, 1.0);
/* If we were using a private read/write colormap we'd setup our color
* table with something like this: */
/*
* black = 1; Togl_SetColor( togl, black, 0.0, 0.0, 0.0 ); red = 2;
* Togl_SetColor( togl, red, 1.0, 0.0, 0.0 ); green = 3; Togl_SetColor(
* togl, green, 0.0, 1.0, 0.0 ); blue = 4; Togl_SetColor( togl, blue, 0.0,
* 0.0, 1.0 ); */
glShadeModel(GL_FLAT);
glDisable(GL_DITHER);
}
/*
* Togl widget reshape callback. This is called by Tcl/Tk when the widget
* has been resized. Typically, we call glViewport and perhaps setup the
* projection matrix.
*/
void
reshape_cb(Togl *togl)
{
int width = Togl_Width(togl);
int height = Togl_Height(togl);
float aspect = (float) width / (float) height;
glViewport(0, 0, width, height);
/* Set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-aspect, aspect, -1.0, 1.0, -1.0, 1.0);
/* Change back to model view transform for rendering */
glMatrixMode(GL_MODELVIEW);
}
/*
* Togl widget display callback. This is called by Tcl/Tk when the widget's
* contents have to be redrawn. Typically, we clear the color and depth
* buffers, render our objects, then swap the front/back color buffers.
*/
void
display_cb(Togl *togl)
{
glClearIndex(black);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.3, -0.3, 0.0);
glRotatef(Angle, 0.0, 0.0, 1.0);
glIndexi(red);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5, -0.3);
glVertex2f(0.5, -0.3);
glVertex2f(0.0, 0.6);
glEnd();
glPopMatrix();
glPushMatrix();
glRotatef(Angle, 0.0, 0.0, 1.0);
glIndexi(green);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5, -0.3);
glVertex2f(0.5, -0.3);
glVertex2f(0.0, 0.6);
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.3, 0.3, 0.0);
glRotatef(Angle, 0.0, 0.0, 1.0);
glIndexi(blue);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5, -0.3);
glVertex2f(0.5, -0.3);
glVertex2f(0.0, 0.6);
glEnd();
glPopMatrix();
glFlush();
Togl_SwapBuffers(togl);
}
void
timer_cb(Togl *togl)
{
Angle += 5.0;
Togl_PostRedisplay(togl);
}
TOGL_EXTERN int
Index_Init(Tcl_Interp *interp)
{
/*
* Initialize Tcl, Tk, and the Togl widget module.
*/
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
if (Tk_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
if (Togl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
/*
* Specify the C callback functions for widget creation, display,
* and reshape.
*/
Togl_CreateFunc(create_cb);
Togl_DisplayFunc(display_cb);
Togl_ReshapeFunc(reshape_cb);
Togl_TimerFunc(timer_cb);
/*
* Make a new Togl widget command so the Tcl code can set a C variable.
*/
/* NONE */
/*
* Call Tcl_CreateCommand for application-specific commands, if
* they weren't already created by the init procedures called above.
*/
return TCL_OK;
}

View File

@ -1,51 +0,0 @@
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
# $Id: index.tcl,v 1.5 2001/12/20 13:59:31 beskow Exp $
# Togl - a Tk OpenGL widget
# Copyright (C) 1996 Brian Paul and Ben Bederson
# See the LICENSE file for copyright details.
# $Log: index.tcl,v $
# Revision 1.5 2001/12/20 13:59:31 beskow
# Improved error-handling in togl.c in case of window creation failure
# Added pkgIndex target to makefile
# Updated documentation to reflect stubs-interface (Togl.html + new README.stubs)
# Added tk8.4a3 headers
# Removed obsolete Tk internal headers
#
# Revision 1.4 2001/01/29 18:11:53 brianp
# Jonas Beskow's changes to use Tcl/Tk stub interface
#
# Revision 1.3 1998/01/24 14:05:50 brianp
# added quit button (Ben Bederson)
#
# Revision 1.2 1997/04/11 01:37:34 brianp
# added a timer to rotate the triangles
#
# Revision 1.1 1996/10/23 23:18:11 brianp
# Initial revision
#
# A Tk/OpenGL widget demo using color-index mode.
load [file dirname [info script]]/index[info sharedlibextension]
proc setup {} {
wm title . "Color index demo"
togl .win -width 200 -height 200 -rgba false -double true -privatecmap false -time 10
button .btn -text Quit -command exit
pack .win -expand true -fill both
pack .btn -expand true -fill both
}
# Execution starts here!
setup

View File

@ -1,194 +0,0 @@
/* $Id: overlay.c,v 1.7 2005/04/23 07:49:13 gregcouch Exp $ */
/*
* Togl - a Tk OpenGL widget
* Copyright (C) 1996-1997 Brian Paul and Ben Bederson
* See the LICENSE file for copyright details.
*/
/*
* An example Togl program using an overlay.
*/
#include "togl.h"
#include <stdlib.h>
#include <string.h>
/*
* The following variable is a special hack that is needed in order for
* Sun shared libraries to be used for Tcl.
*/
#ifdef SUN
extern int matherr();
int *tclDummyMathPtr = (int *) matherr;
#endif
/* Overlay color indexes: */
static unsigned long Red, Green;
/*
* Togl widget create callback. This is called by Tcl/Tk when the widget has
* been realized. Here's where one may do some one-time context setup or
* initializations.
*/
void
create_cb(Togl *togl)
{
/* allocate overlay color indexes */
Red = Togl_AllocColorOverlay(togl, 1.0, 0.0, 0.0);
Green = Togl_AllocColorOverlay(togl, 0.0, 1.0, 0.0);
/* in this demo we always show the overlay */
if (Togl_ExistsOverlay(togl)) {
Togl_ShowOverlay(togl);
printf("Red and green lines are in the overlay\n");
} else {
printf("Sorry, this display doesn't support overlays\n");
}
}
/*
* Togl widget reshape callback. This is called by Tcl/Tk when the widget
* has been resized. Typically, we call glViewport and perhaps setup the
* projection matrix.
*/
void
reshape_cb(Togl *togl)
{
int width = Togl_Width(togl);
int height = Togl_Height(togl);
float aspect = (float) width / (float) height;
/* Set up viewing for normal plane's context */
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-aspect, aspect, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
/* Set up viewing for overlay plane's context */
if (Togl_ExistsOverlay(togl)) {
Togl_UseLayer(togl, TOGL_OVERLAY);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
Togl_UseLayer(togl, TOGL_NORMAL);
}
}
/*
* Togl widget overlay display callback. This is called by Tcl/Tk when the
* overlay has to be redrawn.
*/
void
overlay_display_cb(Togl *togl)
{
glClear(GL_COLOR_BUFFER_BIT);
glIndexi(Red);
glBegin(GL_LINES);
glVertex2f(-1.0, -1.0);
glVertex2f(1.0, 1.0);
glVertex2f(-1.0, 1.0);
glVertex2f(1.0, -1.0);
glEnd();
glIndexi(Green);
glBegin(GL_LINE_LOOP);
glVertex2f(-0.5, -0.5);
glVertex2f(0.5, -0.5);
glVertex2f(0.5, 0.5);
glVertex2f(-0.5, 0.5);
glEnd();
glFlush();
}
/*
* Togl widget display callback. This is called by Tcl/Tk when the widget's
* contents have to be redrawn. Typically, we clear the color and depth
* buffers, render our objects, then swap the front/back color buffers.
*/
void
display_cb(Togl *togl)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 1.0);
glVertex2f(-0.5, -0.3);
glVertex2f(0.5, -0.3);
glVertex2f(0.0, 0.6);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(-0.5 + 0.2, -0.3 - 0.2);
glVertex2f(0.5 + 0.2, -0.3 - 0.2);
glVertex2f(0.0 + 0.2, 0.6 - 0.2);
glColor3f(0.0, 1.0, 1.0);
glVertex2f(-0.5 + 0.4, -0.3 - 0.4);
glVertex2f(0.5 + 0.4, -0.3 - 0.4);
glVertex2f(0.0 + 0.4, 0.6 - 0.4);
glEnd();
glFlush();
}
/*
* Called by Tk_Main() to let me initialize the modules (Togl) I will need.
*/
TOGL_EXTERN int
Overlay_Init(Tcl_Interp *interp)
{
/*
* Initialize Tcl, Tk, and the Togl widget module.
*/
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
if (Tk_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
if (Togl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
/*
* Specify the C callback functions for widget creation, display,
* and reshape.
*/
Togl_CreateFunc(create_cb);
Togl_DisplayFunc(display_cb);
Togl_ReshapeFunc(reshape_cb);
Togl_OverlayDisplayFunc(overlay_display_cb);
/*
* Make a new Togl widget command so the Tcl code can set a C variable.
*/
/* NONE */
/*
* Call Tcl_CreateCommand for application-specific commands, if
* they weren't already created by the init procedures called above.
*/
return TCL_OK;
}

View File

@ -1,49 +0,0 @@
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
# $Id: overlay.tcl,v 1.4 2001/12/20 13:59:31 beskow Exp $
# Togl - a Tk OpenGL widget
# Copyright (C) 1996 Brian Paul and Ben Bederson
# See the LICENSE file for copyright details.
# $Log: overlay.tcl,v $
# Revision 1.4 2001/12/20 13:59:31 beskow
# Improved error-handling in togl.c in case of window creation failure
# Added pkgIndex target to makefile
# Updated documentation to reflect stubs-interface (Togl.html + new README.stubs)
# Added tk8.4a3 headers
# Removed obsolete Tk internal headers
#
# Revision 1.3 2001/01/29 18:11:53 brianp
# Jonas Beskow's changes to use Tcl/Tk stub interface
#
# Revision 1.2 1998/01/24 14:05:50 brianp
# added quit button (Ben Bederson)
#
# Revision 1.1 1997/03/07 01:26:38 brianp
# Initial revision
#
#
# A Tk/OpenGL widget demo using an overlay.
load [file dirname [info script]]/overlay[info sharedlibextension]
proc setup {} {
wm title . "Overlay demo"
togl .win -width 200 -height 200 -rgba true -double false -overlay true
button .btn -text Quit -command exit
pack .win -expand true -fill both
pack .btn -expand true -fill both
}
# Execution starts here!
setup

View File

@ -1,5 +0,0 @@
#
# Tcl package index file
#
package ifneeded @PACKAGE_NAME@ @PACKAGE_VERSION@ \
[list load [file join $dir @PKG_LIB_FILE@]]

View File

@ -1,352 +0,0 @@
/* $Id: stereo.c,v 1.6 2005/04/23 07:49:13 gregcouch Exp $ */
/*
* Togl - a Tk OpenGL widget
* Copyright (C) 1996-1997 Brian Paul and Ben Bederson
* See the LICENSE file for copyright details.
*/
#include "togl.h"
#include <stdlib.h>
#include <string.h>
/*
* The following variable is a special hack that is needed in order for
* Sun shared libraries to be used for Tcl.
*/
#ifdef SUN
extern int matherr();
int *tclDummyMathPtr = (int *) matherr;
#endif
static GLuint FontBase;
static float xAngle = 0.0, yAngle = 0.0, zAngle = 0.0;
static GLfloat CornerX, CornerY, CornerZ; /* where to print strings */
static GLfloat scale = 1.0;
/*
* Togl widget create callback. This is called by Tcl/Tk when the widget has
* been realized. Here's where one may do some one-time context setup or
* initializations.
*/
void
create_cb(Togl *togl)
{
FontBase = Togl_LoadBitmapFont(togl, TOGL_BITMAP_8_BY_13);
if (!FontBase) {
printf("Couldn't load font!\n");
exit(1);
}
}
/*
* Togl widget reshape callback. This is called by Tcl/Tk when the widget
* has been resized. Typically, we call glViewport and perhaps setup the
* projection matrix.
*/
void
reshape_cb(Togl *togl)
{
int width = Togl_Width(togl);
int height = Togl_Height(togl);
float aspect = (float) width / (float) height;
glViewport(0, 0, width, height);
/* Set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-aspect, aspect, -1.0, 1.0, 1.0, 10.0);
CornerX = -aspect;
CornerY = -1.0;
CornerZ = -1.1;
/* Change back to model view transform for rendering */
glMatrixMode(GL_MODELVIEW);
}
static void
print_string(const char *s)
{
glCallLists(strlen(s), GL_UNSIGNED_BYTE, s);
}
/*
* Togl widget display callback. This is called by Tcl/Tk when the widget's
* contents have to be redrawn. Typically, we clear the color and depth
* buffers, render our objects, then swap the front/back color buffers.
*/
void
display_cb(Togl *togl)
{
const char *ident;
GLfloat eyeDist = 2.0;
GLfloat eyeOffset = 0.05;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); /* Reset modelview matrix to the identity
* matrix */
glTranslatef(0.0, 0.0, -3.0); /* Move the camera back three units */
glScalef(scale, scale, scale); /* Zoom in and out */
glRotatef(xAngle, 1.0, 0.0, 0.0); /* Rotate by X, Y, and Z angles */
glRotatef(yAngle, 0.0, 1.0, 0.0);
glRotatef(zAngle, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
/* stereo right eye */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Togl_StereoFrustum(-1, 1, -1, 1, 1, 10, eyeDist, eyeOffset);
glMatrixMode(GL_MODELVIEW);
#ifdef OLD_STEREO
Togl_OldStereoDrawBuffer(GL_BACK_RIGHT);
Togl_OldStereoClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#else
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif
/* Front face */
glBegin(GL_QUADS);
glColor3f(0.0, 0.7, 0.1); /* Green */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(-1.0, -1.0, 1.0);
/* Back face */
glColor3f(0.9, 1.0, 0.0); /* Yellow */
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
/* Top side face */
glColor3f(0.2, 0.2, 1.0); /* Blue */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);
/* Bottom side face */
glColor3f(0.7, 0.0, 0.1); /* Red */
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glEnd();
/* stereo left eye */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
Togl_StereoFrustum(-1, 1, -1, 1, 1, 10, eyeDist, -eyeOffset);
glMatrixMode(GL_MODELVIEW);
#ifdef OLD_STEREO
Togl_OldStereoDrawBuffer(GL_BACK_LEFT);
Togl_OldStereoClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#else
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif
/* Front face */
glBegin(GL_QUADS);
glColor3f(0.0, 0.7, 0.1); /* Green */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(-1.0, -1.0, 1.0);
/* Back face */
glColor3f(0.9, 1.0, 0.0); /* Yellow */
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
/* Top side face */
glColor3f(0.2, 0.2, 1.0); /* Blue */
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);
/* Bottom side face */
glColor3f(0.7, 0.0, 0.1); /* Red */
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glEnd();
glDisable(GL_DEPTH_TEST);
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glRasterPos3f(CornerX, CornerY, CornerZ);
glListBase(FontBase);
/* ident = Togl_Ident( togl ); if (strcmp(ident,"Single")==0) {
* print_string( "Single buffered" ); } else { print_string( "Double
* buffered" ); } */
print_string(Togl_Ident(togl));
Togl_SwapBuffers(togl);
}
int
setXrot_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName setXrot ?angle?\"",
TCL_STATIC);
return TCL_ERROR;
}
xAngle = atof(argv[2]);
/* printf( "before %f ", xAngle ); */
if (xAngle < 0.0) {
xAngle += 360.0;
} else if (xAngle > 360.0) {
xAngle -= 360.0;
}
/* printf( "after %f \n", xAngle ); */
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
int
setYrot_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName setYrot ?angle?\"",
TCL_STATIC);
return TCL_ERROR;
}
yAngle = atof(argv[2]);
if (yAngle < 0.0) {
yAngle += 360.0;
} else if (yAngle > 360.0) {
yAngle -= 360.0;
}
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
int
getXrot_cb(ClientData clientData, Tcl_Interp *interp,
int argc, CONST84 char *argv[])
{
sprintf(interp->result, "%d", (int) xAngle);
return TCL_OK;
}
int
getYrot_cb(ClientData clientData, Tcl_Interp *interp,
int argc, CONST84 char *argv[])
{
sprintf(interp->result, "%d", (int) yAngle);
return TCL_OK;
}
int
scale_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName scale ?value?\"",
TCL_STATIC);
return TCL_ERROR;
}
scale = atof(argv[2]);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
TOGL_EXTERN int
Stereo_Init(Tcl_Interp *interp)
{
/*
* Initialize Tcl, Tk, and the Togl widget module.
*/
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
if (Tk_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
if (Togl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
/*
* Specify the C callback functions for widget creation, display,
* and reshape.
*/
Togl_CreateFunc(create_cb);
Togl_DisplayFunc(display_cb);
Togl_ReshapeFunc(reshape_cb);
/*
* Make a new Togl widget command so the Tcl code can set a C variable.
*/
Togl_CreateCommand("setXrot", setXrot_cb);
Togl_CreateCommand("setYrot", setYrot_cb);
Togl_CreateCommand("scale", scale_cb);
/*
* Call Tcl_CreateCommand for application-specific commands, if
* they weren't already created by the init procedures called above.
*/
Tcl_CreateCommand(interp, "getXrot", getXrot_cb, (ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(interp, "getYrot", getYrot_cb, (ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}

View File

@ -1,108 +0,0 @@
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
# $Id: stereo.tcl,v 1.4 2004/12/21 05:28:39 gregcouch Exp $
# Togl - a Tk OpenGL widget
# Copyright (C) 1996 Brian Paul and Ben Bederson
# See the LICENSE file for copyright details.
# $Log: stereo.tcl,v $
# Revision 1.4 2004/12/21 05:28:39 gregcouch
# Apply outstanding patches and Mac OS X support.
#
# Revision 1.3 2001/12/20 13:59:31 beskow
# Improved error-handling in togl.c in case of window creation failure
# Added pkgIndex target to makefile
# Updated documentation to reflect stubs-interface (Togl.html + new README.stubs)
# Added tk8.4a3 headers
# Removed obsolete Tk internal headers
#
# Revision 1.2 2001/01/29 18:11:53 brianp
# Jonas Beskow's changes to use Tcl/Tk stub interface
#
# Revision 1.1 1997/10/01 02:53:12 brianp
# Initial revision
#
#
# Revision 1.1 1997/9/28 18:54:46 Ben Evans
# Initial revision. Based on double.tcl
#
# An Tk/OpenGL widget demo with two windows, one single buffered and the
# other double buffered.
load [file dirname [info script]]/stereo[info sharedlibextension]
proc setup {} {
global scale
set scale 1.0
wm title . "Full Screen Stereo Buffering"
frame .f1
togl .f1.o1 -width 200 -height 200 -rgba true -stereo true -double true -depth true -ident "stereo buffer"
scale .sx -label {X Axis} -from 0 -to 360 -command {setAngle x} -orient horizontal
scale .sy -label {Y Axis} -from 0 -to 360 -command {setAngle y} -orient horizontal
button .btn -text Quit -command exit
bind .f1.o1 <B1-Motion> {
motion_event [lindex [%W config -width] 4] \
[lindex [%W config -height] 4] \
%x %y
}
bind .f1.o1 <ButtonPress-2> {
set startx %x
set starty %y
set scale0 $scale
}
bind .f1.o1 <B1-B2-Motion> {
set q [ expr ($starty - %y) / 400.0 ]
set scale [expr $scale0 * exp($q)]
.f1.o1 scale $scale
}
pack .f1.o1 -side left -padx 3 -pady 3 -fill both -expand t
pack .f1 -fill both -expand t
pack .sx -fill x
pack .sy -fill x
pack .btn -fill x
if {[string first $::tcl_platform(os) IRIX] != -1} {
puts "use /usr/gfx/setmon -n 60 to reset display and /usr/gfx/setmon -n STR_RECT to put in display in stereo mode"
}
}
# This is called when mouse button 1 is pressed and moved in either of
# the OpenGL windows.
proc motion_event { width height x y } {
.f1.o1 setXrot [expr 360.0 * $y / $height]
.f1.o1 setYrot [expr 360.0 * ($width - $x) / $width]
# .sx set [expr 360.0 * $y / $height]
# .sy set [expr 360.0 * ($width - $x) / $width]
.sx set [getXrot]
.sy set [getYrot]
}
# This is called when a slider is changed.
proc setAngle {axis value} {
global xAngle yAngle zAngle
switch -exact $axis {
x {.f1.o1 setXrot $value}
y {.f1.o1 setYrot $value}
}
}
# Execution starts here!
setup

View File

@ -1,26 +0,0 @@
These files comprise the basic building blocks for a Tcl Extension
Architecture (TEA) extension. For more information on TEA see:
http://www.tcl.tk/doc/tea/
This package is part of the Tcl project at SourceForge, and latest
sources should be available there:
http://tcl.sourceforge.net/
This package is a freely available open source package. You can do
virtually anything you like with it, such as modifying it, redistributing
it, and selling it either in whole or in part.
CONTENTS
========
The following is a short description of the files you will find in
the sample extension.
README.txt This file
install-sh Program used for copying binaries and script files
to their install locations.
tcl.m4 Collection of Tcl autoconf macros. Included by a package's
aclocal.m4 to define TEA_* macros.

View File

@ -1,119 +0,0 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5; it is not part of GNU.
#
# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
instcmd="$mvprog"
chmodcmd=""
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
fi
# Make a temp file name in the proper directory.
dstdir=`dirname $dst`
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp
# and set any options; do chmod last to preserve setuid bits
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
# Now rename the file to the real destination.
$doit $rmcmd $dst
$doit $mvcmd $dsttmp $dst
exit 0

File diff suppressed because it is too large Load Diff

View File

@ -1,608 +0,0 @@
/* $Id: texture.c,v 1.10 2005/04/23 07:49:14 gregcouch Exp $ */
/*
* Togl - a Tk OpenGL widget
* Copyright (C) 1996-1997 Brian Paul and Ben Bederson
* See the LICENSE file for copyright details.
*/
/*
* An example Togl program demonstrating texture mapping
*/
#include "togl.h"
#include <stdlib.h>
#include <string.h>
#if defined(TOGL_AGL) || defined(TOGL_AGL_CLASSIC)
# include <OpenGL/glu.h>
#else
# include <GL/glu.h>
#endif
#include "image.h"
/*
* The following variable is a special hack that is needed in order for
* Sun shared libraries to be used for Tcl.
*/
#ifdef SUN
extern int matherr();
int *tclDummyMathPtr = (int *) matherr;
#endif
#define CHECKER 0
#define FACE 1
#define TREE 2
static GLenum minfilter = GL_NEAREST_MIPMAP_LINEAR;
static GLenum magfilter = GL_LINEAR;
static GLenum swrap = GL_REPEAT;
static GLenum twrap = GL_REPEAT;
static GLenum envmode = GL_MODULATE;
static GLubyte polycolor[4] = { 255, 255, 255, 255 };
static int image = CHECKER;
static GLfloat coord_scale = 1.0;
static GLfloat xrot = 0.0;
static GLfloat yrot = 0.0;
static GLfloat scale = 1.0;
static GLint width, height;
static GLboolean blend = GL_FALSE;
/*
* Load a texture image. n is one of CHECKER, FACE or TREE.
*/
void
texture_image(int n)
{
if (n == CHECKER) {
#define WIDTH 64
#define HEIGHT 64
GLubyte teximage[WIDTH * HEIGHT][4];
int i, j;
for (i = 0; i < HEIGHT; i++) {
for (j = 0; j < WIDTH; j++) {
GLubyte value;
value = ((i / 4 + j / 4) % 2) ? 0xff : 0x00;
teximage[i * WIDTH + j][0] = value;
teximage[i * WIDTH + j][1] = value;
teximage[i * WIDTH + j][2] = value;
teximage[i * WIDTH + j][3] = value;
}
}
glEnable(GL_TEXTURE_2D);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, WIDTH, HEIGHT,
GL_RGBA, GL_UNSIGNED_BYTE, teximage);
blend = GL_FALSE;
#undef WIDTH
#undef HEIGHT
} else if (n == FACE) {
TK_RGBImageRec *img = tkRGBImageLoad("ben.rgb");
if (img) {
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
gluBuild2DMipmaps(GL_TEXTURE_2D, img->sizeZ, img->sizeX, img->sizeY,
img->sizeZ == 3 ? GL_RGB : GL_RGBA,
GL_UNSIGNED_BYTE, img->data);
blend = GL_TRUE;
}
} else if (n == TREE) {
TK_RGBImageRec *img = tkRGBImageLoad("tree2.rgba");
if (img) {
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
gluBuild2DMipmaps(GL_TEXTURE_2D, img->sizeZ, img->sizeX, img->sizeY,
img->sizeZ == 3 ? GL_RGB : GL_RGBA,
GL_UNSIGNED_BYTE, img->data);
blend = GL_TRUE;
}
} else {
abort();
}
}
/*
* Togl widget create callback. This is called by Tcl/Tk when the widget has
* been realized. Here's where one may do some one-time context setup or
* initializations.
*/
void
create_cb(Togl *togl)
{
glEnable(GL_DEPTH_TEST); /* Enable depth buffering */
texture_image(CHECKER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter);
}
/*
* Togl widget reshape callback. This is called by Tcl/Tk when the widget
* has been resized. Typically, we call glViewport and perhaps setup the
* projection matrix.
*/
void
reshape_cb(Togl *togl)
{
width = Togl_Width(togl);
height = Togl_Height(togl);
glViewport(0, 0, width, height);
}
static void
check_error(char *where)
{
GLenum error;
while (1) {
error = glGetError();
if (error == GL_NO_ERROR) {
break;
}
printf("OpenGL error near %s: %s\n", where, gluErrorString(error));
}
}
/*
* Togl widget display callback. This is called by Tcl/Tk when the widget's
* contents have to be redrawn. Typically, we clear the color and depth
* buffers, render our objects, then swap the front/back color buffers.
*/
void
display_cb(Togl *togl)
{
float aspect = (float) width / (float) height;
check_error("begin display\n");
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Draw background image */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 0.3);
glVertex2f(-1.0, -1.0);
glColor3f(0.0, 0.0, 0.3);
glVertex2f(1.0, -1.0);
glColor3f(0.0, 0.0, 0.9);
glVertex2f(1.0, 1.0);
glColor3f(0.0, 0.0, 0.9);
glVertex2f(-1.0, 1.0);
glEnd();
/* draw textured object */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-aspect, aspect, -1.0, 1.0, 2.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
glScalef(scale, scale, scale);
glRotatef(yrot, 0.0, 1.0, 0.0);
glRotatef(xrot, 1.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glColor4ubv(polycolor);
if (blend) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0);
glVertex2f(-1.0, -1.0);
glTexCoord2f(coord_scale, 0.0);
glVertex2f(1.0, -1.0);
glTexCoord2f(coord_scale, coord_scale);
glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, coord_scale);
glVertex2f(-1.0, 1.0);
glEnd();
glDisable(GL_BLEND);
Togl_SwapBuffers(togl);
}
/*
* Called when a magnification filter radio button is pressed.
*/
int
magfilter_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
if (strcmp(argv[2], "GL_NEAREST") == 0) {
magfilter = GL_NEAREST;
} else if (strcmp(argv[2], "GL_LINEAR") == 0) {
magfilter = GL_LINEAR;
} else {
Tcl_SetResult(interp, "unknown magnification filter type", TCL_STATIC);
return TCL_ERROR;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter);
Togl_PostRedisplay(togl);
return TCL_OK;
}
/*
* Called when a minification filter radio button is pressed.
*/
int
minfilter_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
if (strcmp(argv[2], "GL_NEAREST") == 0) {
minfilter = GL_NEAREST;
} else if (strcmp(argv[2], "GL_LINEAR") == 0) {
minfilter = GL_LINEAR;
} else if (strcmp(argv[2], "GL_NEAREST_MIPMAP_NEAREST") == 0) {
minfilter = GL_NEAREST_MIPMAP_NEAREST;
} else if (strcmp(argv[2], "GL_LINEAR_MIPMAP_NEAREST") == 0) {
minfilter = GL_LINEAR_MIPMAP_NEAREST;
} else if (strcmp(argv[2], "GL_NEAREST_MIPMAP_LINEAR") == 0) {
minfilter = GL_NEAREST_MIPMAP_LINEAR;
} else if (strcmp(argv[2], "GL_LINEAR_MIPMAP_LINEAR") == 0) {
minfilter = GL_LINEAR_MIPMAP_LINEAR;
} else {
Tcl_SetResult(interp, "unknown minification filter type", TCL_STATIC);
return TCL_ERROR;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter);
Togl_PostRedisplay(togl);
return TCL_OK;
}
int
xrot_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName setXrot ?angle?\"",
TCL_STATIC);
return TCL_ERROR;
}
xrot = atof(argv[2]);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
int
yrot_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName setYrot ?angle?\"",
TCL_STATIC);
return TCL_ERROR;
}
yrot = atof(argv[2]);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
int
scale_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName scale ?value?\"",
TCL_STATIC);
return TCL_ERROR;
}
scale = atof(argv[2]);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
/*
* Called when S texture coordinate wrapping is changed.
*/
int
swrap_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName swrap ?mode?\"",
TCL_STATIC);
return TCL_ERROR;
}
if (strcmp(argv[2], "GL_CLAMP") == 0) {
swrap = GL_CLAMP;
} else if (strcmp(argv[2], "GL_REPEAT") == 0) {
swrap = GL_REPEAT;
} else {
Tcl_SetResult(interp, "unknown wrap value", TCL_STATIC);
return TCL_ERROR;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, swrap);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
/*
* Called when T texture coordinate wrapping is changed.
*/
int
twrap_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName twrap ?mode?\"",
TCL_STATIC);
return TCL_ERROR;
}
if (strcmp(argv[2], "GL_CLAMP") == 0) {
twrap = GL_CLAMP;
} else if (strcmp(argv[2], "GL_REPEAT") == 0) {
twrap = GL_REPEAT;
} else {
Tcl_SetResult(interp, "unknown wrap value", TCL_STATIC);
return TCL_ERROR;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, twrap);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
/*
* Called when the texture environment mode is changed.
*/
int
envmode_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName envmode ?mode?\"",
TCL_STATIC);
return TCL_ERROR;
}
if (strcmp(argv[2], "GL_MODULATE") == 0) {
envmode = GL_MODULATE;
} else if (strcmp(argv[2], "GL_DECAL") == 0) {
envmode = GL_DECAL;
} else if (strcmp(argv[2], "GL_BLEND") == 0) {
envmode = GL_BLEND;
} else {
Tcl_SetResult(interp, "unknown texture env mode", TCL_STATIC);
return TCL_ERROR;
}
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, envmode);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
/*
* Called when the polygon color is changed.
*/
int
polycolor_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 5) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName polycolor ?r? ?g? ?b?\"",
TCL_STATIC);
return TCL_ERROR;
}
polycolor[0] = atoi(argv[2]);
polycolor[1] = atoi(argv[3]);
polycolor[2] = atoi(argv[4]);
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
/*
* Called when the texture image is to be changed
*/
int
image_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName image ?name?\"",
TCL_STATIC);
return TCL_ERROR;
}
if (strcmp(argv[2], "CHECKER") == 0) {
texture_image(CHECKER);
} else if (strcmp(argv[2], "FACE") == 0) {
texture_image(FACE);
} else if (strcmp(argv[2], "TREE") == 0) {
texture_image(TREE);
} else {
Tcl_SetResult(interp, "unknown texture image", TCL_STATIC);
return TCL_ERROR;
}
Togl_PostRedisplay(togl);
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
/*
* Called when the texture coordinate scale is changed.
*/
int
coord_scale_cb(Togl *togl, int argc, CONST84 char *argv[])
{
Tcl_Interp *interp = Togl_Interp(togl);
float s;
/* error checking */
if (argc != 3) {
Tcl_SetResult(interp,
"wrong # args: should be \"pathName coord_scale ?scale?\"",
TCL_STATIC);
return TCL_ERROR;
}
s = atof(argv[2]);
if (s > 0.0 && s < 10.0) {
coord_scale = s;
Togl_PostRedisplay(togl);
}
/* Let result string equal value */
strcpy(interp->result, argv[2]);
return TCL_OK;
}
TOGL_EXTERN int
Texture_Init(Tcl_Interp *interp)
{
/*
* Initialize Tcl, Tk, and the Togl widget module.
*/
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
if (Tk_InitStubs(interp, "8.1", 0) == NULL) {
return TCL_ERROR;
}
#endif
if (Togl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
/*
* Specify the C callback functions for widget creation, display,
* and reshape.
*/
Togl_CreateFunc(create_cb);
Togl_DisplayFunc(display_cb);
Togl_ReshapeFunc(reshape_cb);
/*
* Make a new Togl widget command so the Tcl code can set a C variable.
*/
Togl_CreateCommand("min_filter", minfilter_cb);
Togl_CreateCommand("mag_filter", magfilter_cb);
Togl_CreateCommand("xrot", xrot_cb);
Togl_CreateCommand("yrot", yrot_cb);
Togl_CreateCommand("scale", scale_cb);
Togl_CreateCommand("swrap", swrap_cb);
Togl_CreateCommand("twrap", twrap_cb);
Togl_CreateCommand("envmode", envmode_cb);
Togl_CreateCommand("polycolor", polycolor_cb);
Togl_CreateCommand("image", image_cb);
Togl_CreateCommand("coord_scale", coord_scale_cb);
/*
* Call Tcl_CreateCommand for application-specific commands, if
* they weren't already created by the init procedures called above.
*/
return TCL_OK;
}

View File

@ -1,283 +0,0 @@
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
# $Id: texture.tcl,v 1.5 2001/12/20 13:59:31 beskow Exp $
# Togl - a Tk OpenGL widget
# Copyright (C) 1996 Brian Paul and Ben Bederson
# See the LICENSE file for copyright details.
# $Log: texture.tcl,v $
# Revision 1.5 2001/12/20 13:59:31 beskow
# Improved error-handling in togl.c in case of window creation failure
# Added pkgIndex target to makefile
# Updated documentation to reflect stubs-interface (Togl.html + new README.stubs)
# Added tk8.4a3 headers
# Removed obsolete Tk internal headers
#
# Revision 1.4 2001/01/29 18:11:53 brianp
# Jonas Beskow's changes to use Tcl/Tk stub interface
#
# Revision 1.3 1998/01/24 14:05:50 brianp
# added quit button (Ben Bederson)
#
# Revision 1.2 1997/09/30 23:54:46 brianp
# new layout
#
# Revision 1.1 1996/10/23 23:18:36 brianp
# Initial revision
#
# Togl texture map demo
load [file dirname [info script]]/texture[info sharedlibextension]
# Called magnification filter changes
proc new_magfilter {} {
global magfilter
.f1.view mag_filter $magfilter
}
# Called minification filter changes
proc new_minfilter {} {
global minfilter
.f1.view min_filter $minfilter
}
# Called when texture image radio button changes
proc new_image {} {
global teximage
.f1.view image $teximage
}
# Called when texture S wrap button changes
proc new_swrap {} {
global swrap
.f1.view swrap $swrap
}
# Called when texture T wrap button changes
proc new_twrap {} {
global twrap
.f1.view twrap $twrap
}
# Called when texture environment radio button selected
proc new_env {} {
global envmode
.f1.view envmode $envmode
}
# Called when polygon color sliders change
proc new_color { foo } {
global poly_red poly_green poly_blue
.f1.view polycolor $poly_red $poly_green $poly_blue
}
proc new_coord_scale { name element op } {
global coord_scale
.f1.view coord_scale $coord_scale
}
# Make the widgets
proc setup {} {
global magfilter
global minfilter
global teximage
global swrap
global twrap
global envmode
global poly_red
global poly_green
global poly_blue
global coord_scale
global startx starty # location of mouse when button pressed
global xangle yangle
global xangle0 yangle0
global scale scale0
wm title . "Texture Map Options"
### Two frames: top half and bottom half
frame .f1
frame .f2
### The OpenGL window
togl .f1.view -width 250 -height 250 -rgba true -double true -depth true
### Filter radio buttons
frame .f1.filter -relief ridge -borderwidth 3
frame .f1.filter.mag -relief ridge -borderwidth 2
label .f1.filter.mag.label -text "Magnification Filter" -anchor w
radiobutton .f1.filter.mag.nearest -text GL_NEAREST -anchor w -variable magfilter -value GL_NEAREST -command new_magfilter
radiobutton .f1.filter.mag.linear -text GL_LINEAR -anchor w -variable magfilter -value GL_LINEAR -command new_magfilter
frame .f1.filter.min -relief ridge -borderwidth 2
label .f1.filter.min.label -text "Minification Filter" -anchor w
radiobutton .f1.filter.min.nearest -text GL_NEAREST -anchor w -variable minfilter -value GL_NEAREST -command new_minfilter
radiobutton .f1.filter.min.linear -text GL_LINEAR -anchor w -variable minfilter -value GL_LINEAR -command new_minfilter
radiobutton .f1.filter.min.nearest_mipmap_nearest -text GL_NEAREST_MIPMAP_NEAREST -anchor w -variable minfilter -value GL_NEAREST_MIPMAP_NEAREST -command new_minfilter
radiobutton .f1.filter.min.linear_mipmap_nearest -text GL_LINEAR_MIPMAP_NEAREST -anchor w -variable minfilter -value GL_LINEAR_MIPMAP_NEAREST -command new_minfilter
radiobutton .f1.filter.min.nearest_mipmap_linear -text GL_NEAREST_MIPMAP_LINEAR -anchor w -variable minfilter -value GL_NEAREST_MIPMAP_LINEAR -command new_minfilter
radiobutton .f1.filter.min.linear_mipmap_linear -text GL_LINEAR_MIPMAP_LINEAR -anchor w -variable minfilter -value GL_LINEAR_MIPMAP_LINEAR -command new_minfilter
pack .f1.filter.mag -fill x
pack .f1.filter.mag.label -fill x
pack .f1.filter.mag.nearest -side top -fill x
pack .f1.filter.mag.linear -side top -fill x
pack .f1.filter.min -fill both -expand true
pack .f1.filter.min.label -side top -fill x
pack .f1.filter.min.nearest -side top -fill x
pack .f1.filter.min.linear -side top -fill x
pack .f1.filter.min.nearest_mipmap_nearest -side top -fill x
pack .f1.filter.min.linear_mipmap_nearest -side top -fill x
pack .f1.filter.min.nearest_mipmap_linear -side top -fill x
pack .f1.filter.min.linear_mipmap_linear -side top -fill x
### Texture coordinate scale and wrapping
frame .f2.coord -relief ridge -borderwidth 3
frame .f2.coord.scale -relief ridge -borderwidth 2
label .f2.coord.scale.label -text "Max Texture Coord" -anchor w
entry .f2.coord.scale.entry -textvariable coord_scale
trace variable coord_scale w new_coord_scale
frame .f2.coord.s -relief ridge -borderwidth 2
label .f2.coord.s.label -text "GL_TEXTURE_WRAP_S" -anchor w
radiobutton .f2.coord.s.repeat -text "GL_REPEAT" -anchor w -variable swrap -value GL_REPEAT -command new_swrap
radiobutton .f2.coord.s.clamp -text "GL_CLAMP" -anchor w -variable swrap -value GL_CLAMP -command new_swrap
frame .f2.coord.t -relief ridge -borderwidth 2
label .f2.coord.t.label -text "GL_TEXTURE_WRAP_T" -anchor w
radiobutton .f2.coord.t.repeat -text "GL_REPEAT" -anchor w -variable twrap -value GL_REPEAT -command new_twrap
radiobutton .f2.coord.t.clamp -text "GL_CLAMP" -anchor w -variable twrap -value GL_CLAMP -command new_twrap
pack .f2.coord.scale -fill both -expand true
pack .f2.coord.scale.label -side top -fill x
pack .f2.coord.scale.entry -side top -fill x
pack .f2.coord.s -fill x
pack .f2.coord.s.label -side top -fill x
pack .f2.coord.s.repeat -side top -fill x
pack .f2.coord.s.clamp -side top -fill x
pack .f2.coord.t -fill x
pack .f2.coord.t.label -side top -fill x
pack .f2.coord.t.repeat -side top -fill x
pack .f2.coord.t.clamp -side top -fill x
### Texture image radio buttons (just happens to fit into the coord frame)
frame .f2.env -relief ridge -borderwidth 3
frame .f2.env.image -relief ridge -borderwidth 2
label .f2.env.image.label -text "Texture Image" -anchor w
radiobutton .f2.env.image.checker -text "Checker" -anchor w -variable teximage -value CHECKER -command new_image
radiobutton .f2.env.image.tree -text "Tree" -anchor w -variable teximage -value TREE -command new_image
radiobutton .f2.env.image.face -text "Face" -anchor w -variable teximage -value FACE -command new_image
pack .f2.env.image -fill x
pack .f2.env.image.label -side top -fill x
pack .f2.env.image.checker -side top -fill x
pack .f2.env.image.tree -side top -fill x
pack .f2.env.image.face -side top -fill x
### Texture Environment
label .f2.env.label -text "GL_TEXTURE_ENV_MODE" -anchor w
radiobutton .f2.env.modulate -text "GL_MODULATE" -anchor w -variable envmode -value GL_MODULATE -command new_env
radiobutton .f2.env.decal -text "GL_DECAL" -anchor w -variable envmode -value GL_DECAL -command new_env
radiobutton .f2.env.blend -text "GL_BLEND" -anchor w -variable envmode -value GL_BLEND -command new_env
pack .f2.env.label -fill x
pack .f2.env.modulate -side top -fill x
pack .f2.env.decal -side top -fill x
pack .f2.env.blend -side top -fill x
### Polygon color
frame .f2.color -relief ridge -borderwidth 3
label .f2.color.label -text "Polygon color" -anchor w
scale .f2.color.red -label Red -from 0 -to 255 -orient horizontal -variable poly_red -command new_color
scale .f2.color.green -label Green -from 0 -to 255 -orient horizontal -variable poly_green -command new_color
scale .f2.color.blue -label Blue -from 0 -to 255 -orient horizontal -variable poly_blue -command new_color
pack .f2.color.label -fill x
pack .f2.color.red -side top -fill x
pack .f2.color.green -side top -fill x
pack .f2.color.blue -side top -fill x
### Main widgets
pack .f1.view -side left -fill both -expand true
pack .f1.filter -side left -fill y
pack .f1 -side top -fill both -expand true
pack .f2.coord .f2.env -side left -fill both
pack .f2.color -fill x
pack .f2 -side top -fill x
button .btn -text Quit -command exit
pack .btn -expand true -fill both
bind .f1.view <ButtonPress-1> {
set startx %x
set starty %y
set xangle0 $xangle
set yangle0 $yangle
}
bind .f1.view <B1-Motion> {
set xangle [expr $xangle0 + (%x - $startx) / 3.0 ]
set yangle [expr $yangle0 + (%y - $starty) / 3.0 ]
.f1.view yrot $xangle
.f1.view xrot $yangle
}
bind .f1.view <ButtonPress-2> {
set startx %x
set starty %y
set scale0 $scale
}
bind .f1.view <B2-Motion> {
set q [ expr ($starty - %y) / 400.0 ]
set scale [expr $scale0 * exp($q)]
.f1.view scale $scale
}
# set default values:
set minfilter GL_NEAREST_MIPMAP_LINEAR
set magfilter GL_LINEAR
set swrap GL_REPEAT
set twrap GL_REPEAT
set envmode GL_MODULATE
set teximage CHECKER
set poly_red 255
set poly_green 255
set poly_blue 255
set coord_scale 1.0
set xangle 0.0
set yangle 0.0
set scale 1.0
}
# Execution starts here!
setup

View File

@ -1,35 +0,0 @@
/* This file isn't installed by default */
/*
* tkMacOSXInt.h --
*
* Declarations of Macintosh specific exported variables and procedures.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tkMacOSX.h,v 1.1 2005/04/22 02:00:07 gregcouch Exp $
*/
#ifndef _TKMAC
#define _TKMAC
#include <Carbon/Carbon.h>
#include "tkInt.h"
/*
* Structures and function types for handling Netscape-type in process
* embedding where Tk does not control the top-level
*/
typedef int (Tk_MacOSXEmbedRegisterWinProc) (int winID, Tk_Window window);
typedef GWorldPtr (Tk_MacOSXEmbedGetGrafPortProc) (Tk_Window window);
typedef int (Tk_MacOSXEmbedMakeContainerExistProc) (Tk_Window window);
typedef void (Tk_MacOSXEmbedGetClipProc) (Tk_Window window, RgnHandle rgn);
typedef void (Tk_MacOSXEmbedGetOffsetInParentProc) (Tk_Window window, Point *ulCorner);
#include "tkPlatDecls.h"
#endif /* _TKMAC */

File diff suppressed because it is too large Load Diff

View File

@ -1,244 +0,0 @@
/* $Id: togl.h,v 1.28 2005/10/27 07:45:48 gregcouch Exp $ */
/* vi:set sw=4: */
/*
* Togl - a Tk OpenGL widget
*
* Copyright (C) 1996-1998 Brian Paul and Ben Bederson
* See the LICENSE file for copyright details.
*/
#ifndef TOGL_H
# define TOGL_H
#if !defined TOGL_X11 && !defined TOGL_WGL && !defined TOGL_AGL_CLASSIC && !defined TOGL_AGL
# include "togl_ws.h"
#endif
# ifdef TOGL_WGL
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef WIN32_LEAN_AND_MEAN
# if defined(_MSC_VER)
# define DllEntryPoint DllMain
# endif
# endif
# ifdef _WIN32
# define TOGL_EXTERN __declspec(dllexport) extern
# else
# define TOGL_EXTERN extern
# endif /* _WIN32 */
# ifdef TOGL_AGL_CLASSIC
# ifndef MAC_TCL
# define MAC_TCL 1
# endif
# endif
# ifdef TOGL_AGL
# ifndef MAC_OSX_TCL
# define MAC_OSX_TCL 1
# endif
# ifndef MAC_OSX_TK
# define MAC_OSX_TK 1
# endif
# endif
# include <tcl.h>
# include <tk.h>
# if defined(TOGL_AGL) || defined(TOGL_AGL_CLASSIC)
# include <OpenGL/gl.h>
# else
# include <GL/gl.h>
# endif
# ifdef __sgi
# include <GL/glx.h>
# include <X11/extensions/SGIStereo.h>
# endif
# ifndef CONST84
# define CONST84
# endif
# ifndef NULL
# define NULL 0
# endif
# ifndef TOGL_USE_FONTS
# define TOGL_USE_FONTS 1 /* needed for demos */
# endif
# ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
# endif
# define TOGL_VERSION "1.7"
# define TOGL_MAJOR_VERSION 1
# define TOGL_MINOR_VERSION 7
/*
* "Standard" fonts which can be specified to Togl_LoadBitmapFont()
*/
# define TOGL_BITMAP_8_BY_13 ((char *) 1)
# define TOGL_BITMAP_9_BY_15 ((char *) 2)
# define TOGL_BITMAP_TIMES_ROMAN_10 ((char *) 3)
# define TOGL_BITMAP_TIMES_ROMAN_24 ((char *) 4)
# define TOGL_BITMAP_HELVETICA_10 ((char *) 5)
# define TOGL_BITMAP_HELVETICA_12 ((char *) 6)
# define TOGL_BITMAP_HELVETICA_18 ((char *) 7)
/*
* Normal and overlay plane constants
*/
# define TOGL_NORMAL 1
# define TOGL_OVERLAY 2
struct Togl;
typedef struct Togl Togl;
typedef void (Togl_Callback) (Togl *togl);
typedef int (Togl_CmdProc) (Togl *togl, int argc, CONST84 char *argv[]);
TOGL_EXTERN int Togl_Init(Tcl_Interp *interp);
/*
* Default/initial callback setup functions
*/
TOGL_EXTERN void Togl_CreateFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_DisplayFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_ReshapeFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_DestroyFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_TimerFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_ResetDefaultCallbacks(void);
/*
* Change callbacks for existing widget
*/
TOGL_EXTERN void Togl_SetCreateFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetDisplayFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetReshapeFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetDestroyFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetTimerFunc(Togl *togl, Togl_Callback *proc);
/*
* Miscellaneous
*/
TOGL_EXTERN int Togl_Configure(Tcl_Interp *interp, Togl *togl,
int argc, const char *argv[], int flags);
TOGL_EXTERN void Togl_MakeCurrent(const Togl *togl);
TOGL_EXTERN void Togl_CreateCommand(char *cmd_name, Togl_CmdProc *cmd_proc);
TOGL_EXTERN void Togl_PostRedisplay(Togl *togl);
TOGL_EXTERN void Togl_SwapBuffers(const Togl *togl);
/*
* Query functions
*/
TOGL_EXTERN const char *Togl_Ident(const Togl *togl);
TOGL_EXTERN int Togl_Width(const Togl *togl);
TOGL_EXTERN int Togl_Height(const Togl *togl);
TOGL_EXTERN Tcl_Interp *Togl_Interp(const Togl *togl);
TOGL_EXTERN Tk_Window Togl_TkWin(const Togl *togl);
/*
* Color Index mode
*/
TOGL_EXTERN unsigned long Togl_AllocColor(const Togl *togl, float red,
float green, float blue);
TOGL_EXTERN void Togl_FreeColor(const Togl *togl, unsigned long index);
TOGL_EXTERN void Togl_SetColor(const Togl *togl, unsigned long index,
float red, float green, float blue);
# if TOGL_USE_FONTS == 1
/*
* Bitmap fonts
*/
TOGL_EXTERN GLuint Togl_LoadBitmapFont(const Togl *togl, const char *fontname);
TOGL_EXTERN void Togl_UnloadBitmapFont(const Togl *togl, GLuint fontbase);
# endif
/*
* Overlay functions
*/
TOGL_EXTERN void Togl_UseLayer(Togl *togl, int layer);
TOGL_EXTERN void Togl_ShowOverlay(Togl *togl);
TOGL_EXTERN void Togl_HideOverlay(Togl *togl);
TOGL_EXTERN void Togl_PostOverlayRedisplay(Togl *togl);
TOGL_EXTERN void Togl_OverlayDisplayFunc(Togl_Callback *proc);
TOGL_EXTERN int Togl_ExistsOverlay(const Togl *togl);
TOGL_EXTERN int Togl_GetOverlayTransparentValue(const Togl *togl);
TOGL_EXTERN int Togl_IsMappedOverlay(const Togl *togl);
TOGL_EXTERN unsigned long Togl_AllocColorOverlay(const Togl *togl,
float red, float green, float blue);
TOGL_EXTERN void Togl_FreeColorOverlay(const Togl *togl, unsigned long index);
/*
* User client data
*/
TOGL_EXTERN void Togl_ClientData(ClientData clientData);
TOGL_EXTERN ClientData Togl_GetClientData(const Togl *togl);
TOGL_EXTERN void Togl_SetClientData(Togl *togl, ClientData clientData);
# ifdef TOGL_X11
/*
* X11-only commands.
* Contributed by Miguel A. De Riera Pasenau (miguel@DALILA.UPC.ES)
*/
TOGL_EXTERN Display *Togl_Display(const Togl *togl);
TOGL_EXTERN Screen *Togl_Screen(const Togl *togl);
TOGL_EXTERN int Togl_ScreenNumber(const Togl *togl);
TOGL_EXTERN Colormap Togl_Colormap(const Togl *togl);
# endif
# ifdef __sgi
/*
* SGI stereo-only commands.
* Contributed by Ben Evans (Ben.Evans@anusf.anu.edu.au)
*/
TOGL_EXTERN void Togl_OldStereoDrawBuffer(GLenum mode);
TOGL_EXTERN void Togl_OldStereoClear(GLbitfield mask);
# endif
TOGL_EXTERN void Togl_StereoFrustum(GLfloat left, GLfloat right, GLfloat bottom,
GLfloat top, GLfloat near, GLfloat far, GLfloat eyeDist,
GLfloat eyeOffset);
/*
* Generate EPS file.
* Contributed by Miguel A. De Riera Pasenau (miguel@DALILA.UPC.ES)
*/
TOGL_EXTERN int Togl_DumpToEpsFile(const Togl *togl, const char *filename,
int inColor, void (*user_redraw) (const Togl *));
# ifdef TOGL_AGL_CLASSIC
/*
* Mac-specific setup functions
*/
extern int Togl_MacInit(void);
extern int Togl_MacSetupMainInterp(Tcl_Interp *interp);
# endif
# ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
# endif
#endif

View File

@ -1,7 +0,0 @@
#ifndef TOGL_WS_H
# define TOGL_WS_H
/* define windowing system togl is compiled with */
# define @TOGL_WINDOWINGSYSTEM@
#endif

Binary file not shown.

View File

@ -27,14 +27,6 @@ if { [Ng_GetToglVersion] == 2 } {
# puts "have Togl 2.1"
set toglok 1
}
} {
# Togl 1.7
if {[catch {togl .ndraw -width 400 -height 300 -rgba true -double true -depth true -privatecmap false -stereo false -indirect false }] } {
puts "no OpenGL"
} {
# puts "have Togl 1.7"
set toglok 1
}
}
if { $toglok == 1} {

View File

@ -195,7 +195,7 @@ namespace netgen
if(mesh->GetGeometry())
ng_geometry = mesh->GetGeometry();
}
catch (NgException e)
catch (const NgException & e)
{
PrintMessage (3, e.What());
return TCL_ERROR;
@ -270,7 +270,7 @@ namespace netgen
geometry -> LoadSurfaces(infile);
}
}
catch (NgException e)
catch (const NgException & e)
{
PrintMessage (3, e.What());
return TCL_ERROR;
@ -552,7 +552,7 @@ namespace netgen
}
}
catch (NgException e)
catch (const NgException & e)
{
Tcl_SetResult (interp, const_cast<char*> (e.What().c_str()), TCL_VOLATILE);
return TCL_ERROR;
@ -583,7 +583,7 @@ namespace netgen
{
ng_geometry -> Save (string (cfilename));
}
catch (NgException e)
catch (const NgException & e)
{
Tcl_SetResult (interp, const_cast<char*> (e.What().c_str()), TCL_VOLATILE);
return TCL_ERROR;
@ -1441,7 +1441,7 @@ namespace netgen
PrintMessage (1, "Meshing done, time = ", GetTime(), " sec");
}
catch (NgException e)
catch (const NgException & e)
{
cout << e.What() << endl;
}

View File

@ -1,244 +0,0 @@
/* $Id: togl.h,v 1.28 2005/10/27 07:45:48 gregcouch Exp $ */
/* vi:set sw=4: */
/*
* Togl - a Tk OpenGL widget
*
* Copyright (C) 1996-1998 Brian Paul and Ben Bederson
* See the LICENSE file for copyright details.
*/
#ifndef TOGL_H
# define TOGL_H
#if !defined TOGL_X11 && !defined TOGL_WGL && !defined TOGL_AGL_CLASSIC && !defined TOGL_AGL
# include "togl_ws.h"
#endif
# ifdef TOGL_WGL
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef WIN32_LEAN_AND_MEAN
# if defined(_MSC_VER)
# define DllEntryPoint DllMain
# endif
# endif
# ifdef _WIN32
# define TOGL_EXTERN __declspec(dllexport) extern
# else
# define TOGL_EXTERN extern
# endif /* _WIN32 */
# ifdef TOGL_AGL_CLASSIC
# ifndef MAC_TCL
# define MAC_TCL 1
# endif
# endif
# ifdef TOGL_AGL
# ifndef MAC_OSX_TCL
# define MAC_OSX_TCL 1
# endif
# ifndef MAC_OSX_TK
# define MAC_OSX_TK 1
# endif
# endif
# include <tcl.h>
# include <tk.h>
# if defined(TOGL_AGL) || defined(TOGL_AGL_CLASSIC)
# include <OpenGL/gl.h>
# else
# include <GL/gl.h>
# endif
# ifdef __sgi
# include <GL/glx.h>
# include <X11/extensions/SGIStereo.h>
# endif
# ifndef CONST84
# define CONST84
# endif
# ifndef NULL
# define NULL 0
# endif
# ifndef TOGL_USE_FONTS
# define TOGL_USE_FONTS 1 /* needed for demos */
# endif
# ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
# endif
# define TOGL_VERSION "1.7"
# define TOGL_MAJOR_VERSION 1
# define TOGL_MINOR_VERSION 7
/*
* "Standard" fonts which can be specified to Togl_LoadBitmapFont()
*/
# define TOGL_BITMAP_8_BY_13 ((char *) 1)
# define TOGL_BITMAP_9_BY_15 ((char *) 2)
# define TOGL_BITMAP_TIMES_ROMAN_10 ((char *) 3)
# define TOGL_BITMAP_TIMES_ROMAN_24 ((char *) 4)
# define TOGL_BITMAP_HELVETICA_10 ((char *) 5)
# define TOGL_BITMAP_HELVETICA_12 ((char *) 6)
# define TOGL_BITMAP_HELVETICA_18 ((char *) 7)
/*
* Normal and overlay plane constants
*/
# define TOGL_NORMAL 1
# define TOGL_OVERLAY 2
struct Togl;
typedef struct Togl Togl;
typedef void (Togl_Callback) (Togl *togl);
typedef int (Togl_CmdProc) (Togl *togl, int argc, CONST84 char *argv[]);
TOGL_EXTERN int Togl_Init(Tcl_Interp *interp);
/*
* Default/initial callback setup functions
*/
TOGL_EXTERN void Togl_CreateFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_DisplayFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_ReshapeFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_DestroyFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_TimerFunc(Togl_Callback *proc);
TOGL_EXTERN void Togl_ResetDefaultCallbacks(void);
/*
* Change callbacks for existing widget
*/
TOGL_EXTERN void Togl_SetCreateFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetDisplayFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetReshapeFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetDestroyFunc(Togl *togl, Togl_Callback *proc);
TOGL_EXTERN void Togl_SetTimerFunc(Togl *togl, Togl_Callback *proc);
/*
* Miscellaneous
*/
TOGL_EXTERN int Togl_Configure(Tcl_Interp *interp, Togl *togl,
int argc, const char *argv[], int flags);
TOGL_EXTERN void Togl_MakeCurrent(const Togl *togl);
TOGL_EXTERN void Togl_CreateCommand(char *cmd_name, Togl_CmdProc *cmd_proc);
TOGL_EXTERN void Togl_PostRedisplay(Togl *togl);
TOGL_EXTERN void Togl_SwapBuffers(const Togl *togl);
/*
* Query functions
*/
TOGL_EXTERN const char *Togl_Ident(const Togl *togl);
TOGL_EXTERN int Togl_Width(const Togl *togl);
TOGL_EXTERN int Togl_Height(const Togl *togl);
TOGL_EXTERN Tcl_Interp *Togl_Interp(const Togl *togl);
TOGL_EXTERN Tk_Window Togl_TkWin(const Togl *togl);
/*
* Color Index mode
*/
TOGL_EXTERN unsigned long Togl_AllocColor(const Togl *togl, float red,
float green, float blue);
TOGL_EXTERN void Togl_FreeColor(const Togl *togl, unsigned long index);
TOGL_EXTERN void Togl_SetColor(const Togl *togl, unsigned long index,
float red, float green, float blue);
# if TOGL_USE_FONTS == 1
/*
* Bitmap fonts
*/
TOGL_EXTERN GLuint Togl_LoadBitmapFont(const Togl *togl, const char *fontname);
TOGL_EXTERN void Togl_UnloadBitmapFont(const Togl *togl, GLuint fontbase);
# endif
/*
* Overlay functions
*/
TOGL_EXTERN void Togl_UseLayer(Togl *togl, int layer);
TOGL_EXTERN void Togl_ShowOverlay(Togl *togl);
TOGL_EXTERN void Togl_HideOverlay(Togl *togl);
TOGL_EXTERN void Togl_PostOverlayRedisplay(Togl *togl);
TOGL_EXTERN void Togl_OverlayDisplayFunc(Togl_Callback *proc);
TOGL_EXTERN int Togl_ExistsOverlay(const Togl *togl);
TOGL_EXTERN int Togl_GetOverlayTransparentValue(const Togl *togl);
TOGL_EXTERN int Togl_IsMappedOverlay(const Togl *togl);
TOGL_EXTERN unsigned long Togl_AllocColorOverlay(const Togl *togl,
float red, float green, float blue);
TOGL_EXTERN void Togl_FreeColorOverlay(const Togl *togl, unsigned long index);
/*
* User client data
*/
TOGL_EXTERN void Togl_ClientData(ClientData clientData);
TOGL_EXTERN ClientData Togl_GetClientData(const Togl *togl);
TOGL_EXTERN void Togl_SetClientData(Togl *togl, ClientData clientData);
# ifdef TOGL_X11
/*
* X11-only commands.
* Contributed by Miguel A. De Riera Pasenau (miguel@DALILA.UPC.ES)
*/
TOGL_EXTERN Display *Togl_Display(const Togl *togl);
TOGL_EXTERN Screen *Togl_Screen(const Togl *togl);
TOGL_EXTERN int Togl_ScreenNumber(const Togl *togl);
TOGL_EXTERN Colormap Togl_Colormap(const Togl *togl);
# endif
# ifdef __sgi
/*
* SGI stereo-only commands.
* Contributed by Ben Evans (Ben.Evans@anusf.anu.edu.au)
*/
TOGL_EXTERN void Togl_OldStereoDrawBuffer(GLenum mode);
TOGL_EXTERN void Togl_OldStereoClear(GLbitfield mask);
# endif
TOGL_EXTERN void Togl_StereoFrustum(GLfloat left, GLfloat right, GLfloat bottom,
GLfloat top, GLfloat near, GLfloat far, GLfloat eyeDist,
GLfloat eyeOffset);
/*
* Generate EPS file.
* Contributed by Miguel A. De Riera Pasenau (miguel@DALILA.UPC.ES)
*/
TOGL_EXTERN int Togl_DumpToEpsFile(const Togl *togl, const char *filename,
int inColor, void (*user_redraw) (const Togl *));
# ifdef TOGL_AGL_CLASSIC
/*
* Mac-specific setup functions
*/
extern int Togl_MacInit(void);
extern int Togl_MacSetupMainInterp(Tcl_Interp *interp);
# endif
# ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
# endif
#endif

View File

@ -8,6 +8,9 @@ try:
from webgui_jupyter_widgets import BaseWebGuiScene, WebGuiDocuWidget
import webgui_jupyter_widgets.widget as wg
except ImportError:
class BaseWebGuiScene:
pass
wg = None
def encodeData( data, dtype=None, encoding='b64' ):
@ -214,9 +217,13 @@ def GetData(mesh, args, kwargs):
d[name] = pnew
return d
base = object if wg is None else BaseWebGuiScene
class WebGLScene(base):
class WebGLScene(BaseWebGuiScene):
class Widget:
def __init__(self):
self.value = {}
def __init__(self, obj, args=[], kwargs={}):
self.widget = self.Widget()
self.obj = obj
self.args = args
self.kwargs = kwargs
@ -414,12 +421,29 @@ def Draw(obj, *args, show=True, **kwargs):
scene.GenerateHTML(filename=kwargs_with_defaults["filename"])
return scene
async def _MakeScreenshot(data, png_file, width=1200, height=600):
"""Uses playwright to make a screenshot of the given html file."""
# pylint: disable=import-outside-toplevel
from playwright.async_api import async_playwright
from webgui_jupyter_widgets.html import GenerateHTML, getScreenshotHTML
html_file = png_file + ".html"
GenerateHTML(data, filename=html_file, template=getScreenshotHTML())
async with async_playwright() as play:
browser = await play.chromium.launch()
page = await browser.new_page(viewport={"width": width, "height": height})
await page.goto(f"file://{os.path.abspath(html_file)}")
await page.screenshot(path=png_file)
await browser.close()
def _DrawDocu(obj, *args, **kwargs):
import json
import asyncio
kwargs_with_defaults = _get_draw_default_args()
kwargs_with_defaults.update(kwargs)
scene = WebGLScene(obj, args, kwargs_with_defaults)
import json
docu_path = os.environ["NETGEN_DOCUMENTATION_OUT_DIR"]
src_path = os.environ["NETGEN_DOCUMENTATION_SRC_DIR"]
@ -447,7 +471,7 @@ def _DrawDocu(obj, *args, **kwargs):
scene.widget = widget
data = scene.GetData()
json.dump(data, open(data_file_abs, "w"))
scene.MakeScreenshot(preview_file_abs, 1200, 600)
asyncio.run(_MakeScreenshot(data, preview_file_abs, 1200, 600))
scene.Redraw = lambda: None
from IPython.display import display, HTML
@ -456,6 +480,10 @@ def _DrawDocu(obj, *args, **kwargs):
if "NETGEN_DOCUMENTATION_SRC_DIR" in os.environ:
# use nest_asyncio to allow reentrant asyncio when executing jupyter notebooks
import nest_asyncio
nest_asyncio.apply()
# we are buiding the documentation, some things are handled differently:
# 1) Draw() is generating a .png (using headless chromium via selenium) and a render_data.json
# to show a preview image and load the render_data only when requested by user