Import Geant4 10.6.0 source tree
This commit is contained in:
@@ -22,6 +22,7 @@ endif()
|
||||
|
||||
add_subdirectory(accumulables)
|
||||
add_subdirectory(csv)
|
||||
add_subdirectory(factory)
|
||||
add_subdirectory(g4tools)
|
||||
add_subdirectory(hntools)
|
||||
add_subdirectory(management)
|
||||
@@ -38,6 +39,7 @@ if(NOT GEANT4_BUILD_GRANULAR_LIBS)
|
||||
COMPONENTS
|
||||
accumulables/sources.cmake
|
||||
csv/sources.cmake
|
||||
factory/sources.cmake
|
||||
g4tools/sources.cmake
|
||||
hdf5/sources.cmake
|
||||
hntools/sources.cmake
|
||||
@@ -50,6 +52,7 @@ if(NOT GEANT4_BUILD_GRANULAR_LIBS)
|
||||
COMPONENTS
|
||||
accumulables/sources.cmake
|
||||
csv/sources.cmake
|
||||
factory/sources.cmake
|
||||
g4tools/sources.cmake
|
||||
hntools/sources.cmake
|
||||
management/sources.cmake
|
||||
|
||||
@@ -17,8 +17,8 @@ endif
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
|
||||
SUBDIRS = g4tools management hntools csv root xml accumulables
|
||||
SUBLIBS = G4tools G4analysismng G4hntools G4csv G4root G4xml G4accumulables
|
||||
SUBDIRS = g4tools management hntools csv root xml factory accumulables
|
||||
SUBLIBS = G4tools G4analysismng G4hntools G4csv G4root G4xml G4analysisfac G4accumulables
|
||||
|
||||
include $(G4INSTALL)/config/globlib.gmk
|
||||
|
||||
|
||||
@@ -16,6 +16,84 @@ committal in the SVN repository !
|
||||
* Reverse chronological order (last date on top), please *
|
||||
----------------------------------------------------------
|
||||
|
||||
December 3, 2019 Hrivnacova (analysis-V10-05-13)
|
||||
- Use consistently the same default value of rowMode
|
||||
in G4RootAnalysisManager::SetNtupleRowWise() as defined in the
|
||||
G4VAnalysisManager base class.
|
||||
|
||||
November 19, 2019 G. Cosmo (analysis-V10-05-12)
|
||||
- Fixed more cases of implicit type conversions.
|
||||
|
||||
November 17, 2019 Hrivnacova (analysis-V10-05-11)
|
||||
- Updated to g4tools 5.0.5 (Guy Barrand):
|
||||
Fixed compilation warning from gl2ps showing up on gcc-9.2.
|
||||
See History_tools for the complete list of modifications.
|
||||
|
||||
November 15, 2019 G. Cosmo (analysis-V10-05-10)
|
||||
- Fixed cases of implicit type conversions from size_t to G4int.
|
||||
|
||||
November 11, 2019 B. Morgan (analysis-V10-05-09)
|
||||
- Link directly to FreeType and HDF5 impormted targets
|
||||
|
||||
November 8, 2019 I. Hrivnacova (analysis-V10-05-08)
|
||||
- In G4PlotManager: Disabled PAW encoding
|
||||
(this fixes a problem with unwanted axis labels in Greek)
|
||||
- Updated to g4tools 5.0.4 (Guy Barrand):
|
||||
- sg/plotter: added function set_encoding(), set_encoding_none() which allow
|
||||
to disable (unwanted) paw specific encoding
|
||||
- Fixed Coverity warnings
|
||||
|
||||
October 21, 2019 I. Hrivnacova (analysis-V10-05-07)
|
||||
- Added fRowWise data member in G4RootNtupleManager to make the parameter
|
||||
available in MPI
|
||||
|
||||
October 17, 2019 I. Hrivnacova (analysis-V10-05-06)
|
||||
- Updated to g4tools 5.0.2 (Guy Barrand):
|
||||
Handle axis label of format "10^%d?" in case of freetype font.
|
||||
|
||||
October 14, 2019 I. Hrivnacova (analysis-V10-05-05)
|
||||
- Enhanced the G4VAnalysisManager interface:
|
||||
- Added new option for ntuple merging and updated/added functions for merging:
|
||||
- SetNtupleMerging(): removed rowWise and basketSize optional paremeters
|
||||
- SetNtupleRowWise(): added parameter 'rowMode' with a default value
|
||||
- SetBasketSize(), SetBasketEntries(): new methods
|
||||
- Added functions and UI commands for setting axis log scale for plotting:
|
||||
- Set[H,P][1,2,3][X,Y.Z]AxisIsLog()
|
||||
and analoguos getters
|
||||
- New UI commands
|
||||
/analysis/[h,p][1,2,3]/set[X,Y,Z]axisLog true|false
|
||||
- Fix in g4tools for axis labels with log scale
|
||||
|
||||
October 9, 2019 I. Hrivnacova (analysis-V10-05-04)
|
||||
- Updated to g4tools 5.0.1 (Guy Barrand):
|
||||
- ROOT format : restore a "per event/row view" for the ntuple column-wise in MT and MPI.
|
||||
- batch plotting : fixes to avoid labels overlap when having a grid of plotters.
|
||||
- MPI : fix a memory leak.
|
||||
- scene graph : have material for interactive plotting.
|
||||
- include modifications coming from other usage of inlib/exlib, for example, in rroot, to be able to read TClonesArray.
|
||||
See History_tools for the complete list of modifications.
|
||||
|
||||
September 24, 2019 I. Hrivnacova (analysis-V10-05-03)
|
||||
- Fix in g4tools:
|
||||
- mpi_create_basket: fixed memory leak (Guy Barrand)
|
||||
|
||||
September 10, 2019 I. Hrivnacova (analysis-V10-05-02)
|
||||
- Added new factory function G4Analysis::ManagerInstance():
|
||||
which allows to create the analysis manager of the type selected via a string argument; example of the user code:
|
||||
#include "g4analysis.hh"
|
||||
G4AnalysisManager* analysisManager = G4Analysis::ManagerInstance("root");
|
||||
|
||||
Note that G4AnalysisManager is in this case G4ToolsAnalysisManager, and not
|
||||
the output type specific manager (eg. G4RootAnalysisManager), as it is
|
||||
in case of using a type specific include, eg. "g4root.hh"
|
||||
|
||||
Details:
|
||||
- Added new analysis sub-category "factory"
|
||||
- Clean-up analysis type definitions:
|
||||
G4Hn*, G4Pn* types moved out of type specific namespace
|
||||
- Added methods for setting ntuple merge mode in G4VAnalysisManager
|
||||
with a default implementatation (issuing a warning if merging is not available)
|
||||
|
||||
June 12, 2019 I. Hrivnacova (analysis-V10-05-01)
|
||||
- Fixed CSV, XML ntuple file names
|
||||
|
||||
|
||||
@@ -1,3 +1,185 @@
|
||||
5.0.5:
|
||||
- tools/gl2ps : gl2psPDFgroupListWriteXObjectResources : add a break at end of case GL2PS_PIXMAP.
|
||||
|
||||
5.0.4:
|
||||
- tools/sg/vertices : fix a shadow warning in the add(vector<float>&) method.
|
||||
|
||||
5.0.3:
|
||||
- tools/gl2ps : tools_gl2psPrintPostScriptPixmap : quiet coverity.
|
||||
- tools/rroot/vector3 : quiet coverity about uninited variables.
|
||||
- tools/zb/buffer : get_pixel() : quiet coverity : set a_pixel=0 in case args out of range.
|
||||
- tools/sg/text : quiet coverity : a bxw => bxh.
|
||||
- tools/sg/axis, sg/plotter : set_encoding(), set_encoding_none().
|
||||
- tools/sg/render_gsots : init fields in cp cstor and operator=.
|
||||
- tools/sg/plotter : add fields : title_box_[width,height,x_margin,y_margin].
|
||||
|
||||
5.0.2:
|
||||
- tools/sg/tools : add_string_opt : handle axis label of format "10^%d?" in case of freetype font.
|
||||
|
||||
5.0.1 :
|
||||
- gl2ps_def.h, gl2ps_begin.icc, Xt/OpenGLArea.c : /*/////*/ => /*-----*/.
|
||||
- lina/vec3, vec3f : cos_angle.
|
||||
|
||||
5.0.0 : ROOT format : restore a "per event/row view" for the ntuple column-wise in MT and MPI.
|
||||
batch plotting : fixes to avoid labels overlap when having a grid of plotters.
|
||||
MPI : fix a memory leak.
|
||||
scene graph : have material for interactive plotting.
|
||||
include modifications coming from other usage of inlib/exlib, for example, in rroot, to be able to read TClonesArray.
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// ROOT file format : ///////////////////////////
|
||||
/// restore event view in MT/MPI column_wise : ///
|
||||
//////////////////////////////////////////////////
|
||||
- wroot/base_pntuple, base_pntuple_column_wise, branch, ntuple,
|
||||
mpi_basket_add, mpi_ntuple_column_wise, mpi_ntuple_row_wise, mpi_send_basket, mpi_protocol,
|
||||
mt_ntuple_column_wise, mt_ntuple_row_wise, mt_basket_add, :
|
||||
modification to handle the staging of baskets in MT and MPI
|
||||
(stored in in branch::std::vector<basket*> m_parallel_baskets;)
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// ROOT file format : ///////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
- wroot/ntuple : mpi_add_basket : have "delete basket" in case some "branch.add_basket" failed.
|
||||
- wroot/directory : keys() getter.
|
||||
- wroot/file, infos : StreamerInfo => streamer_info.
|
||||
- wroot/info : StreamerInfo => streamer_info. Then have consistent casing relative to the rest for this class.
|
||||
- wroot/element : streamer_info => streamer__info : in order to reuse the name for our reimplementation
|
||||
of "TStreamerInfo" (then streamer_info for us) class.
|
||||
|
||||
- rroot/buffer : m_map_objs(true) : have obj in map the default when reading.
|
||||
- rroot/info, cids, streamers : as for wroot, StreamerInfo => streamer_info to have consistent casing.
|
||||
- rroot/info : in stream() : handle "obj_created" after pointer_stream().
|
||||
- rroot/THistogram, rall : to handle old OpenScientist/AIDA files.
|
||||
- rroot/tree_manip : find_tree : handle a_map_objs argument, to be able to control if read objects are handled in the buffer map or not.
|
||||
- rroot/ifac, fac, iros, obj_list, hash_list, obj_array, streamers, branch, tree : a factory does not handle the ownership of object. (Having
|
||||
that introduced a lot of confusion about the ownership of read objects when implementing the "clone array" logic). Now iros, list, obj_array
|
||||
handle (or not) the ownership of what they read (according to what buffer.read_object returns).
|
||||
- rroot/buffer : pointer_stream() : return (in "a_created" argument) if object had been created (by a factory) or not (existing in buffer map)).
|
||||
- rroot/buffer : dummy_TXxx_pointer_stream : if object created, delete it.
|
||||
- rroot/ntuple : read::intuple => read::icol(a_from) in copy constructors of columns.
|
||||
- rroot/ntuple : title(), number_of_entries() : implementation of the virtual intuple methods.
|
||||
- rrrot/branch : begin of reading clone arrays.
|
||||
- rroot/tree : be able to read "version>=20" trees.
|
||||
- rroot/vector3, cids, fac : to read TVector3.
|
||||
- rroot/list => obj_list.
|
||||
- rroot/file : dump_streamer_infos(), find_streamer_info(), read_streamer_infos_data() : to read TClonesArray of TVector3 in a generic way.
|
||||
- rroot/branch_element : to read TClonesArray of TVector3 in a generic way.
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// around graphics : ////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
- new files :
|
||||
o tools/sg/GL_action, GL_viewer, base_tex, blend, cloud2plot, cloud2plot_cp, cursor_shape, ellipse, f2plot
|
||||
fit2plot, gl, gstos_add, h2plot_cp, GL_plots_viewer, plotter_style, render_gstos, render_manager, tex_quadrilateral
|
||||
tex_rect, xy2plot, zb_action, zb_manager.
|
||||
o tools/curve, glbuf, OpenGL, plotter_common.icc.
|
||||
o tools/hdf5/group_exits.
|
||||
o tools/Qt/plots_glarea.
|
||||
o tools/Xt/OpenGLarea[.h,P.h,c], tools.
|
||||
o tools/X11/base_session,session,dispatcher.
|
||||
o for plotter printing : image, image_reader, paper_format, xpm, jpeg, png.
|
||||
- sg/axis : two new fields to avoid label overlapping :
|
||||
labels_no_overlap_automated (true by default)
|
||||
labels_gap : amount of gap to set betwen labels when removing overlaps.
|
||||
- sg/viewer : use cursor_shape include (instead of local enum).
|
||||
- sg/viewer : get_clear_color().
|
||||
- sg/vertices, atb_vertices : have the gstos mode (to store primitives in GPU) on vertices.
|
||||
- sg/field, field_desc, snode, vertices, torche, text_hershey, text_freetype, text, ortho, normal, style, plots, matrix, plotter, rgba, markers,
|
||||
line_set, line_style, legend, infos_box, holder, atb_vertices, axis, back_area, _switch, base_camera, base_text, draw_style :
|
||||
use a thread safe way to declare fields in node_desc_fields().
|
||||
- sg/text, text_freetype, style, text_valop, text_style, style_parser, infos_box : handle modeling font_pixmap.
|
||||
- sg/state, render_action, GL_manager : handle GL_BLEND.
|
||||
- sg/* : gl_manager => render_manager. manager_zb => zb_manager. render_zb => zb_action.
|
||||
- sg/sf_mat4f : set_rotate.
|
||||
- sg/strings : more global strings for sg_serv mode.
|
||||
- sg/plots : handle layout logic in set_plotter_layout() method.
|
||||
- sg/plotter, plottables : handle primitive_ellipse plottable.
|
||||
- sg/group : clear() : use safe_reverse_clear().
|
||||
- sg/primitive_visitor : add_texture().
|
||||
- sg/event : be able to cast by id (more faster than string).
|
||||
- sg/cube : inherit render_gsto to handle gsto.
|
||||
- sg/draw_style : enum e_style => draw_type.
|
||||
- sg/glprims : add utilities line_strip_to_lines(), line_loop_to_lines(), triangle_fan_to_triangles[_2to3]() methods.
|
||||
- columns : following a Coverity report (99671), handle "tree*" instead of "tree" in the std::vector m_sub field of class tree.
|
||||
- sg/line_style : from/to string : width, pattern on sp.width, pattern.
|
||||
- sg/style_parser : handle width, pattern.
|
||||
- sg/axis, plotter : touched, reset_touched by taking into account styles.
|
||||
- sg/node : touched, reset_touched virtual. For axis and plotter.
|
||||
- sg/gl2ps_action : a gl2ps render action using the below pure header gl2ps.
|
||||
- gl2ps, gl2ps_def.h, gl2ps_begin.icc, gl2ps_end.icc : pure header gl2ps.
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// around histos, nutples : /////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
- tools/aida_ntuple, xml/aidas : cols() => columns(). columns() => number_of_columns().
|
||||
- tools/aida_ntuple : column_min(), column_max().
|
||||
- tools/ntuple_binding : add_column_vec().
|
||||
- tools/ntuple_booking : add_column_vec(), add_column(T& user variable).
|
||||
- tools/rcsv_ntuple : add title(). number_of_entries() methods.
|
||||
- tools/rntuple : intuple : virtual tile(), number_of_entries() methods.
|
||||
- tools/rntuple : add methods number_of_columns, column_names, find_icol_case_insensitive, find_column, column_is_of_type, column_min,max.
|
||||
- tools/histo/base_histo : add get_Sw_Sw2, get_all_Sw_Sw2 methods.
|
||||
- tools/histo/p1 : add set_bin_content, get_bin_content methods. (It permits a "full access" to all infos of a bin).
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// hdf5 : ///////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
- tools/hdf5 :
|
||||
T_tools, ntuple, pages : handle "vlen" variable length array.
|
||||
store : in write mode, add "type" "object" attribute. Increment write version number (1 =>2).
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// various : ////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
- tools/zlib : have the TOOLS_USE_OUREX_ZLIB logic.
|
||||
- tools/xml/styles : handle "copy" keyword.
|
||||
- tools/args : insert_begin() to insert an arg at head of list.
|
||||
- tools/args : file() to get the last argument as a file name.
|
||||
- tools/test : have const ref (instead of const only).
|
||||
- tools/vmanip : use size_t.
|
||||
- tools/strip : handle "all chars are the same" case.
|
||||
- tools/value : m_id => m_itag.
|
||||
- tools/mathd : dcos, dsin, dpow, ldfabs (not on ANDROID).
|
||||
- tools/mapmanip : add_unique().
|
||||
- tools/glutess/* : GLU_[FALSE,TRUE] => TOOLS_GLU_[FALSE,TRUE] to avdoid clash with glu.h.
|
||||
- tools/cmathT : remove.
|
||||
- tools/colorf : handle cpp TOOLS_MEM_ATEXIT if wanting to have a correct counting of statics with TOOLS_MEM at exit.
|
||||
- tools/colorfs : in cpp TOOLS_COLORFS_STAT remove not used r,g,b arguments.
|
||||
- tools/colors : add (some of) CERN-ROOT colors.
|
||||
- tools/cstr : add str_lcpy().
|
||||
- tools/eqT : add vector_are_equal().
|
||||
- tools/file : add is_kumac().
|
||||
- tools/file_format : handle .kumac extension.
|
||||
- tools/system : iOS : do not compile ::system().
|
||||
- tools/system : execute() => std_system(). repenv() => rep_env().
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// test programs (test/cpp) : ///////////////////
|
||||
//////////////////////////////////////////////////
|
||||
- utest*.ps, wrap*_ps : new versions to take into account modifications to avoid automatically overlap of labels
|
||||
in each plotter when having a grid of plotters.
|
||||
- read_root.iccc, mpi_ntuple.cpp, mt_ntuple.cpp, mt_ntuple_ref.cpp, mt_ntuple_seq.cpp :
|
||||
arguments -row_mode, -basket_entries and flag row_wise => read_check_row_wise : to be able to handle various writting
|
||||
mode of ntuple (column-wise, column-wise-row-mode, row-wise).
|
||||
- wcsv_histo.cpp : -no_header argument.
|
||||
- build, vc++, find_link_exe, use_* : use the vc++ shell script to build with VisualC++.
|
||||
It permits to build on CYGWIN but also on WSL (Microsoft/ubuntu) by using VisualC++.
|
||||
- rroot.cpp, wroot.cpp, utest.cpp, rxrayfluo.cpp : handle TOOLS_MEM to be able, if built with "-mem", to have a decount, at end,
|
||||
of created/deleted objects. (If all is ok, the decount should be "0", and nothing be printed).
|
||||
- raxml.cpp : cols() => columns().
|
||||
- hdf5_histos.cpp : test handling of a directory.
|
||||
- threads : have exit_set() to handle with mutex.lock the query of "a_args.m_exit".
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
4.2.3 :
|
||||
- test/cpp/use_freetype : -DDTOOLS_USE_OUREX_FREETYPE => -DTOOLS_USE_OUREX_FREETYPE.
|
||||
- test/cpp/test/build : be able to have -our_freetype to not use system freetype.
|
||||
Used at LAL for utest unitary tests using freetype in order to compare with
|
||||
reference .ps files produced on macOS with ourex/freetype.
|
||||
- test/cpp/test/use_freetype : handle build_use_our_freetype variable.
|
||||
|
||||
4.2.3 :
|
||||
- tools/sg/text_freetype : g++-8.1.0 : use the functions introduced below in glutess.
|
||||
- tools/tess_contour : g++-8.1.0 : use the functions introduced below in glutess.
|
||||
|
||||
@@ -104,7 +104,7 @@ G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
||||
//_____________________________________________________________________________
|
||||
inline G4int G4AccumulableManager::GetNofAccumulables() const
|
||||
{
|
||||
return fVector.size();
|
||||
return G4int(fVector.size());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
@@ -70,6 +70,9 @@ G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
|
||||
case G4MergeMode::kMinimum:
|
||||
// return std::bind([](const T& x, const T& y) { return std::min(x,y);});
|
||||
return [](const T& x, const T& y) { return std::min(x,y); };
|
||||
|
||||
default:
|
||||
return [](const T&, const T&) { return 0.0; };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,44 +29,13 @@
|
||||
#ifndef g4csv_defs_h
|
||||
#define g4csv_defs_h
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/wcsv_ntuple"
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4CsvAnalysisReader.hh"
|
||||
#include "g4hntools_defs.hh"
|
||||
|
||||
namespace G4Csv {
|
||||
|
||||
// H1 types
|
||||
using G4AnaH1 = tools::histo::h1d; // keep for backward compatibility
|
||||
using G4H1 = tools::histo::h1d;
|
||||
using G4H1Iterator = std::vector<tools::histo::h1d*>::iterator;
|
||||
using G4H1ConstIterator = std::vector<tools::histo::h1d*>::const_iterator;
|
||||
|
||||
// H2 types
|
||||
using G4AnaH2 = tools::histo::h2d; // keep for backward compatibility
|
||||
using G4H2 = tools::histo::h2d;
|
||||
using G4H2Iterator = std::vector<tools::histo::h2d*>::iterator;
|
||||
using G4H2ConstIterator = std::vector<tools::histo::h2d*>::const_iterator;
|
||||
|
||||
// H3 types
|
||||
using G4H3 = tools::histo::h3d;
|
||||
using G4H3Iterator = std::vector<tools::histo::h3d*>::iterator;
|
||||
using G4H3ConstIterator = std::vector<tools::histo::h3d*>::const_iterator;
|
||||
|
||||
// P1 types
|
||||
using G4P1 = tools::histo::p1d;
|
||||
using G4P1Iterator = std::vector<tools::histo::p1d*>::iterator;
|
||||
using G4P1ConstIterator = std::vector<tools::histo::p1d*>::const_iterator;
|
||||
|
||||
// P2 types
|
||||
using G4P2 = tools::histo::p2d;
|
||||
using G4P2Iterator = std::vector<tools::histo::p2d*>::iterator;
|
||||
using G4P2ConstIterator = std::vector<tools::histo::p2d*>::const_iterator;
|
||||
|
||||
namespace G4Csv
|
||||
{
|
||||
// Ntuple types
|
||||
using G4Ntuple = tools::wcsv::ntuple;
|
||||
using G4NtupleIterator = std::vector<tools::wcsv::ntuple*>::iterator;
|
||||
@@ -78,5 +47,3 @@ namespace G4Csv {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
Analysis_F001: Fatal exception when trying to create a singleton manager twice
|
||||
|
||||
Analysis_F002: Fatal exception when selecting non-existing output type.
|
||||
|
||||
Analysis_W001: Cannot create file or directory for output
|
||||
|
||||
Analysis_W002: Cannot create an object for output
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# CMakeLists.txt
|
||||
# Module : G4analysis
|
||||
# Package: Geant4.src.G4analysis.G4analysismng
|
||||
#
|
||||
# CMakeLists.txt for building a single granular library.
|
||||
#
|
||||
# Created on : 15/07/2013
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
if(GEANT4_BUILD_GRANULAR_LIBS)
|
||||
include(Geant4MacroLibraryTargets)
|
||||
GEANT4_GRANULAR_LIBRARY_TARGET(COMPONENT sources.cmake)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# --------------------------------------------------------------------
|
||||
# GNUmakefile for analysis/management sub-library.
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
name := G4analysisfac
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../..
|
||||
endif
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
|
||||
CPPFLAGS += -I$(G4BASE)/global/management/include \
|
||||
-I$(G4BASE)/intercoms/include \
|
||||
-I$(G4BASE)/analysis/g4tools/include \
|
||||
-I$(G4BASE)/analysis/management/include \
|
||||
-I$(G4BASE)/analysis/hntools/include \
|
||||
-I$(G4BASE)/analysis/csv/include \
|
||||
-I$(G4BASE)/analysis/root/include \
|
||||
-I$(G4BASE)/analysis/xml/include
|
||||
|
||||
include $(G4INSTALL)/config/common.gmk
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 10/09/2019 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef g4analysis_h
|
||||
#define g4analysis_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "g4analysis_defs.hh"
|
||||
|
||||
namespace G4Analysis
|
||||
{
|
||||
|
||||
G4ToolsAnalysisManager* ManagerInstance(const G4String& outputType);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 10/09/2019 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef g4analysis_defs_h
|
||||
#define g4analysis_defs_h 1
|
||||
|
||||
#include "g4hntools_defs.hh"
|
||||
#include "G4ToolsAnalysisManager.hh"
|
||||
|
||||
using G4AnalysisManager = G4ToolsAnalysisManager;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
Added new factory function which allows to create analysis manager
|
||||
of the type selected via a string argument; the user code:
|
||||
#include "g4analysis.hh"
|
||||
G4AnalysisManager* analysisManager = G4Analysis::ManagerInstance("root");
|
||||
|
||||
Note that G4AnalysisManager is in this case G4ToolsAnalysisManager, and not
|
||||
the output type specific manager (eg. G4RootAnalysisManager), as it is
|
||||
in case of using a type specific include, eg. "g4root.hh"
|
||||
|
||||
Details:
|
||||
- Added new analysis sub-category "factory"
|
||||
- Clean-up analysis type definitions:
|
||||
G4Hn*, G4Pn* types moved out of type specific namespace
|
||||
- Added methods for setting ntuple merge mode in G4VAnalysisManager
|
||||
with a default implementatation (issuing a warning if merging is not available)
|
||||
@@ -0,0 +1,61 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# sources.cmake
|
||||
# Module : G4csv
|
||||
# Package: Geant4.src.G4analysis.G4analysismng
|
||||
#
|
||||
# Sources description for a library.
|
||||
# Lists the sources and headers of the code explicitely.
|
||||
# Lists include paths needed.
|
||||
# Lists the internal granular and global dependencies of the library.
|
||||
# Source specific properties should be added at the end.
|
||||
#
|
||||
# Generated on : 15/07/2013
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# List external includes needed.
|
||||
include_directories(${CLHEP_INCLUDE_DIRS})
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
if (GEANT4_USE_HDF5)
|
||||
include_directories(${HDF5_INCLUDE_DIRS})
|
||||
set(G4analysisfac_LINK_LIBRARIES Geant4::HDF5)
|
||||
endif()
|
||||
if(GEANT4_USE_FREETYPE)
|
||||
set(G4analysisfac_LINK_LIBRARIES Freetype::Freetype ${G4analysisfac_LINK_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# List internal includes needed.
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/global/management/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/intercoms/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/g4tools/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/management/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/hntools/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/csv/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/root/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/xml/include)
|
||||
if (GEANT4_USE_HDF5)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/hdf5/include)
|
||||
endif()
|
||||
|
||||
#
|
||||
# Define the Geant4 Module.
|
||||
#
|
||||
include(Geant4MacroDefineModule)
|
||||
GEANT4_DEFINE_MODULE(NAME G4analysisfac
|
||||
HEADERS
|
||||
g4analysis.hh
|
||||
g4analysis_defs.hh
|
||||
SOURCES
|
||||
g4analysis.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
G4globman
|
||||
G4intercoms
|
||||
GLOBAL_DEPENDENCIES
|
||||
G4global
|
||||
G4intercoms
|
||||
LINK_LIBRARIES
|
||||
${G4analysisfac_LINK_LIBRARIES}
|
||||
)
|
||||
|
||||
# List any source specific properties here
|
||||
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 09/09/2019 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "g4analysis.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4RootAnalysisManager.hh"
|
||||
#include "G4XmlAnalysisManager.hh"
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
#include "G4Hdf5AnalysisManager.hh"
|
||||
#endif
|
||||
#include "G4Exception.hh"
|
||||
|
||||
namespace {
|
||||
|
||||
void DoFatalException(const G4String& outputName)
|
||||
{
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " \"" << outputName << "\" output type is not supported." << G4endl
|
||||
<< " " << "Analysis manager cannot be created.";
|
||||
G4Exception("G4Analysis::ManagerInstance",
|
||||
"Analysis_F002", FatalException, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace G4Analysis
|
||||
{
|
||||
|
||||
G4ToolsAnalysisManager* ManagerInstance(const G4String& outputName)
|
||||
{
|
||||
// Get output type
|
||||
G4AnalysisOutput outputType = GetOutput(outputName, false);
|
||||
if ( outputType == G4AnalysisOutput::kNone ) {
|
||||
DoFatalException(outputName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create the analysis manager of a selected type
|
||||
switch ( outputType ) {
|
||||
case G4AnalysisOutput::kCsv:
|
||||
return G4CsvAnalysisManager::Instance();
|
||||
break;
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
return G4Hdf5AnalysisManager::Instance();
|
||||
break;
|
||||
#endif
|
||||
case G4AnalysisOutput::kRoot:
|
||||
return G4RootAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kXml:
|
||||
return G4XmlAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kNone:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// should never reach this line
|
||||
DoFatalException(outputName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,11 @@ private:\
|
||||
typedef a__parent parent;\
|
||||
public:\
|
||||
TOOLS_SCLASS(a__sclass)\
|
||||
/*public:\
|
||||
static bool is_a(const std::string& a_class) {\
|
||||
if(!rcmp(a_class,s_class())) return true;\
|
||||
return parent::is_a(a_class);\
|
||||
}*/\
|
||||
public:\
|
||||
virtual void* cast(const std::string& a_class) const {\
|
||||
if(void* p = tools::cmp_cast<a__class>(this,a_class)) return p;\
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_OpenGL
|
||||
#define tools_OpenGL
|
||||
|
||||
#ifdef TOOLS_TOOLS_GL
|
||||
|
||||
#include "inlib_OpenGL"
|
||||
|
||||
#else //!TOOLS_TOOLS_GL
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#include <OpenGLES/ES1/gl.h>
|
||||
#elif defined(ANDROID)
|
||||
#include <GLES/gl.h>
|
||||
#elif _WIN32
|
||||
#include <windows.h>
|
||||
#include <GL/gl.h>
|
||||
#elif __APPLE__
|
||||
#include <OpenGL/gl.h> //Cocoa
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#endif //TOOLS_TOOLS_GL
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Qt_plots_glarea
|
||||
#define tools_Qt_plots_glarea
|
||||
|
||||
#include <QtOpenGL/qgl.h>
|
||||
|
||||
#include "../sg/GL_plots_viewer"
|
||||
|
||||
namespace tools {
|
||||
namespace Qt {
|
||||
|
||||
class plots_glarea : public QGLWidget {
|
||||
typedef QGLWidget parent;
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual void initialieGL() {}
|
||||
virtual void resizeGL(int a_w,int a_h){
|
||||
//::printf("debug : resize : %d %d\n",a_w,a_h);
|
||||
#if QT_VERSION < 0x050000
|
||||
#else
|
||||
m_width = a_w;
|
||||
m_height = a_h;
|
||||
#endif
|
||||
}
|
||||
//virtual void paintGL();
|
||||
virtual void paintGL() {
|
||||
#if QT_VERSION < 0x050000
|
||||
//::printf("debug : exlib::Qt::plots_glarea::paintGL %d %d\n",width(),height());
|
||||
m_viewer.set_size(width(),height());
|
||||
#else
|
||||
//::printf("debug : exlib::Qt::plots_glarea::paintGL %d %d\n",m_width,m_height);
|
||||
m_viewer.set_size(m_width,m_height);
|
||||
#endif
|
||||
m_viewer.render();
|
||||
}
|
||||
|
||||
virtual void mousePressEvent(QMouseEvent*){}
|
||||
virtual void mouseReleaseEvent(QMouseEvent*){}
|
||||
virtual void mouseMoveEvent(QMouseEvent*){}
|
||||
public:
|
||||
plots_glarea(QWidget* a_parent,tools::sg::GL_plots_viewer& a_viewer):parent(a_parent),m_viewer(a_viewer){}
|
||||
virtual ~plots_glarea(){}
|
||||
protected:
|
||||
tools::sg::GL_plots_viewer& m_viewer;
|
||||
#if QT_VERSION < 0x050000
|
||||
#else
|
||||
protected:
|
||||
int m_width;
|
||||
int m_height;
|
||||
#endif
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -66,4 +66,11 @@ static const std::string& s_class() {\
|
||||
}\
|
||||
static void check_class_name() {a_name<a_T1,a_T2,a_T3>::s_class();}
|
||||
|
||||
// to transform the value of a cpp macro to a string :
|
||||
#define TOOLS_CPP_TO__STRING(a_cpp) #a_cpp
|
||||
#define TOOLS_CPP_TO_STRING(a_cpp) std::string(TOOLS_CPP_TO__STRING(a_cpp))
|
||||
// for example :
|
||||
// #define FOO foo
|
||||
// std::cout << TOOLS_CPP_TO_STRING(FOO) << std::endl;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,810 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Windows_WinTk
|
||||
#define tools_Windows_WinTk
|
||||
|
||||
#include "../Windows/tools" //and not "tools", because this fancy VisualC++ will not find the file!
|
||||
|
||||
#include <tools/touplow>
|
||||
#include <tools/words>
|
||||
#ifdef TOOLS_MEM
|
||||
#include <tools/mem>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace tools {
|
||||
namespace WinTk {
|
||||
|
||||
class Component;
|
||||
|
||||
class CallbackData {
|
||||
public:
|
||||
CallbackData():x(0),y(0),wparam(0),lparam(0){}
|
||||
public:
|
||||
std::string value;
|
||||
int x;
|
||||
int y;
|
||||
WPARAM wparam;
|
||||
LPARAM lparam;
|
||||
};
|
||||
|
||||
typedef void (*Callback)(Component&,CallbackData&,void*);
|
||||
|
||||
class Component {
|
||||
typedef std::vector< std::pair<Callback,void*> > Callbacks;
|
||||
typedef std::pair<std::string,Callbacks> NamedCallbacks;
|
||||
#ifdef TOOLS_MEM
|
||||
TOOLS_SCLASS(exlib::WinTk::Component)
|
||||
#endif
|
||||
public:
|
||||
Component(const std::string& aType):fType(aType),fWindow(0),fParent(0){
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
Component(const std::string& aType,Component& aParent):fType(aType),fWindow(0),fParent(&aParent) {
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
virtual ~Component() {
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
protected:
|
||||
Component(Component&) {
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
Component& operator=(Component&) {return *this;}
|
||||
public:
|
||||
std::string name() const {return fName;}
|
||||
void setName(const std::string& aName) {fName = aName;}
|
||||
|
||||
const std::string& type() const {return fType;}
|
||||
HWND nativeWindow() {return fWindow;}
|
||||
Component* parent() const {return fParent;}
|
||||
virtual void show() {
|
||||
//if(!fWindow) return;
|
||||
//::ShowWindow(fWindow,SW_SHOWDEFAULT);
|
||||
}
|
||||
void hide() {
|
||||
if(!fWindow) return;
|
||||
::ShowWindow(fWindow,SW_HIDE);
|
||||
}
|
||||
|
||||
virtual bool size(unsigned int& aWidth,unsigned int& aHeight) {
|
||||
aWidth = 0;
|
||||
aHeight = 0;
|
||||
if(!fWindow) return false;
|
||||
RECT rect;
|
||||
::GetClientRect(fWindow,&rect);
|
||||
aWidth = rect.right-rect.left;
|
||||
aHeight = rect.bottom-rect.top;
|
||||
return true;
|
||||
}
|
||||
virtual bool position(int& aX,int& aY) {
|
||||
aX = 0;
|
||||
aY = 0;
|
||||
if(!fWindow) return false;
|
||||
RECT rect;
|
||||
::GetClientRect(fWindow,&rect);
|
||||
aX = rect.left;
|
||||
aY = rect.top;
|
||||
return true;
|
||||
}
|
||||
Component* findFather(const std::string& aType) {
|
||||
if(aType==type()) return this;
|
||||
Component* parent = fParent;
|
||||
while(parent) {
|
||||
if(aType==parent->type()) return parent;
|
||||
parent = parent->fParent;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool setBackground(double aR,double aG,double aB){
|
||||
if(!fWindow) return false;
|
||||
|
||||
int r = int(aR*255.0);
|
||||
if((r<0)||(r>255)) return false;
|
||||
int g = int(aG*255.0);
|
||||
if((g<0)||(g>255)) return false;
|
||||
int b = int(aB*255.0);
|
||||
if((b<0)||(b>255)) return false;
|
||||
|
||||
/*
|
||||
//COLORREF cr = RGB(r,g,b);
|
||||
HBRUSH brush = ::CreateSolidBrush(RGB(r,g,b));
|
||||
::printf("debug : WinTk::Component::setBackground : brush %lu\n",brush);
|
||||
|
||||
HBRUSH prev = (HBRUSH)::GetClassLongPtr(fWindow,GCLP_HBRBACKGROUND);
|
||||
::printf("debug : WinTk::Component::setBackground : prev brush %lu\n",prev);
|
||||
|
||||
{WNDCLASSEX wc;
|
||||
::GetClassInfoEx(::GetModuleHandle(NULL),WC_STATIC,&wc);
|
||||
::printf("debug : prev brush xxx %lu\n",wc.hbrBackground);}
|
||||
|
||||
ULONG_PTR stat =
|
||||
::SetClassLongPtr(fWindow,GCLP_HBRBACKGROUND,(LONG_PTR)brush);
|
||||
if(prev && !stat) {
|
||||
::printf("debug : WinTk::Component::setBackground : SetClassLongPtr failed.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
{ULONG_PTR stat =
|
||||
::SetClassLongPtr(fWindow,GCLP_HBRBACKGROUND,(LONG_PTR)brush);
|
||||
::printf("debug : WinTk::Component::setBackground : SetClassLongPtr failed.yyy %lu.\n",stat);}
|
||||
|
||||
{WNDCLASSEX wc;
|
||||
::GetClassInfoEx(::GetModuleHandle(NULL),WC_STATIC,&wc);
|
||||
::printf("debug : prev brush yyy %lu\n",wc.hbrBackground);}
|
||||
|
||||
if(!::InvalidateRect(fWindow,NULL,TRUE)) {
|
||||
::printf("debug : WinTk::Component::setBackground : InvalidateRect failed.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
//::DeleteObject(brush);
|
||||
return true;
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
public:
|
||||
void addCallback(const std::string& aName,Callback aFunction,void* aTag) {
|
||||
NamedCallbacks* cbks = 0;
|
||||
std::vector<NamedCallbacks>::iterator it;
|
||||
for(it=fCallbacks.begin();it!=fCallbacks.end();++it) {
|
||||
if(aName==(*it).first) {
|
||||
cbks = &(*it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!cbks) {
|
||||
fCallbacks.push_back(std::pair<std::string,Callbacks>(aName,Callbacks()));
|
||||
cbks = &(fCallbacks.back());
|
||||
}
|
||||
cbks->second.push_back(std::pair<Callback,void*>(aFunction,aTag));
|
||||
}
|
||||
void removeCallback(const std::string& aName,Callback aFunction,void* aTag) {
|
||||
NamedCallbacks* cbks = 0;
|
||||
std::vector<NamedCallbacks>::iterator it;
|
||||
for(it=fCallbacks.begin();it!=fCallbacks.end();++it) {
|
||||
if(aName==(*it).first) {
|
||||
cbks = &(*it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(cbks) {
|
||||
Callbacks::iterator it;
|
||||
for(it=cbks->second.begin();it!=cbks->second.end();++it) {
|
||||
if( (aFunction==(*it).first) && (aTag==(*it).second) ) {
|
||||
cbks->second.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool executeCallbacks(const std::string& aName,CallbackData& aData) {
|
||||
std::vector<NamedCallbacks>::const_iterator it;
|
||||
for(it=fCallbacks.begin();it!=fCallbacks.end();++it) {
|
||||
if(aName==(*it).first) {
|
||||
const Callbacks& cbks = (*it).second;
|
||||
Callbacks::const_iterator it2;
|
||||
for(it2=cbks.begin();it2!=cbks.end();++it2) {
|
||||
Callback cbk = (*it2).first;
|
||||
if(cbk) {
|
||||
HWND back_fWindow = fWindow;
|
||||
cbk(*this,aData,(*it2).second);
|
||||
// The callback may have destroyed the Component and
|
||||
// the native HWND. The below checks that.
|
||||
// In a proc, it is better to not use the HWND
|
||||
// (or the Component) after calling executeCallbacks.
|
||||
if(back_fWindow && !::GetWindowLongPtr(back_fWindow,GWLP_USERDATA)) {
|
||||
//::printf("WinTk::Component::executeCallbacks : WARNING : A callback destroyed the native HWND window !\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool hasCallbacks(const std::string& aName) const {
|
||||
std::vector<NamedCallbacks>::const_iterator it;
|
||||
for(it=fCallbacks.begin();it!=fCallbacks.end();++it) {
|
||||
if(aName==(*it).first) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected:
|
||||
static void wm__destroy(HWND aWindow) {
|
||||
Component* This = (Component*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) { //How to be sure that we have a Component* ???
|
||||
if(This->fWindow!=aWindow) {
|
||||
::printf("WinTk::Component::wm_destroy : HWND mismatch !\n");
|
||||
}
|
||||
if(This->hasCallbacks("WM_DESTROY")) {
|
||||
CallbackData data;
|
||||
This->executeCallbacks("WM_DESTROY",data);
|
||||
}
|
||||
This->fWindow = 0;
|
||||
}
|
||||
::SetWindowLongPtr(aWindow,GWLP_USERDATA,LONG_PTR(NULL));
|
||||
}
|
||||
protected:
|
||||
// WM_PARENTNOTIFY is sent within the CreateWindow of the child.
|
||||
// When received by the parent, the parent Post (not Send) to itself
|
||||
// a WM_TK_CHILDCREATED in order to be notify of the child creation
|
||||
// out of any CreateWindow.
|
||||
#define WM_TK_CHILDCREATED ((WM_USER)+888)
|
||||
#define WM_TK_CHILDDELETED ((WM_USER)+889)
|
||||
#define TK_KEY 127 // To be sure that it is a message of our own.
|
||||
static LRESULT CALLBACK containerProc(HWND aWindow,UINT aMessage,WPARAM aWParam,LPARAM aLParam) {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Some child send notification message to their parent (instead of sending
|
||||
// the message to themselves !). This procedure is used by containers
|
||||
// to forward these messages to the child.
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
switch(aMessage) {
|
||||
case WM_PARENTNOTIFY:{
|
||||
if(aWParam==WM_CREATE) {
|
||||
::PostMessage(aWindow,WM_TK_CHILDCREATED,TK_KEY,0);
|
||||
return 0;
|
||||
} else if(aWParam==WM_DESTROY) {
|
||||
::PostMessage(aWindow,WM_TK_CHILDDELETED,TK_KEY,0);
|
||||
return 0;
|
||||
}
|
||||
}break;
|
||||
case WM_TK_CHILDCREATED:{
|
||||
if(aWParam==TK_KEY) {
|
||||
RECT rect;
|
||||
::GetClientRect(aWindow,&rect);
|
||||
LPARAM size = MAKELPARAM(rect.right-rect.left,rect.bottom-rect.top);
|
||||
::SendMessage(aWindow,WM_SIZE,(WPARAM)0,size);
|
||||
return 0;
|
||||
}
|
||||
}break;
|
||||
case WM_TK_CHILDDELETED:{
|
||||
if(aWParam==TK_KEY) {
|
||||
}
|
||||
}break;
|
||||
case WM_NOTIFY:{ //Coming from a child (combobox, scrollbar, toolbar).
|
||||
NMHDR* nmhdr = (NMHDR*)aLParam;
|
||||
HWND from_win = nmhdr->hwndFrom;
|
||||
if(from_win!=aWindow) {
|
||||
::SendMessage(from_win,aMessage,aWParam,aLParam);
|
||||
}
|
||||
}return 0;
|
||||
case WM_COMMAND:
|
||||
case WM_VSCROLL:
|
||||
case WM_HSCROLL:{
|
||||
::SendMessage((HWND)aLParam,aMessage,aWParam,(LPARAM)0);
|
||||
}return 0;
|
||||
}
|
||||
return TRUE; //Not handled.
|
||||
}
|
||||
#undef WM_TK_CHILDCREATED
|
||||
#undef WM_TK_CHILDDELETED
|
||||
#undef TK_KEY
|
||||
protected:
|
||||
void destroy() {
|
||||
if(hasCallbacks("delete")) {
|
||||
CallbackData data;
|
||||
executeCallbacks("delete",data);
|
||||
}
|
||||
if(fWindow) {
|
||||
::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(NULL));
|
||||
::DestroyWindow(fWindow);
|
||||
fWindow = 0;
|
||||
}
|
||||
}
|
||||
void rubberDrawLine(POINT& aBegin,POINT& aEnd) {
|
||||
if(!fWindow) return;
|
||||
HPEN pen = ::CreatePen(PS_SOLID,5,RGB(0,0,0));
|
||||
HDC hdc = ::GetWindowDC(fWindow);
|
||||
HPEN oldPen = SelectPen(hdc,pen);
|
||||
int oldROP = ::SetROP2(hdc,R2_NOT);
|
||||
POINT pt;
|
||||
::MoveToEx(hdc,aBegin.x,aBegin.y,&pt);
|
||||
::LineTo(hdc,aEnd.x,aEnd.y);
|
||||
::SetROP2(hdc,oldROP);
|
||||
SelectPen(hdc,oldPen);
|
||||
::ReleaseDC(fWindow,hdc);
|
||||
::DeletePen(pen);
|
||||
}
|
||||
void rubberDrawRect(POINT& aBegin,POINT& aEnd) {
|
||||
if(!fWindow) return;
|
||||
HPEN pen = ::CreatePen(PS_SOLID,0,RGB(0,0,0));
|
||||
HDC hdc = ::GetWindowDC(fWindow);
|
||||
HPEN oldPen = SelectPen(hdc,pen);
|
||||
int oldROP = ::SetROP2(hdc,R2_NOT);
|
||||
POINT pt;
|
||||
::MoveToEx(hdc,aBegin.x,aBegin.y,&pt);
|
||||
::LineTo(hdc,aBegin.x,aEnd.y);
|
||||
::LineTo(hdc,aEnd.x,aEnd.y);
|
||||
::LineTo(hdc,aEnd.x,aBegin.y);
|
||||
::LineTo(hdc,aBegin.x,aBegin.y);
|
||||
::SetROP2(hdc,oldROP);
|
||||
SelectPen(hdc,oldPen);
|
||||
::ReleaseDC(fWindow,hdc);
|
||||
::DeletePen(pen);
|
||||
}
|
||||
private:
|
||||
std::string fType;
|
||||
protected:
|
||||
HWND fWindow;
|
||||
Component* fParent;
|
||||
std::vector<NamedCallbacks> fCallbacks;
|
||||
std::string fName;
|
||||
};
|
||||
|
||||
class Shell;
|
||||
typedef void(*SetFocusCallback)(Shell*,void*);
|
||||
|
||||
class Shell : public Component {
|
||||
public:
|
||||
Shell(unsigned int aMask)
|
||||
:Component("Shell")
|
||||
,fFocusWindow(0)
|
||||
,fSetFocusCallback(0)
|
||||
,fSetFocusTag(0)
|
||||
,fAcceleratorTable(0)
|
||||
{
|
||||
static char sWindowClassName[] = "WinTk::Shell";
|
||||
static bool done = false;
|
||||
if(!done) {
|
||||
WNDCLASS wc;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = (WNDPROC)Shell::proc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = ::GetModuleHandle(NULL);
|
||||
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
|
||||
wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
||||
wc.lpszMenuName = sWindowClassName;
|
||||
wc.lpszClassName = sWindowClassName;
|
||||
::RegisterClass(&wc);
|
||||
done = true;
|
||||
}
|
||||
|
||||
fWindow = ::CreateWindow(sWindowClassName,
|
||||
NULL,
|
||||
aMask, //WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,CW_USEDEFAULT,
|
||||
400,400,
|
||||
NULL,NULL,
|
||||
::GetModuleHandle(NULL),
|
||||
NULL);
|
||||
if(!fWindow) return;
|
||||
::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(this));
|
||||
}
|
||||
virtual ~Shell() {
|
||||
if(fAcceleratorTable) {
|
||||
::DestroyAcceleratorTable(fAcceleratorTable);
|
||||
fAcceleratorTable = 0;
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
protected:
|
||||
Shell(Shell& a_from):Component(a_from) {}
|
||||
Shell& operator=(Shell&) {return *this;}
|
||||
public:
|
||||
virtual void show() {
|
||||
if(!fWindow) return;
|
||||
::SetForegroundWindow(fWindow);
|
||||
::ShowWindow(fWindow,SW_SHOWDEFAULT);
|
||||
::UpdateWindow(fWindow);
|
||||
::DrawMenuBar(fWindow);
|
||||
}
|
||||
void setTitle(const std::string& aString) {
|
||||
if(!fWindow) return;
|
||||
::SetWindowText(fWindow,aString.c_str());
|
||||
}
|
||||
void setGeometry(int aX,int aY,unsigned int aWidth,unsigned int aHeight) {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Given width, height is the desired client area.
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
if(!fWindow) return;
|
||||
int hborder = ::GetSystemMetrics(SM_CYCAPTION);
|
||||
if(::GetWindowLongPtr(fWindow,GWLP_ID)) // Has a menubar.
|
||||
hborder += ::GetSystemMetrics(SM_CYMENU);
|
||||
::MoveWindow(fWindow,aX,aY,aWidth,hborder + aHeight,TRUE);
|
||||
}
|
||||
void setSize(unsigned int aWidth,unsigned int aHeight) {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Given width, height is the desired client area.
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
if(!fWindow) return;
|
||||
int hborder = ::GetSystemMetrics(SM_CYCAPTION);
|
||||
RECT rect;
|
||||
::GetWindowRect(fWindow,&rect);
|
||||
::MoveWindow(fWindow,rect.left,rect.top,aWidth,hborder + aHeight,TRUE);
|
||||
}
|
||||
void setFocusWindow(HWND aWindow) {fFocusWindow = aWindow;}
|
||||
HWND focusWindow() {return fFocusWindow;}
|
||||
|
||||
void setSetFocusCallback(SetFocusCallback aCallback,void* aTag) {
|
||||
fSetFocusCallback = aCallback;
|
||||
fSetFocusTag = aTag;
|
||||
}
|
||||
void callSetFocusCallback() {
|
||||
if(!fSetFocusCallback) return;
|
||||
fSetFocusCallback(this,fSetFocusTag);
|
||||
}
|
||||
HACCEL nativeAcceleratorTable() {return fAcceleratorTable;}
|
||||
|
||||
bool addAccelerator(const std::string& aString,int aID) {
|
||||
//printf("debug : accel : %s %d\n",aString.c_str(),aID);
|
||||
// aString should be of the form : "a" or "Ctrl+a".
|
||||
ACCEL acc;
|
||||
//acc.fVirt : FALT, FCONTROL, FNOINVERT, FSHIFT, FVIRTKEY
|
||||
{acc.cmd = aID;
|
||||
std::vector<std::string> words;
|
||||
std::string s(aString);
|
||||
tools::touppercase(s);
|
||||
tools::words(s,"+",false,words);
|
||||
if(words.size()==1) {
|
||||
acc.fVirt = FVIRTKEY;
|
||||
if(!string_to_VK(words[0],acc.key)) return false;
|
||||
} else if((words.size()==2)&&(words[1].size())) {
|
||||
if(words[0]=="CTRL") {
|
||||
acc.fVirt = FCONTROL;
|
||||
} else if(words[0]=="ALT") {
|
||||
acc.fVirt = FALT;
|
||||
} else if(words[0]=="SHIFT") {
|
||||
acc.fVirt = FSHIFT;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
acc.fVirt |= FVIRTKEY;
|
||||
if(!string_to_VK(words[1],acc.key)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}}
|
||||
|
||||
if(!fAcceleratorTable) {
|
||||
fAcceleratorTable = ::CreateAcceleratorTable(&acc,1);
|
||||
} else {
|
||||
int n = ::CopyAcceleratorTable(fAcceleratorTable,NULL,0);
|
||||
ACCEL* tbl = new ACCEL[n+1];
|
||||
::CopyAcceleratorTable(fAcceleratorTable,tbl,n);
|
||||
ACCEL& tacc = tbl[n];
|
||||
tacc.fVirt = acc.fVirt;
|
||||
tacc.key = acc.key;
|
||||
tacc.cmd = acc.cmd;
|
||||
::DestroyAcceleratorTable(fAcceleratorTable);
|
||||
fAcceleratorTable = ::CreateAcceleratorTable(tbl,n+1);
|
||||
delete [] tbl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
|
||||
static bool string_to_VK(const std::string& aString,WORD& a_VK) {
|
||||
//VK_xxx are defined in WinUser.h
|
||||
if(aString.size()==1) { a_VK = aString[0];return true;} //WM_W is 'W'
|
||||
|
||||
#define S_VK(aWhat) \
|
||||
if(!::strcmp(aString.c_str(),#aWhat)) { a_VK = VK_##aWhat;return true;}
|
||||
|
||||
S_VK(BACK)
|
||||
S_VK(TAB)
|
||||
S_VK(CLEAR)
|
||||
S_VK(RETURN)
|
||||
S_VK(ESCAPE)
|
||||
S_VK(SPACE)
|
||||
|
||||
S_VK(UP)
|
||||
S_VK(DOWN)
|
||||
S_VK(LEFT)
|
||||
S_VK(RIGHT)
|
||||
|
||||
S_VK(F1)
|
||||
S_VK(F2)
|
||||
S_VK(F3)
|
||||
S_VK(F4)
|
||||
S_VK(F5)
|
||||
S_VK(F6)
|
||||
S_VK(F7)
|
||||
S_VK(F8)
|
||||
S_VK(F9)
|
||||
S_VK(F10)
|
||||
S_VK(F11)
|
||||
S_VK(F12)
|
||||
S_VK(F13)
|
||||
S_VK(F14)
|
||||
S_VK(F15)
|
||||
S_VK(F16)
|
||||
S_VK(F17)
|
||||
S_VK(F18)
|
||||
S_VK(F19)
|
||||
S_VK(F20)
|
||||
S_VK(F21)
|
||||
S_VK(F22)
|
||||
S_VK(F23)
|
||||
S_VK(F24)
|
||||
|
||||
//FIXME : handle other keys ? NUMPAD[0-9]
|
||||
|
||||
#undef S_VK
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK proc(HWND aWindow,UINT aMessage,WPARAM aWParam,LPARAM aLParam) {
|
||||
switch (aMessage) {
|
||||
// Same logic as containerProc :
|
||||
case WM_NOTIFY:{ //Coming from a child (combobox, scrollbar, toolbar).
|
||||
NMHDR* nmhdr = (NMHDR*)aLParam;
|
||||
HWND from_win = nmhdr->hwndFrom;
|
||||
if(from_win!=aWindow) {
|
||||
::SendMessage(from_win,aMessage,aWParam,aLParam);
|
||||
}
|
||||
}return 0;
|
||||
// Else :
|
||||
case WM_SIZE:{ // Assume one child window ! FIXME : have a message if not.
|
||||
int width = LOWORD(aLParam);
|
||||
int height = HIWORD(aLParam);
|
||||
HWND hwnd = GetFirstChild(aWindow);
|
||||
if(hwnd) {
|
||||
//FIXME : have to treat the case of TOOLBAR not being the first.
|
||||
if(GetClassName(hwnd)==std::string(TOOLBARCLASSNAME)) {
|
||||
HWND next = GetNextSibling(hwnd);
|
||||
// Share area between toolbar and second child :
|
||||
RECT rect;
|
||||
::GetWindowRect(hwnd,&rect);
|
||||
int htb = rect.bottom-rect.top;
|
||||
SetGeometry(next,0,htb,width,height-htb);
|
||||
} else {
|
||||
SetGeometry(hwnd,0,0,width,height);
|
||||
}
|
||||
}
|
||||
}return 0;
|
||||
case WM_SETFOCUS:{
|
||||
Shell* This = (Shell*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
This->callSetFocusCallback();
|
||||
HWND win = This->focusWindow();
|
||||
if(win) ::SetFocus(win);
|
||||
}
|
||||
}return 0;
|
||||
case WM_INITMENUPOPUP:{ //0x0117
|
||||
//aWParam is the HMENU (from CreatePopupMenu)
|
||||
//aLParam is the MenuItemCount
|
||||
Shell* This = (Shell*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
CallbackData data;
|
||||
data.wparam = aWParam;
|
||||
This->executeCallbacks("cascading",data);
|
||||
}
|
||||
} return 0;
|
||||
case WM_COMMAND:{ //Coming from a menu item, a toolbar !
|
||||
if(aLParam) {
|
||||
// From a toolbar ; send it back to it :
|
||||
::SendMessage((HWND)aLParam,aMessage,aWParam,0);
|
||||
} else {
|
||||
//if(HIWORD(aWParam)==1) { //From an accelerator.
|
||||
//}
|
||||
// From a menu item :
|
||||
Shell* This = (Shell*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
CallbackData data;
|
||||
data.wparam = LOWORD(aWParam);
|
||||
This->executeCallbacks("activate",data);
|
||||
}
|
||||
}
|
||||
}return 0;
|
||||
case WM_CLOSE:{
|
||||
Shell* This = (Shell*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
if(This->hasCallbacks("close")) {
|
||||
CallbackData data;
|
||||
This->executeCallbacks("close",data);
|
||||
}
|
||||
}
|
||||
}break; //NOTE : can't be return 0.
|
||||
case WM_DESTROY:wm__destroy(aWindow);return 0;
|
||||
}
|
||||
return (DefWindowProc(aWindow,aMessage,aWParam,aLParam));
|
||||
}
|
||||
private:
|
||||
HWND fFocusWindow;
|
||||
SetFocusCallback fSetFocusCallback;
|
||||
void* fSetFocusTag;
|
||||
HACCEL fAcceleratorTable;
|
||||
};
|
||||
|
||||
class OpenGLArea : public Component {
|
||||
public:
|
||||
OpenGLArea(Component& aParent)
|
||||
:Component("OpenGLArea",aParent)
|
||||
,fContext(0)
|
||||
,fHDC(0)
|
||||
{
|
||||
if(!fParent || !fParent->nativeWindow()) return;
|
||||
HWND parent = fParent->nativeWindow();
|
||||
|
||||
static char sOpenGLAreaClassName[] = "WinTk::OpenGLArea";
|
||||
static bool done = false;
|
||||
if(!done) {
|
||||
WNDCLASS wc;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = (WNDPROC)OpenGLArea::proc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = GetWindowInstance(parent),
|
||||
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
|
||||
wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
|
||||
wc.lpszMenuName = sOpenGLAreaClassName;
|
||||
wc.lpszClassName = sOpenGLAreaClassName;
|
||||
::RegisterClass(&wc);
|
||||
done = true;
|
||||
}
|
||||
|
||||
// The WS_BORDER is needed. Else probleme of size at startup.
|
||||
RECT rect;
|
||||
::GetClientRect(parent,&rect);
|
||||
fWindow = ::CreateWindow(sOpenGLAreaClassName,
|
||||
NULL,
|
||||
WS_CHILD | WS_VISIBLE,
|
||||
0,0,
|
||||
rect.right-rect.left,
|
||||
rect.bottom-rect.top,
|
||||
parent,NULL,
|
||||
GetWindowInstance(parent),
|
||||
NULL);
|
||||
if(!fWindow) return;
|
||||
::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(this));
|
||||
|
||||
// initialize OpenGL rendering :
|
||||
fHDC = ::GetDC(fWindow);
|
||||
if( fHDC && SetWindowPixelFormat(fHDC) ) {
|
||||
fContext = ::wglCreateContext(fHDC);
|
||||
}
|
||||
}
|
||||
virtual ~OpenGLArea() {
|
||||
if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
|
||||
if(fContext) {
|
||||
wglDeleteContext(fContext);
|
||||
fContext = 0;
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
protected:
|
||||
OpenGLArea(OpenGLArea& a_from):Component(a_from) {}
|
||||
OpenGLArea& operator=(OpenGLArea&) {return *this;}
|
||||
public:
|
||||
bool write_gl2ps(const std::string&,const std::string&);
|
||||
private:
|
||||
static LRESULT CALLBACK proc(HWND aWindow,UINT aMessage,WPARAM aWParam,LPARAM aLParam) {
|
||||
switch (aMessage) {
|
||||
case WM_PAINT:{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hDC = BeginPaint(aWindow,&ps);
|
||||
OpenGLArea* This = (OpenGLArea*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
HDC hdc = This->fHDC;
|
||||
HGLRC context = This->fContext;
|
||||
if(hdc && context) {
|
||||
::wglMakeCurrent(hdc,context);
|
||||
// User OpenGL paint code :
|
||||
|
||||
CallbackData data;
|
||||
data.wparam = aWParam;
|
||||
data.lparam = aLParam;
|
||||
This->executeCallbacks("paint",data);
|
||||
|
||||
::SwapBuffers(hdc);
|
||||
}
|
||||
}
|
||||
EndPaint(aWindow,&ps);
|
||||
}return 0;
|
||||
case WM_LBUTTONDOWN:{
|
||||
OpenGLArea* This = (OpenGLArea*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
CallbackData data;
|
||||
data.wparam = aWParam;
|
||||
data.lparam = aLParam;
|
||||
data.value = "ButtonPress";
|
||||
data.x = LOWORD(aLParam);
|
||||
data.y = HIWORD(aLParam);
|
||||
This->executeCallbacks("event",data);
|
||||
}
|
||||
}return 0;
|
||||
case WM_LBUTTONUP:{
|
||||
OpenGLArea* This = (OpenGLArea*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
CallbackData data;
|
||||
data.wparam = aWParam;
|
||||
data.lparam = aLParam;
|
||||
data.value = "ButtonRelease";
|
||||
data.x = LOWORD(aLParam);
|
||||
data.y = HIWORD(aLParam);
|
||||
This->executeCallbacks("event",data);
|
||||
}
|
||||
} return 0;
|
||||
case WM_MOUSEMOVE:{
|
||||
unsigned int state = aWParam;
|
||||
if((state & MK_LBUTTON)==MK_LBUTTON) {
|
||||
OpenGLArea* This = (OpenGLArea*)::GetWindowLongPtr(aWindow,GWLP_USERDATA);
|
||||
if(This) {
|
||||
CallbackData data;
|
||||
data.wparam = aWParam;
|
||||
data.lparam = aLParam;
|
||||
data.value = "MotionNotify";
|
||||
data.x = LOWORD(aLParam);
|
||||
data.y = HIWORD(aLParam);
|
||||
This->executeCallbacks("event",data);
|
||||
}
|
||||
}
|
||||
}return 0;
|
||||
case WM_DESTROY:wm__destroy(aWindow);return 0;
|
||||
}
|
||||
return (DefWindowProc(aWindow,aMessage,aWParam,aLParam));
|
||||
}
|
||||
static bool SetWindowPixelFormat(HDC aHdc) {
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags =
|
||||
PFD_DRAW_TO_WINDOW |
|
||||
PFD_SUPPORT_OPENGL |
|
||||
PFD_DOUBLEBUFFER |
|
||||
PFD_STEREO_DONTCARE;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cRedBits = 8;
|
||||
pfd.cRedShift = 16;
|
||||
pfd.cGreenBits = 8;
|
||||
pfd.cGreenShift = 8;
|
||||
pfd.cBlueBits = 8;
|
||||
pfd.cBlueShift = 0;
|
||||
pfd.cAlphaBits = 0;
|
||||
pfd.cAlphaShift = 0;
|
||||
pfd.cAccumBits = 64;
|
||||
pfd.cAccumRedBits = 16;
|
||||
pfd.cAccumGreenBits = 16;
|
||||
pfd.cAccumBlueBits = 16;
|
||||
pfd.cAccumAlphaBits = 0;
|
||||
pfd.cDepthBits = 32;
|
||||
pfd.cStencilBits = 8;
|
||||
pfd.cAuxBuffers = 0;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
pfd.bReserved = 0;
|
||||
pfd.dwLayerMask = 0;
|
||||
pfd.dwVisibleMask = 0;
|
||||
pfd.dwDamageMask = 0;
|
||||
|
||||
int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
|
||||
if (pixelIndex==0) {
|
||||
// Let's choose a default index.
|
||||
pixelIndex = 1;
|
||||
if (::DescribePixelFormat(aHdc,
|
||||
pixelIndex,
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
&pfd)==0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
HGLRC fContext;
|
||||
HDC fHDC;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,601 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Windows_tools
|
||||
#define tools_Windows_tools
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace tools {
|
||||
namespace WinTk {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline bool GetClassName(HWND aWindow,std::string& a_value) {
|
||||
if(!aWindow) {a_value.clear();return false;}
|
||||
char className[256];
|
||||
::GetClassName(aWindow,className,128);
|
||||
a_value = std::string(className);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline HWND GetChildByClassName(HWND aWindow,const std::string& aClassName) {
|
||||
// A CBS_SIMPLE has two children of class ComboLBox and Edit.
|
||||
// At creation, a CBS_DROPDOWN has one child of class Edit.
|
||||
if(!aWindow) return NULL;
|
||||
HWND child = GetFirstChild(aWindow);
|
||||
std::string ss;
|
||||
while(child) {
|
||||
GetClassName(child,ss);
|
||||
if(ss==aClassName) return child;
|
||||
child = GetNextSibling(child);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline void SetGeometry(HWND aWindow,int aX,int aY,unsigned int aWidth,unsigned int aHeight) {
|
||||
if(!aWindow) return;
|
||||
std::string className;
|
||||
GetClassName(aWindow,className);
|
||||
if(className=="ComboBox") {
|
||||
// For a Combo the height is the visible part + the height of the list !
|
||||
// (A combo may have no edit control).
|
||||
::MoveWindow(aWindow,aX,aY,aWidth,200,TRUE);
|
||||
} else {
|
||||
::MoveWindow(aWindow,aX,aY,aWidth,aHeight,TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
inline void GetSize(HWND aWindow,int& aWidth,int& aHeight) {
|
||||
RECT rect;
|
||||
::GetWindowRect(aWindow,&rect);
|
||||
aWidth = rect.right-rect.left;
|
||||
aHeight = rect.bottom-rect.top;
|
||||
}
|
||||
|
||||
inline unsigned int GetNumberOfChildren(HWND aWindow) {
|
||||
unsigned int number = 0;
|
||||
HWND child = GetFirstChild(aWindow);
|
||||
while(child) {
|
||||
number++;
|
||||
child = GetNextSibling(child);
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
inline HWND GetLastChild(HWND aWindow) {
|
||||
HWND child = GetFirstChild(aWindow);
|
||||
while(child) {
|
||||
HWND next = GetNextSibling(child);
|
||||
if(!next) return child;
|
||||
child = next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void GetText(HWND aWindow,std::string& a_value) {
|
||||
int l = ::GetWindowTextLength(aWindow);
|
||||
a_value.resize(l);
|
||||
::GetWindowText(aWindow,(char*)a_value.c_str(),l+1);
|
||||
}
|
||||
|
||||
/*
|
||||
inline void PrintChildren(HWND aWindow) {
|
||||
// A CBS_SIMPLE has two children of class ComboLBox and Edit.
|
||||
// At creation, a CBS_DROPDOWN has one child of class Edit.
|
||||
if(!aWindow) return;
|
||||
HWND child = GetFirstChild(aWindow);
|
||||
while(child) {
|
||||
//printf("debug : window : %ld, child : %ld class \"%s\"\n",
|
||||
// aWindow,child,ClassName(child).c_str());
|
||||
child = GetNextSibling(child);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline bool IsStyle(HWND aWindow,LONG aStyle) {
|
||||
LONG_PTR style = ::GetWindowLongPtr(aWindow,GWL_STYLE);
|
||||
return ( ((style & aStyle ) == aStyle) ? true : false);
|
||||
}
|
||||
|
||||
inline void ChangeStyle(HWND aWindow,LONG aStyle,bool aValue) {
|
||||
LONG_PTR style = ::GetWindowLongPtr(aWindow,GWL_STYLE);
|
||||
if(aValue) { //Enable style.
|
||||
style = style | aStyle;
|
||||
} else { //Disbale style.
|
||||
style = style & ~aStyle;
|
||||
}
|
||||
::SetWindowLongPtr(aWindow,GWL_STYLE,style);
|
||||
}
|
||||
|
||||
inline bool IsShell(HWND aWindow) {
|
||||
if(IsStyle(aWindow,WS_OVERLAPPEDWINDOW)) return true;
|
||||
if(IsStyle(aWindow,WS_POPUP)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
inline HWND GetShell(HWND aWindow) {
|
||||
HWND window = aWindow;
|
||||
if(IsShell(window)) return window;
|
||||
while(true) {
|
||||
HWND parent = GetParent(window);
|
||||
if(!parent) return window;
|
||||
if(IsShell(parent)) return parent;
|
||||
window = parent;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline bool Show(HWND aWindow) {
|
||||
HWND shell = GetShell(aWindow);
|
||||
if(!shell) return false;
|
||||
::SetForegroundWindow(shell);
|
||||
::ShowWindow(shell,SW_SHOWDEFAULT);
|
||||
::UpdateWindow(shell);
|
||||
::DrawMenuBar(shell);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Hide(HWND aWindow) {
|
||||
HWND shell = GetShell(aWindow);
|
||||
if(!shell) return false;
|
||||
::ShowWindow(shell,SW_HIDE);
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline bool IsTabStop(HWND aWindow) {
|
||||
LONG_PTR style = ::GetWindowLongPtr(aWindow,GWL_STYLE);
|
||||
return ((style & WS_TABSTOP ) == WS_TABSTOP ? true : false);
|
||||
}
|
||||
|
||||
inline HWND GetTabStopInTree(HWND aWindow,bool aForward) {
|
||||
if(IsTabStop(aWindow)) return aWindow;
|
||||
HWND child = aForward ? GetFirstChild(aWindow) : GetLastChild(aWindow);
|
||||
while(child) {
|
||||
HWND tabStop = GetTabStopInTree(child,aForward);
|
||||
if(tabStop) return tabStop;
|
||||
child = aForward ? GetNextSibling(child) : GetPrevSibling(child);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline HWND GetTabStopInSibling(HWND aWindow,bool aForward) {
|
||||
if(!aWindow) return NULL;
|
||||
HWND child = aForward ? GetNextSibling(aWindow) : GetPrevSibling(aWindow);
|
||||
while(child) {
|
||||
HWND tabStop = GetTabStopInTree(child,aForward);
|
||||
if(tabStop) return tabStop;
|
||||
child = aForward ? GetNextSibling(child) : GetPrevSibling(child);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline HWND GetTabStop(HWND aDialog,HWND aWindow,bool aForward = true) {
|
||||
if(!aWindow) return NULL;
|
||||
HWND window = aWindow;
|
||||
while(window && (window!=aDialog) ) {
|
||||
HWND tabStop = GetTabStopInSibling(window,aForward);
|
||||
if(tabStop) return tabStop;
|
||||
window = GetParent(window);
|
||||
}
|
||||
return GetTabStopInTree(aDialog,aForward);
|
||||
}
|
||||
|
||||
inline HBITMAP CreateDIB(HDC aDC,int aWidth,int aHeight,int aBPP /*16||24||32*/,void** aBits) {
|
||||
if((aBPP!=24) && (aBPP!=32)) return 0;
|
||||
|
||||
BITMAPINFO format;
|
||||
BITMAPINFOHEADER* header = (BITMAPINFOHEADER*)&format;
|
||||
header->biSize = sizeof(BITMAPINFOHEADER);
|
||||
header->biWidth = aWidth;
|
||||
header->biHeight = -aHeight;
|
||||
header->biPlanes = 1;
|
||||
header->biBitCount = aBPP;
|
||||
header->biCompression = BI_RGB;
|
||||
header->biSizeImage = 0;
|
||||
header->biXPelsPerMeter = 0;
|
||||
header->biYPelsPerMeter = 0;
|
||||
header->biClrUsed = 0;
|
||||
header->biClrImportant = 0;
|
||||
|
||||
UINT flag = DIB_RGB_COLORS;
|
||||
HBITMAP bitmap = ::CreateDIBSection(aDC,&format,flag,(void**)aBits,NULL,0);
|
||||
|
||||
if(!(*aBits)) return 0;
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <commctrl.h>
|
||||
|
||||
namespace tools {
|
||||
namespace WinTk {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
inline bool TreeGetItemLabel(HWND aWindow,HTREEITEM aItem,std::string& a_value) {
|
||||
TCHAR text[256];
|
||||
TV_ITEM item;
|
||||
item.hItem = aItem;
|
||||
item.mask = TVIF_TEXT;
|
||||
item.pszText = text;
|
||||
item.cchTextMax = 256;
|
||||
if(!TreeView_GetItem(aWindow,&item)) {a_value.clear();return false;}
|
||||
a_value = std::string(text);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool TreeIsItemBranch(HWND aWindow,HTREEITEM aItem) {
|
||||
TV_ITEM item;
|
||||
item.hItem = aItem;
|
||||
item.mask = TVIF_CHILDREN;
|
||||
if(!TreeView_GetItem(aWindow,&item)) return 0;
|
||||
return item.cChildren?true:false;
|
||||
}
|
||||
|
||||
inline bool TreeIsItemExpanded(HWND aWindow,HTREEITEM aItem) {
|
||||
TV_ITEM item;
|
||||
item.hItem = aItem;
|
||||
item.mask = TVIS_EXPANDED;
|
||||
if(!TreeView_GetItem(aWindow,&item)) return 0;
|
||||
return ((item.state & TVIS_EXPANDED)== TVIS_EXPANDED) ? true : false;
|
||||
}
|
||||
|
||||
inline void TreeGetItemPath(HWND aWindow,HTREEITEM aItem,std::string& a_value) {
|
||||
HTREEITEM item = aItem;
|
||||
a_value.clear();
|
||||
std::string ss;
|
||||
while(item && (item!=TVI_ROOT)) {
|
||||
TreeGetItemLabel(aWindow,item,ss);
|
||||
std::string opath = a_value;
|
||||
a_value = "\n";
|
||||
a_value += ss;
|
||||
a_value += opath;
|
||||
item = TreeView_GetParent(aWindow,item);
|
||||
}
|
||||
// Remove the leading \n
|
||||
if(a_value.size()) a_value = a_value.substr(1,a_value.size()-1);
|
||||
}
|
||||
|
||||
inline void TreeGetItemXML(HWND aWindow,HTREEITEM aItem,std::string& a_value) {
|
||||
//return a XML string representing this tree
|
||||
std::string spaceItem = "";
|
||||
std::string spaceRoot = "";
|
||||
std::string ss;
|
||||
a_value.clear();
|
||||
do {
|
||||
a_value += spaceRoot + "<treeItem>";
|
||||
a_value += spaceItem + "<label>";
|
||||
TreeGetItemLabel(aWindow,aItem,ss);
|
||||
a_value.append(ss);
|
||||
a_value += "</label>";
|
||||
a_value += spaceItem + "<opened>";
|
||||
if (TreeIsItemExpanded(aWindow,aItem)) a_value.append("true");
|
||||
else a_value.append("false");
|
||||
a_value += "</opened>";
|
||||
if (TreeView_GetChild(aWindow,aItem)) {
|
||||
TreeGetItemXML(aWindow,TreeView_GetChild(aWindow,aItem),ss);
|
||||
a_value += ss;
|
||||
}
|
||||
a_value += spaceRoot + "</treeItem>";
|
||||
aItem = TreeView_GetNextSibling(aWindow,aItem);
|
||||
}
|
||||
while (aItem);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
inline int smanip_axtoi(const std::string& a_string) {
|
||||
// convert from ASCII hex to int
|
||||
// Exa : "FF" -> 256.
|
||||
int x = 0;
|
||||
size_t n = a_string.size();
|
||||
// convert n nibbles
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
char c = a_string[i];
|
||||
// numbers 0 - 9
|
||||
if ((c > 0x2F) && (c < 0x3A))
|
||||
x += ((c - 0x30) << ((n - i - 1) * 4));
|
||||
|
||||
// capital letters A - F
|
||||
if ((c > 0x40) && (c < 0x47))
|
||||
x += ((c - 0x41 + 0x0A) << ((n - i - 1) * 4));
|
||||
|
||||
// lower case letters a - f
|
||||
if ((c > 0x60) && (c < 0x67))
|
||||
x += ((c - 0x61 + 0x0A) << ((n - i - 1) * 4));
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <tools/svalues>
|
||||
|
||||
namespace tools {
|
||||
namespace WinTk {
|
||||
|
||||
inline HBITMAP ConvertXpmToDIB(HDC aDC,const std::vector<std::string>& aXPM,int& aWidth,int& aHeight) {
|
||||
// Convert from xpm to DIB (demands hex colors).
|
||||
// From CoinWin/widgets/SoWinBitmapButton.cpp.
|
||||
aWidth = 0;
|
||||
aHeight = 0;
|
||||
if(!aXPM.size()) return 0;
|
||||
|
||||
std::vector<int> vals;
|
||||
tools::values<int>(aXPM[0]," ",false,vals);
|
||||
if(vals.size()!=4) return 0;
|
||||
int width = vals[0];
|
||||
int height = vals[1];
|
||||
int numcol = vals[2];
|
||||
int numchars = vals[3];
|
||||
if(width<=0) return 0;
|
||||
if(height<=0) return 0;
|
||||
if(numcol<=0) return 0;
|
||||
if(numchars<=0) return 0;
|
||||
|
||||
// Check consistency :
|
||||
if((height+numcol)!=aXPM.size()-1) return 0;
|
||||
|
||||
size_t lcolor = 0;
|
||||
int i;
|
||||
for (i = 0; i < numcol; i++) {
|
||||
std::string::size_type pos = aXPM[i+1].rfind("c #");
|
||||
if(pos==std::string::npos) continue; // May be "c None"
|
||||
lcolor = aXPM[i+1].size()-(pos+3);
|
||||
break;
|
||||
}
|
||||
//printf("debug : xpm : numcol %d (%d)\n",numcol,lcolor);
|
||||
|
||||
if( (lcolor!=6) && (lcolor!=12) ) return 0;
|
||||
|
||||
// create color lookup table
|
||||
char* charlookuptable = new char[numcol * numchars];
|
||||
//long* colorlookuptable = new long[numcol];
|
||||
int* rlookuptable = new int[numcol];
|
||||
int* glookuptable = new int[numcol];
|
||||
int* blookuptable = new int[numcol];
|
||||
|
||||
bool done = true;
|
||||
// get colors
|
||||
for (i = 0; i < numcol; i++) {
|
||||
|
||||
const std::string& line = aXPM[i+1];
|
||||
|
||||
// Check consistency :
|
||||
if((int)line.size()<numchars) {
|
||||
done = false;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int j = 0; j < numchars; j ++) {
|
||||
charlookuptable[(i * numchars) + j] = line[j];
|
||||
}
|
||||
|
||||
// Find color by value :
|
||||
std::string::size_type pos = line.find("c #",numchars);
|
||||
if(pos!=std::string::npos) {
|
||||
size_t lc = line.size()-(pos+3);
|
||||
if(lc!=lcolor) {
|
||||
done = false;
|
||||
//printf("debug : xpm : error in \"%s\" %d %d\n",
|
||||
//line.c_str(),lc,lcolor);
|
||||
break;
|
||||
}
|
||||
if(lcolor==6) {
|
||||
rlookuptable[i] = smanip_axtoi(line.substr(pos+3+0,2));
|
||||
glookuptable[i] = smanip_axtoi(line.substr(pos+3+2,2));
|
||||
blookuptable[i] = smanip_axtoi(line.substr(pos+3+4,2));
|
||||
} else { //lcolor 12
|
||||
rlookuptable[i] = smanip_axtoi(line.substr(pos+3+0,2));
|
||||
glookuptable[i] = smanip_axtoi(line.substr(pos+3+4,2));
|
||||
blookuptable[i] = smanip_axtoi(line.substr(pos+3+8,2));
|
||||
}
|
||||
|
||||
//printf("debug : xpm : color %d : (%x,%x,%x)\n",
|
||||
// i,rlookuptable[i],glookuptable[i],blookuptable[i]);
|
||||
|
||||
} else { // Could be "c None"
|
||||
rlookuptable[i] = -1;
|
||||
glookuptable[i] = -1;
|
||||
blookuptable[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("debug : xpm : read color %d\n",done);
|
||||
|
||||
//WARNING : pixelsize 3 does not work with button in a toolbar.
|
||||
// unsigned char pixelsize = 3;
|
||||
unsigned char pixelsize = 4;
|
||||
|
||||
if(!done) pixelsize = 0; // Will induce a clean exit.
|
||||
|
||||
// create bitmap
|
||||
void* dest;
|
||||
HBITMAP hbmp = CreateDIB(aDC,width,height,pixelsize * 8,&dest);
|
||||
|
||||
if(hbmp) {
|
||||
int noneColor = ::GetSysColor(COLOR_3DFACE);
|
||||
done = true;
|
||||
// put pixels
|
||||
for (i = 0; i < height; i++) {
|
||||
|
||||
const std::string& line = aXPM[i + 1 + numcol];
|
||||
|
||||
// Check consistency :
|
||||
if((int)line.size()!=(numchars*width)) {
|
||||
done = false;
|
||||
break;
|
||||
}
|
||||
|
||||
int y = i * width * pixelsize;
|
||||
|
||||
for (int j = 0; j < width; j++) {
|
||||
|
||||
int x = j * pixelsize;
|
||||
|
||||
// for every color
|
||||
for (int k = 0; k < numcol; k++) {
|
||||
|
||||
bool found = true;
|
||||
for (int l = 0; l < numchars; l++) {
|
||||
if (charlookuptable[(k * numchars) + l]
|
||||
!= line[(j * numchars) + l]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(found) {
|
||||
|
||||
unsigned char r,g,b;
|
||||
if (rlookuptable[k] == -1) {
|
||||
r = (noneColor & 0x00FF0000)>>16;
|
||||
g = (noneColor & 0x0000FF00)>>8;
|
||||
b = noneColor & 0x000000FF;
|
||||
} else {
|
||||
r = rlookuptable[k];
|
||||
g = glookuptable[k];
|
||||
b = blookuptable[k];
|
||||
}
|
||||
|
||||
if(pixelsize==4) {
|
||||
((unsigned char*)dest)[y + x + 0] = b;
|
||||
((unsigned char*)dest)[y + x + 1] = g;
|
||||
((unsigned char*)dest)[y + x + 2] = r;
|
||||
((unsigned char*)dest)[y + x + 3] = 0;
|
||||
} else {
|
||||
((unsigned char*)dest)[y + x + 0] = b;
|
||||
((unsigned char*)dest)[y + x + 1] = g;
|
||||
((unsigned char*)dest)[y + x + 2] = r;
|
||||
}
|
||||
|
||||
// next pixel
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if(!done) {
|
||||
//printf("debug : xpm : can'tread pixels.\n");
|
||||
::DeleteObject(hbmp);
|
||||
hbmp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup
|
||||
delete [] charlookuptable;
|
||||
delete [] rlookuptable;
|
||||
delete [] glookuptable;
|
||||
delete [] blookuptable;
|
||||
|
||||
if(hbmp) {
|
||||
aWidth = width;
|
||||
aHeight = height;
|
||||
}
|
||||
|
||||
return hbmp;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <tools/file>
|
||||
|
||||
namespace tools {
|
||||
namespace WinTk {
|
||||
|
||||
inline HBITMAP Read_Xpm(HDC aDC,const std::string& aFileName,int& aWidth,int& aHeight) {
|
||||
aWidth = 0;
|
||||
aHeight = 0;
|
||||
std::vector<std::string> text;
|
||||
//std::string name;
|
||||
//tools::file_name(aFileName,name);
|
||||
if(!tools::file::read(aFileName,text)) return 0;
|
||||
|
||||
std::vector<std::string> xpm;
|
||||
|
||||
{for(size_t index=0;index<text.size();index++) {
|
||||
if(text[index][0]!='"') continue;
|
||||
std::string::size_type l = text[index].size();
|
||||
std::string line = text[index].substr(1,l-1);
|
||||
std::string::size_type pos = line.find("\"");
|
||||
if(pos==std::string::npos) return 0;
|
||||
xpm.push_back(line.substr(0,pos));
|
||||
}}
|
||||
|
||||
if(!xpm.size()) return 0;
|
||||
|
||||
return ConvertXpmToDIB(aDC,xpm,aWidth,aHeight);
|
||||
}
|
||||
|
||||
inline std::string TreeGetItemLabel(HWND aWindow,HTREEITEM aItem) {
|
||||
std::string ss;
|
||||
TreeGetItemLabel(aWindow,aItem,ss);
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline std::string TreeGetItemPath(HWND aWindow,HTREEITEM aItem) {
|
||||
std::string ss;
|
||||
TreeGetItemPath(aWindow,aItem,ss);
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline std::string TreeGetItemXML(HWND aWindow,HTREEITEM aItem) {
|
||||
std::string ss;
|
||||
TreeGetItemXML(aWindow,aItem,ss);
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline std::string GetText(HWND aWindow) {
|
||||
std::string ss;
|
||||
GetText(aWindow,ss);
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline std::string GetClassName(HWND aWindow) {
|
||||
std::string ss;
|
||||
GetClassName(aWindow,ss);
|
||||
return ss;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <tools/system> //backcomp
|
||||
|
||||
namespace tools {
|
||||
namespace WinTk {
|
||||
|
||||
inline HBITMAP ReadXpm(HDC aDC,const std::string& aFileName,int& aWidth,int& aHeight) {
|
||||
std::string name;
|
||||
tools::file_name(aFileName,name);
|
||||
return Read_Xpm(aDC,name,aWidth,aHeight);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_X11_base_session
|
||||
#define tools_X11_base_session
|
||||
|
||||
// pure X11 code, no GL.
|
||||
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
#include "dispatcher"
|
||||
#include <tools/forit>
|
||||
|
||||
#include <X11/Xatom.h> //XA_INTEGER
|
||||
|
||||
#include <X11/Xutil.h> //XVisualInfo
|
||||
|
||||
namespace tools {
|
||||
namespace X11 {
|
||||
|
||||
class base_session {
|
||||
public:
|
||||
//virtual bool make_current(Window) const {
|
||||
// if(!m_display) return false;
|
||||
// return true;
|
||||
//}
|
||||
//virtual bool swap_buffers(Window) const {
|
||||
// if(!m_display) return false;
|
||||
// return true;
|
||||
//}
|
||||
public:
|
||||
base_session(std::ostream& a_out,unsigned int a_monitor = 0)
|
||||
:m_out(a_out)
|
||||
,m_monitor(a_monitor)
|
||||
,m_display(0)
|
||||
,m_WM_DELETE_WINDOW_atom(None)
|
||||
,m_SESSION_EXIT_STEER_atom(None)
|
||||
{
|
||||
if(!initialize()) {} //throw
|
||||
}
|
||||
virtual ~base_session() {
|
||||
clear_dispatchers();
|
||||
finalize();
|
||||
//std::cout << "debug : ~base_session" << std::endl;
|
||||
}
|
||||
public:
|
||||
base_session(const base_session& a_from)
|
||||
:m_out(a_from.m_out)
|
||||
,m_monitor(a_from.m_monitor)
|
||||
,m_display(0)
|
||||
,m_WM_DELETE_WINDOW_atom(None)
|
||||
,m_SESSION_EXIT_STEER_atom(None)
|
||||
{
|
||||
copy_dispatchers(a_from.m_dispatchers);
|
||||
if(!initialize()) {} //throw
|
||||
}
|
||||
base_session& operator=(const base_session& a_from){
|
||||
if(&a_from==this) return *this;
|
||||
m_monitor = a_from.m_monitor;
|
||||
clear_dispatchers();
|
||||
finalize();
|
||||
copy_dispatchers(a_from.m_dispatchers);
|
||||
if(!initialize()) {} //throw
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
bool initialize() {
|
||||
if(m_display) return true; //done.
|
||||
|
||||
//NOTE : macOS : XOpenDisplay leaks 128 bytes.
|
||||
m_display = ::XOpenDisplay(NULL);
|
||||
if(!m_display) {
|
||||
m_out << "tools::X11::base_session::initialize : can't open display." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int monitors = ::XScreenCount(m_display);
|
||||
if(int(m_monitor)>=monitors) {
|
||||
m_out << "tools::X11::base_session::initialize : bad monitor index " << m_monitor << ". (#monitors " << monitors << ")." << std::endl;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_WM_DELETE_WINDOW_atom = ::XInternAtom(m_display,"WM_DELETE_WINDOW",False);
|
||||
if(m_WM_DELETE_WINDOW_atom==None) {
|
||||
m_out << "tools::X11::base_session::initialize : can't create/get WM_DELETE_WINDOW Atom." << std::endl;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_SESSION_EXIT_STEER_atom = ::XInternAtom(m_display,"TOOLS_X11_SESSION_EXIT_STEER",False);
|
||||
if(m_SESSION_EXIT_STEER_atom==None) {
|
||||
m_out << "tools::X11::base_session::initialize : can't create/get TOOLS_X11_SESSION_EXIT_STEER Atom." << std::endl;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void finalize() {
|
||||
if(!m_display) return;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
}
|
||||
public:
|
||||
std::ostream& out() const {return m_out;}
|
||||
|
||||
Atom WM_DELETE_WINDOW_atom() const {return m_WM_DELETE_WINDOW_atom;}
|
||||
Atom SESSION_EXIT_STEER_atom() const {return m_SESSION_EXIT_STEER_atom;}
|
||||
|
||||
bool is_valid() const {return m_display?true:false;}
|
||||
|
||||
Display* display() const {return m_display;}
|
||||
|
||||
bool steer() {
|
||||
if(!m_display) return false;
|
||||
|
||||
while(true) {
|
||||
XEvent xevent;
|
||||
::XNextEvent(m_display,&xevent);
|
||||
if(xevent.type==ClientMessage) {
|
||||
if(xevent.xclient.data.l[0]==(long)m_SESSION_EXIT_STEER_atom) break;
|
||||
}
|
||||
dispatch(xevent);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sync() {
|
||||
if(!m_display) return false;
|
||||
//::glXWaitX();
|
||||
::XSync(m_display,False);
|
||||
while(true) {
|
||||
XEvent xevent;
|
||||
if(::XPending(m_display)) {
|
||||
::XNextEvent(m_display,&xevent);
|
||||
if(xevent.type==ClientMessage) {
|
||||
if(xevent.xclient.data.l[0]==(long)m_SESSION_EXIT_STEER_atom) return false;
|
||||
}
|
||||
dispatch(xevent);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool event_pending(bool& a_is) {
|
||||
if(!m_display) {a_is = false;return false;}
|
||||
a_is = ::XPending(m_display)?true:false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool next_event(bool& a_to_exit) {
|
||||
if(!m_display) {a_to_exit = false;return false;}
|
||||
XEvent xevent;
|
||||
::XNextEvent(m_display,&xevent);
|
||||
if(xevent.type==ClientMessage) {
|
||||
if(xevent.xclient.data.l[0]==(long)m_SESSION_EXIT_STEER_atom) {
|
||||
a_to_exit = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
dispatch(xevent);
|
||||
a_to_exit = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool flush() {
|
||||
if(!m_display) return false;
|
||||
::XFlush(m_display);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
Window create_window(const char* a_title,int a_x,int a_y,unsigned int a_width,unsigned int a_height) {
|
||||
if(!m_display) return 0L;
|
||||
|
||||
XSetWindowAttributes swa;
|
||||
swa.event_mask = StructureNotifyMask | ExposureMask
|
||||
| ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
|
||||
| PointerMotionMask
|
||||
| KeyPressMask;
|
||||
|
||||
swa.background_pixel = ::XWhitePixel(m_display,m_monitor);
|
||||
|
||||
Window window = ::XCreateWindow(m_display,
|
||||
::XRootWindow(m_display,m_monitor),
|
||||
a_x,a_y,a_width,a_height,
|
||||
0,
|
||||
(int)CopyFromParent,
|
||||
InputOutput,
|
||||
(Visual*)CopyFromParent,
|
||||
CWEventMask|CWBackPixel,&swa);
|
||||
if(window==0L) {
|
||||
m_out << "tools::X11::base_session::create_window : can't create a X11 window." << std::endl;
|
||||
return 0L;
|
||||
}
|
||||
|
||||
XTextProperty tp;
|
||||
::XStringListToTextProperty((char**)&a_title,1,&tp);
|
||||
XSizeHints sh;
|
||||
sh.flags = USPosition | USSize;
|
||||
::XSetWMProperties(m_display,window,&tp,&tp,0,0,&sh,0,0);
|
||||
::XFree(tp.value);
|
||||
|
||||
::XSetWMProtocols(m_display,window,&m_WM_DELETE_WINDOW_atom,1);
|
||||
return window;
|
||||
}
|
||||
|
||||
void map_raise_window(Window a_window) const {
|
||||
if(!m_display) return;
|
||||
::XMapWindow(m_display,a_window);
|
||||
::XRaiseWindow(m_display,a_window);
|
||||
}
|
||||
|
||||
void show_window(Window a_window) const {
|
||||
if(!m_display) return;
|
||||
// we should test if already mapped ! Else we are going to forever wait in the below XIfEvent.
|
||||
::XMapWindow(m_display,a_window);
|
||||
::XRaiseWindow(m_display,a_window);
|
||||
{XEvent event;
|
||||
::XIfEvent(m_display,&event,wait_map_notify,(char*)a_window);}
|
||||
}
|
||||
|
||||
void hide_window(Window a_window) const {
|
||||
if(!m_display) return;
|
||||
::XUnmapWindow(m_display,a_window);
|
||||
{XEvent event;
|
||||
::XIfEvent(m_display,&event,wait_unmap_notify,(char*)a_window);}
|
||||
}
|
||||
|
||||
void resize_window(Window a_window,unsigned int a_width,unsigned int a_height) const {
|
||||
if(!m_display) return;
|
||||
unsigned int mask = CWWidth | CWHeight | CWBorderWidth;
|
||||
XWindowChanges changes;
|
||||
changes.border_width = 0;
|
||||
changes.width = a_width;
|
||||
changes.height = a_height;
|
||||
::XConfigureWindow(m_display,a_window,mask,&changes);
|
||||
}
|
||||
|
||||
bool window_size(Window a_window,int& a_width,int& a_height) const {
|
||||
if(!m_display) {a_width = 0;a_height = 0;return false;}
|
||||
XWindowAttributes watbs;
|
||||
if(!XGetWindowAttributes(m_display,a_window,&watbs)) {a_width = 0;a_height = 0;return false;}
|
||||
a_width = watbs.width;
|
||||
a_height = watbs.height;
|
||||
return true;
|
||||
}
|
||||
|
||||
void delete_window(Window a_window) const {
|
||||
if(!m_display) return;
|
||||
::XDestroyWindow(m_display,a_window);
|
||||
}
|
||||
|
||||
void set_override_redirect(Window a_window) const {
|
||||
//must be executed before window is mapped.
|
||||
if(!m_display) return;
|
||||
XSetWindowAttributes swa;
|
||||
swa.override_redirect = True;
|
||||
::XChangeWindowAttributes(m_display,a_window,CWOverrideRedirect,&swa);
|
||||
}
|
||||
|
||||
void set_wm_no_decorations(Window a_window) const {
|
||||
//must be executed before window is mapped.
|
||||
if(!m_display) return;
|
||||
|
||||
// struct, mwm_hints_decorations taken from OpenMotif MwmUtils.h.
|
||||
struct{
|
||||
unsigned long flags;
|
||||
unsigned long functions;
|
||||
unsigned long decorations;
|
||||
long inputMode;
|
||||
unsigned long status;
|
||||
} prop;
|
||||
|
||||
//unsigned long mwm_hints_functions = 1L << 0;
|
||||
unsigned long mwm_hints_decorations = 1L << 1;
|
||||
|
||||
Atom atom = ::XInternAtom(m_display,"_MOTIF_WM_HINTS",False);
|
||||
if(atom==None) {
|
||||
m_out << "tools::X11::base_session::set_wm_no_decorations : can't create/get _MOTIF_WM_HINTS Atom." << std::endl;
|
||||
return;
|
||||
}
|
||||
prop.flags = mwm_hints_decorations;
|
||||
prop.functions = 0;
|
||||
prop.decorations = 0;
|
||||
|
||||
::XChangeProperty(m_display,a_window,atom,atom,32,PropModeReplace,(unsigned char*)&prop,5);
|
||||
}
|
||||
|
||||
bool post(Window a_win,
|
||||
long a_0 = 0,long a_1 = 0,
|
||||
long a_2 = 0,long a_3 = 0,
|
||||
long a_4 = 0) const {
|
||||
if(!m_display) return false;
|
||||
XEvent event;
|
||||
event.type = ClientMessage;
|
||||
event.xclient.display = m_display;
|
||||
event.xclient.window = a_win;
|
||||
event.xclient.message_type = XA_INTEGER;
|
||||
event.xclient.format = 8; /* put 8 because bug with 32 on VMCMS */
|
||||
event.xclient.data.l[0] = a_0;
|
||||
event.xclient.data.l[1] = a_1;
|
||||
event.xclient.data.l[2] = a_2;
|
||||
event.xclient.data.l[3] = a_3;
|
||||
event.xclient.data.l[4] = a_4;
|
||||
//lock();
|
||||
Status stat = ::XSendEvent(m_display,a_win,False,0L,&event);
|
||||
::XFlush(m_display);
|
||||
//unlock();
|
||||
return (stat==0?false:true);
|
||||
}
|
||||
|
||||
bool post_EXIT_STEER(Window a_win) {
|
||||
return post(a_win,SESSION_EXIT_STEER_atom());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
void add_dispatcher(dispatcher* a_dispatcher) {
|
||||
m_dispatchers.push_back(a_dispatcher); //take ownership.
|
||||
}
|
||||
|
||||
void invalidate_dispatchers_with_window(Window a_win){
|
||||
tools_vforit(dispatcher*,m_dispatchers,it) {
|
||||
if((*it)->window()==a_win) (*it)->invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void remove_dispatchers_with_window(Window a_win){
|
||||
tools_vforit_npp(dispatcher*,m_dispatchers,it) {
|
||||
if((*it)->window()==a_win) {
|
||||
dispatcher* obj = *it;
|
||||
it = m_dispatchers.erase(it);
|
||||
delete obj;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool dispatch(XEvent& a_event) {
|
||||
{tools_vforit_npp(dispatcher*,m_dispatchers,it) {
|
||||
if(!(*it)->is_valid()) {
|
||||
dispatcher* obj = *it;
|
||||
it = m_dispatchers.erase(it);
|
||||
delete obj;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}}
|
||||
tools_vforit(dispatcher*,m_dispatchers,it) {
|
||||
if((*it)->is_valid()) {
|
||||
if((*it)->dispatch(a_event)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected:
|
||||
static Bool wait_map_notify(Display*,XEvent* a_event,char* a_arg){
|
||||
return (a_event->type == MapNotify) && (a_event->xmap.window == (Window)a_arg);
|
||||
}
|
||||
static Bool wait_unmap_notify(Display*,XEvent* a_event,char* a_arg){
|
||||
return (a_event->type == UnmapNotify) && (a_event->xmap.window == (Window)a_arg);
|
||||
}
|
||||
|
||||
/*
|
||||
void wait_xxx(Window a_window) {
|
||||
if(!m_display) return;
|
||||
{wait_what arg;
|
||||
arg.m_event_type = ConfigureNotify;
|
||||
arg.m_window = a_window;
|
||||
XEvent event;
|
||||
::XIfEvent(m_display,&event,wait_for,(char*)&arg);
|
||||
dispatch(event);}
|
||||
}
|
||||
|
||||
struct wait_what {
|
||||
int m_event_type;
|
||||
Window m_window;
|
||||
};
|
||||
static Bool wait_for(Display*,XEvent* a_event,char* a_arg){
|
||||
wait_what* arg = (wait_what*)a_arg;
|
||||
return (a_event->type == arg->m_event_type) &&
|
||||
(a_event->xmap.window == arg->m_window);
|
||||
}
|
||||
*/
|
||||
|
||||
void clear_dispatchers() {
|
||||
tools_vforit_npp(dispatcher*,m_dispatchers,it) {
|
||||
dispatcher* obj = *it;
|
||||
it = m_dispatchers.erase(it);
|
||||
delete obj;
|
||||
}
|
||||
m_dispatchers.clear();
|
||||
}
|
||||
|
||||
void copy_dispatchers(const std::vector<dispatcher*>& a_from) {
|
||||
clear_dispatchers();
|
||||
tools_vforcit(dispatcher*,a_from,it) {
|
||||
m_dispatchers.push_back((*it)->copy());
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::ostream& m_out;
|
||||
unsigned int m_monitor;
|
||||
Display* m_display;
|
||||
Atom m_WM_DELETE_WINDOW_atom;
|
||||
Atom m_SESSION_EXIT_STEER_atom;
|
||||
std::vector<dispatcher*> m_dispatchers;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_X11_dispatcher
|
||||
#define tools_X11_dispatcher
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#ifdef TOOLS_MEM
|
||||
#include <tools/mem>
|
||||
#endif
|
||||
|
||||
namespace tools {
|
||||
namespace X11 {
|
||||
|
||||
class dispatcher {
|
||||
protected:
|
||||
#ifdef TOOLS_MEM
|
||||
static const std::string& s_class() {
|
||||
static const std::string s_v("tools::X11::dispatcher");
|
||||
return s_v;
|
||||
}
|
||||
#endif
|
||||
public:
|
||||
virtual bool dispatch(XEvent&) = 0;
|
||||
virtual Window window() const = 0;
|
||||
virtual dispatcher* copy() const = 0;
|
||||
public:
|
||||
dispatcher():m_is_valid(true){
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
virtual ~dispatcher(){
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
dispatcher(const dispatcher& a_from):m_is_valid(a_from.m_is_valid){
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
dispatcher& operator=(const dispatcher& a_from) { m_is_valid = a_from.m_is_valid;return *this;}
|
||||
public:
|
||||
bool is_valid() const {return m_is_valid;}
|
||||
void invalidate() {m_is_valid = false;}
|
||||
protected:
|
||||
bool m_is_valid;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,223 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_X11_session
|
||||
#define tools_X11_session
|
||||
|
||||
#include "base_session"
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
namespace tools {
|
||||
namespace X11 {
|
||||
|
||||
class session : public base_session {
|
||||
typedef base_session parent;
|
||||
public:
|
||||
//virtual bool make_current(Window a_window) const {
|
||||
// if(!m_display) return false;
|
||||
// if(::glXMakeCurrent(m_display,a_window,m_ctx)==False) {
|
||||
// m_out << "tools::X11::session::make_current : glXMakeCurrent failed." << std::endl;
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
//virtual bool swap_buffers(Window a_window) const {
|
||||
// if(!m_display) return false;
|
||||
// ::glXSwapBuffers(m_display,a_window);
|
||||
// return true;
|
||||
//}
|
||||
public:
|
||||
session(std::ostream& a_out,unsigned int a_monitor = 0)
|
||||
:parent(a_out,a_monitor)
|
||||
,m_vinfo(0)
|
||||
,m_ctx(0)
|
||||
,m_colormap(0)
|
||||
{
|
||||
if(!initialize_gl()) {} //throw
|
||||
}
|
||||
virtual ~session() {
|
||||
finalize_gl();
|
||||
//std::cout << "debug : ~session" << std::endl;
|
||||
}
|
||||
public:
|
||||
session(const session& a_from)
|
||||
:parent(a_from)
|
||||
,m_vinfo(0)
|
||||
,m_ctx(0)
|
||||
,m_colormap(0)
|
||||
{
|
||||
if(!initialize_gl()) {} //throw
|
||||
}
|
||||
session& operator=(const session& a_from){
|
||||
if(&a_from==this) return *this;
|
||||
parent::operator=(a_from);
|
||||
finalize_gl();
|
||||
if(!initialize_gl()) {} //throw
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
bool initialize_gl() {
|
||||
if(!m_display) {
|
||||
m_display = 0;
|
||||
m_vinfo = 0;
|
||||
m_ctx = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
{int glxMajor, glxMinor;
|
||||
::glXQueryVersion(m_display,&glxMajor,&glxMinor);
|
||||
if(glxMajor<=0) {
|
||||
m_out << "tools::X11::session::initialize : bad GLX-Version " << glxMajor << "." << glxMinor << std::endl;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
m_vinfo = 0;
|
||||
m_ctx = 0;
|
||||
return false;
|
||||
}}
|
||||
|
||||
static const int atbs_alpha[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 1,
|
||||
GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1,
|
||||
GLX_ALPHA_SIZE, 1,
|
||||
GLX_DEPTH_SIZE, 1,
|
||||
GLX_DOUBLEBUFFER,
|
||||
None};
|
||||
|
||||
//NOTE : macOS : glXChooseVisual leaks 640 bytes.
|
||||
m_vinfo = ::glXChooseVisual(m_display,m_monitor,(int*)atbs_alpha);
|
||||
if(!m_vinfo) {
|
||||
//m_out << "tools::X11::session::initialize :"
|
||||
// << " can't get a visual with alpha on screen " << m_monitor << ". Try without alpha..."
|
||||
// << std::endl;
|
||||
//m_out << "tools::X11::session::initialize :"
|
||||
// << " DefaultScreen(m_display): " << DefaultScreen(m_display) << "."
|
||||
// << std::endl;
|
||||
|
||||
static const int atbs[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 1,
|
||||
GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1,
|
||||
GLX_DEPTH_SIZE, 1,
|
||||
GLX_DOUBLEBUFFER,
|
||||
None};
|
||||
|
||||
m_vinfo = ::glXChooseVisual(m_display,m_monitor,(int*)atbs);
|
||||
if(!m_vinfo) {
|
||||
m_out << "tools::X11::session::initialize :"
|
||||
<< " can't choose a visual on screen " << m_monitor << "."
|
||||
<< std::endl;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
m_vinfo = 0;
|
||||
m_ctx = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_ctx = ::glXCreateContext(m_display,m_vinfo,NULL,GL_TRUE);
|
||||
if(!m_ctx) {
|
||||
m_out << "tools::X11::session::initialize :"
|
||||
<< " can't create a glX context with direct rendering."
|
||||
<< std::endl;
|
||||
m_ctx = ::glXCreateContext(m_display,m_vinfo,NULL,GL_FALSE);
|
||||
if(!m_ctx) {
|
||||
m_out << "tools::X11::session::initialize :"
|
||||
<< " can't create a glX context."
|
||||
<< std::endl;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
m_vinfo = 0;
|
||||
m_ctx = 0;
|
||||
return false;
|
||||
}
|
||||
//} else {
|
||||
//m_out << "tools::X11::session::initialize :"
|
||||
// << " glX context with direct rendering created."
|
||||
// << std::endl;
|
||||
}
|
||||
|
||||
// It is better to create a colormap adapted to the visual.
|
||||
m_colormap = ::XCreateColormap(m_display,::XRootWindow(m_display,m_monitor),m_vinfo->visual,AllocNone);
|
||||
//m_colormap = ::XDefaultColormap(m_display,m_monitor);
|
||||
if(m_colormap==0L) {
|
||||
m_out << "tools::X11::session::initialize : XCreateColormap failed." << std::endl;
|
||||
::XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
m_vinfo = 0;
|
||||
m_ctx = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void finalize_gl() {
|
||||
if(!m_display) return;
|
||||
if(m_ctx) {
|
||||
::glXDestroyContext(m_display,m_ctx);
|
||||
m_ctx = 0;
|
||||
}
|
||||
if(m_vinfo) {
|
||||
::XFree(m_vinfo);
|
||||
m_vinfo = 0;
|
||||
}
|
||||
if(m_colormap) {
|
||||
::XFreeColormap(m_display,m_colormap);
|
||||
m_colormap = 0;
|
||||
}
|
||||
}
|
||||
public:
|
||||
GLXContext context() const {return m_ctx;}
|
||||
|
||||
Window create_window(const char* a_title,int a_x,int a_y,unsigned int a_width,unsigned int a_height) {
|
||||
if(!m_display) return 0L;
|
||||
|
||||
XSetWindowAttributes swa;
|
||||
swa.event_mask = StructureNotifyMask | ExposureMask
|
||||
| ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
|
||||
| PointerMotionMask
|
||||
| KeyPressMask;
|
||||
|
||||
swa.colormap = m_colormap;
|
||||
swa.border_pixel = 0L;
|
||||
|
||||
Window window = ::XCreateWindow(m_display,
|
||||
::XRootWindow(m_display,m_monitor),
|
||||
a_x,a_y,a_width,a_height,
|
||||
0,
|
||||
m_vinfo->depth,
|
||||
InputOutput,
|
||||
m_vinfo->visual,
|
||||
CWBorderPixel|CWColormap|CWEventMask,&swa);
|
||||
|
||||
if(window==0L) {
|
||||
m_out << "tools::X11::session::create_window :"
|
||||
<< " can't create a X11 window."
|
||||
<< std::endl;
|
||||
return 0L;
|
||||
}
|
||||
|
||||
XTextProperty tp;
|
||||
::XStringListToTextProperty((char**)&a_title,1,&tp);
|
||||
XSizeHints sh;
|
||||
sh.flags = USPosition | USSize;
|
||||
::XSetWMProperties(m_display,window,&tp,&tp,0,0,&sh,0,0);
|
||||
::XFree(tp.value);
|
||||
|
||||
::XSetWMProtocols(m_display,window,&m_WM_DELETE_WINDOW_atom,1);
|
||||
return window;
|
||||
}
|
||||
protected:
|
||||
XVisualInfo* m_vinfo;
|
||||
GLXContext m_ctx;
|
||||
Colormap m_colormap;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_X11_simple_dispatcher
|
||||
#define tools_X11_simple_dispatcher
|
||||
|
||||
#include "base_session"
|
||||
|
||||
#include <tools/saui>
|
||||
|
||||
namespace tools {
|
||||
namespace X11 {
|
||||
|
||||
class simple_dispatcher : public dispatcher {
|
||||
typedef dispatcher parent;
|
||||
public:
|
||||
virtual void win_render() = 0;
|
||||
virtual void set_size(unsigned int a_width,unsigned int a_height) = 0;
|
||||
public:
|
||||
virtual bool dispatch(XEvent& a_event) {
|
||||
if(!m_win) return false;
|
||||
if(a_event.xany.window!=m_win) return false;
|
||||
if( (a_event.type==Expose) || (a_event.type==ConfigureNotify) ){
|
||||
int width,height;
|
||||
m_session.window_size(m_win,width,height);
|
||||
set_size(width,height); //viewer::set_size()
|
||||
win_render();
|
||||
return true;
|
||||
} else if(a_event.type==ClientMessage) {
|
||||
if(a_event.xclient.data.l[0]==(long)m_session.WM_DELETE_WINDOW_atom()) {
|
||||
m_session.post(m_win,m_session.SESSION_EXIT_STEER_atom());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
virtual Window window() const {return m_win;}
|
||||
public:
|
||||
simple_dispatcher(base_session& a_session,Window a_win)
|
||||
:parent()
|
||||
,m_session(a_session)
|
||||
,m_win(a_win)
|
||||
{}
|
||||
virtual ~simple_dispatcher(){}
|
||||
public:
|
||||
simple_dispatcher(const simple_dispatcher& a_from)
|
||||
:parent(a_from)
|
||||
,m_session(a_from.m_session)
|
||||
,m_win(a_from.m_win)
|
||||
{}
|
||||
simple_dispatcher& operator=(const simple_dispatcher& a_from) {
|
||||
parent::operator=(a_from);
|
||||
m_win = a_from.m_win;
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
base_session& m_session;
|
||||
Window m_win;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,531 @@
|
||||
/*
|
||||
#define DEBUG
|
||||
*/
|
||||
|
||||
/*this*/
|
||||
#include "OpenGLAreaP.h"
|
||||
|
||||
#include <X11/StringDefs.h>
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
static void InitializeClass(void);
|
||||
static void InitializeWidget(Widget, Widget,ArgList,Cardinal*);
|
||||
static void RealizeWidget(Widget, XtValueMask*, XSetWindowAttributes*);
|
||||
static void DestroyWidget(Widget);
|
||||
static void ChangeWidgetSize(Widget);
|
||||
static void DrawWidget(Widget, XEvent*, Region);
|
||||
static Boolean SetValues(Widget,Widget,Widget,ArgList,Cardinal *);
|
||||
|
||||
static void EventHandler(Widget,XtPointer,XEvent*,Boolean*);
|
||||
static int MakeCurrent(Widget);
|
||||
static void XWidgetInstallColormap(Widget);
|
||||
static void XWidgetUninstallColormap(Widget);
|
||||
static Widget XWidgetGetShell(Widget);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define athis ((OpenGLAreaWidget)This)->openGLArea
|
||||
#define acur ((OpenGLAreaWidget)a_current)->openGLArea
|
||||
#define CWarn printf
|
||||
#define CWarnF printf
|
||||
|
||||
static XtResource resources [] = {
|
||||
{XoNdoubleBufferOn,"DoubleBufferOn",XtRBoolean,sizeof(Boolean),
|
||||
XtOffset(OpenGLAreaWidget,openGLArea.doubleBufferOn),XtRImmediate,(XtPointer)True},
|
||||
{XoNpaintCallback,XtCCallback,XtRCallback,sizeof(XtCallbackList),
|
||||
XtOffset(OpenGLAreaWidget,openGLArea.paintCallback),XtRImmediate,(XtPointer)NULL},
|
||||
{XoNeventCallback,XtCCallback,XtRCallback,sizeof(XtCallbackList),
|
||||
XtOffset(OpenGLAreaWidget,openGLArea.eventCallback),XtRImmediate,(XtPointer)NULL}
|
||||
};
|
||||
|
||||
OpenGLAreaClassRec openGLAreaClassRec = {
|
||||
/* Core Class Part */
|
||||
{
|
||||
(WidgetClass) &compositeClassRec, /* pointer to superclass ClassRec */
|
||||
"OpenGLArea", /* widget resource class name */
|
||||
sizeof(OpenGLAreaRec), /* size in bytes of widget record */
|
||||
InitializeClass, /* class_initialize */
|
||||
NULL, /* dynamic initialization */
|
||||
FALSE, /* has class been initialized? */
|
||||
InitializeWidget, /* initialize */
|
||||
NULL, /* notify that initialize called */
|
||||
RealizeWidget, /* XCreateWindow for widget */
|
||||
NULL, /* widget semantics name to proc mapWidget*/
|
||||
0, /* number of entries in actions */
|
||||
resources, /* resources for subclass fields */
|
||||
XtNumber(resources), /* number of entries in resources */
|
||||
NULLQUARK, /* resource class quarkified */
|
||||
TRUE, /* compress MotionNotify for widget */
|
||||
TRUE, /* compress Expose events for widget*/
|
||||
TRUE, /* compress enter and leave events */
|
||||
TRUE, /* select for VisibilityNotify */
|
||||
DestroyWidget, /* free data for subclass pointers */
|
||||
ChangeWidgetSize, /* geom manager changed widget size */
|
||||
DrawWidget, /* rediplay window */
|
||||
SetValues, /* set subclass resource values */
|
||||
NULL, /* notify that SetValues called */
|
||||
XtInheritSetValuesAlmost, /* SetValues got "Almost" geo reply*/
|
||||
NULL, /* notify that get_values called */
|
||||
XtInheritAcceptFocus, /* assign input focus to widget */
|
||||
XtVersion, /* version of intrinsics used */
|
||||
NULL, /* list of callback offsets */
|
||||
XtInheritTranslations, /* translations */
|
||||
XtInheritQueryGeometry, /* return preferred geometry */
|
||||
XtInheritDisplayAccelerator, /* display your accelerator */
|
||||
NULL /* pointer to extension record */
|
||||
},
|
||||
/* Composite Class Part */
|
||||
{
|
||||
XtInheritGeometryManager, /* geometry manager for children */
|
||||
XtInheritChangeManaged, /* change managed state of child */
|
||||
XtInheritInsertChild, /* physically add child to parent */
|
||||
XtInheritDeleteChild, /* physically remove child */
|
||||
NULL /* pointer to extension record */
|
||||
},
|
||||
/* OpenGLArea */
|
||||
{
|
||||
NULL
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
WidgetClass openGLAreaWidgetClass = (WidgetClass) &openGLAreaClassRec;
|
||||
|
||||
static void InitializeClass(void) {}
|
||||
|
||||
static void InitializeWidget(Widget a_request,Widget This,ArgList a_args,Cardinal* a_argn) {
|
||||
if(a_request->core.width<=0) This->core.width = 100;
|
||||
if(a_request->core.height<=0) This->core.height = 100;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("debug : OpenGLArea : InitializeWidget : %s\n",XtName(This));
|
||||
#endif
|
||||
|
||||
athis.visual = CopyFromParent;
|
||||
athis.installColormap = False;
|
||||
athis.glContext = NULL;
|
||||
|
||||
{Display* display;
|
||||
Screen* screen;
|
||||
int iscreen;
|
||||
XVisualInfo* vinfo;
|
||||
display = XtDisplay(This);
|
||||
screen = XtScreen(This);
|
||||
iscreen = XScreenNumberOfScreen(screen);
|
||||
|
||||
{int error,event;
|
||||
if(glXQueryExtension(display,&error,&event)==0) {
|
||||
CWarn ("X server does not have OpenGL extensions.\n");
|
||||
}}
|
||||
|
||||
if(athis.doubleBufferOn==True) {
|
||||
int atbs[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 1,
|
||||
GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1,
|
||||
GLX_ALPHA_SIZE, 1,
|
||||
GLX_DEPTH_SIZE, 1,
|
||||
GLX_DOUBLEBUFFER,
|
||||
None
|
||||
};
|
||||
vinfo = glXChooseVisual (display,iscreen,atbs);
|
||||
if(vinfo==NULL) { /*GLX_ALPHA_SIZE : problem with Xming. Try without it.*/
|
||||
int atbs[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 1,
|
||||
GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1,
|
||||
GLX_DEPTH_SIZE, 1,
|
||||
GLX_DOUBLEBUFFER,
|
||||
None
|
||||
};
|
||||
vinfo = glXChooseVisual (display,iscreen,atbs);
|
||||
}
|
||||
} else {
|
||||
int atbs[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 1,
|
||||
GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1,
|
||||
GLX_ALPHA_SIZE, 1,
|
||||
GLX_DEPTH_SIZE, 1,
|
||||
None
|
||||
};
|
||||
vinfo = glXChooseVisual (display,iscreen,atbs);
|
||||
if(vinfo==NULL) { /*GLX_ALPHA_SIZE : problem with Xming. Try without it.*/
|
||||
int atbs[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 1,
|
||||
GLX_GREEN_SIZE, 1,
|
||||
GLX_BLUE_SIZE, 1,
|
||||
GLX_DEPTH_SIZE, 1,
|
||||
None
|
||||
};
|
||||
vinfo = glXChooseVisual (display,iscreen,atbs);
|
||||
}
|
||||
}
|
||||
|
||||
if(vinfo==NULL) {
|
||||
CWarn ("Can't choose a visual.\n");
|
||||
} else {
|
||||
This->core.depth = vinfo->depth;
|
||||
athis.visual = vinfo->visual;
|
||||
if( (vinfo->depth ==DefaultDepth (display,iscreen)) &&
|
||||
(vinfo->visual==DefaultVisual(display,iscreen)) ) {
|
||||
This->core.colormap = XDefaultColormap (display,iscreen);
|
||||
athis.installColormap = False;
|
||||
} else {
|
||||
This->core.colormap =
|
||||
XCreateColormap (display,XRootWindow(display,iscreen),vinfo->visual, AllocNone);
|
||||
athis.installColormap = True;
|
||||
}
|
||||
if(This->core.colormap==0L) {
|
||||
CWarn ("Can't get/create a X colormap.\n");
|
||||
}
|
||||
athis.glContext = glXCreateContext (display,vinfo,NULL,GL_FALSE);
|
||||
if(athis.glContext==NULL) {
|
||||
CWarn ("Can't create a GLX context.\n");
|
||||
}
|
||||
XFree(vinfo);
|
||||
}}
|
||||
|
||||
XtAddEventHandler(This,ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,0,EventHandler,NULL);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : InitializeWidget : end\n");
|
||||
#endif
|
||||
|
||||
/*avoid C++ warnings*/
|
||||
a_request = NULL;
|
||||
a_args = NULL;
|
||||
a_argn = 0;
|
||||
}
|
||||
|
||||
static void RealizeWidget(Widget This,XtValueMask* a_mask,XSetWindowAttributes* a_watbs) {
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : RealizeWidget : %s\n",XtName(This));
|
||||
#endif
|
||||
|
||||
/*Have to create window ourselves due to OpenGL that compells it's visual.*/
|
||||
/*In principle colormap is correctly set in a_watbs.*/
|
||||
|
||||
XtCreateWindow(This,(unsigned int)InputOutput,athis.visual,*a_mask,a_watbs);
|
||||
|
||||
/* Call the Realize procedure (XtInheritRealize) */
|
||||
if(openGLAreaWidgetClass->core_class.superclass->core_class.realize!=NULL)
|
||||
(openGLAreaWidgetClass->core_class.superclass->core_class.realize)(This, a_mask, a_watbs);
|
||||
|
||||
/*If window is delete, all seems ok.*/
|
||||
if(athis.installColormap==True) XWidgetInstallColormap(This);
|
||||
|
||||
/*MakeCurrent(This);*/
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : RealizeWidget : end\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void DestroyWidget(Widget This) {
|
||||
if(athis.installColormap==True) {
|
||||
XWidgetUninstallColormap (This);
|
||||
athis.installColormap = False;
|
||||
XFreeColormap(XtDisplay(This),This->core.colormap);
|
||||
}
|
||||
if(athis.glContext!=NULL) {
|
||||
glXMakeCurrent(XtDisplay(This),None,NULL);
|
||||
glXDestroyContext(XtDisplay(This),athis.glContext);
|
||||
athis.glContext = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#define IFMOD(a_field) if(athis.a_field != acur.a_field)
|
||||
static Boolean SetValues(Widget a_current,Widget a_request,Widget This,ArgList a_args,Cardinal* a_argn) {
|
||||
IFMOD(doubleBufferOn) {
|
||||
/* Can't change buffering here if X window is created.
|
||||
With OpenGL, buffering fix parameter of the X window.
|
||||
Buffering must be choosen before the execution of the
|
||||
Realize method that create the window. */
|
||||
if(XtIsRealized(This) && (athis.installColormap==True)) {
|
||||
CWarn("Can't change buffering after \"realization\" of the widget.\n");
|
||||
athis.doubleBufferOn = acur.doubleBufferOn;
|
||||
}
|
||||
}
|
||||
/*avoid C++ warnings*/
|
||||
a_request = NULL;
|
||||
a_args = NULL;
|
||||
a_argn = 0;
|
||||
return False;
|
||||
}
|
||||
|
||||
static void ChangeWidgetSize(Widget This) {
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : ChangeWidgetSize : %s\n",XtName(This));
|
||||
#endif
|
||||
|
||||
/* Call the Resize procedure (XtInheritResize) */
|
||||
if(openGLAreaWidgetClass->core_class.superclass->core_class.resize!=NULL)
|
||||
(openGLAreaWidgetClass->core_class.superclass->core_class.resize)(This);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : ChangeWidgetSize : end\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void DrawWidget(Widget This,XEvent* a_event,Region a_region) {
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : DrawWidget : %s\n",XtName(This));
|
||||
#endif
|
||||
|
||||
if(openGLAreaWidgetClass->core_class.superclass->core_class.expose!=NULL)
|
||||
(openGLAreaWidgetClass->core_class.superclass->core_class.expose)(This,a_event,a_region);
|
||||
|
||||
if(MakeCurrent(This)==1) {
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : DrawWidget : %s : MakeCurrent ok : call paintCallback...\n",XtName(This));
|
||||
#endif
|
||||
XoAnyCallbackStruct value;
|
||||
value.reason = XoCR_PAINT;
|
||||
value.event = a_event;
|
||||
XtCallCallbacks(This,XoNpaintCallback,(XtPointer)&value);
|
||||
glXSwapBuffers(XtDisplay(This),XtWindow(This));
|
||||
glXMakeCurrent(XtDisplay(This),None,NULL);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("debug : OpenGLArea : DrawWidget : end\n");
|
||||
#endif
|
||||
|
||||
/*avoid C++ warnings*/
|
||||
a_event = NULL;
|
||||
a_region = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/*------------------------------------------------------------------------*/
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void OpenGLAreaPaint(Widget This) {
|
||||
if(!XtIsRealized(This)) return;
|
||||
if(MakeCurrent(This)==1) {
|
||||
XoAnyCallbackStruct value;
|
||||
value.reason = XoCR_PAINT;
|
||||
value.event = 0;
|
||||
XtCallCallbacks(This,XoNpaintCallback,(XtPointer)&value);
|
||||
glXSwapBuffers(XtDisplay(This),XtWindow(This));
|
||||
glXMakeCurrent(XtDisplay(This),None,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TOOLS_XT_OPENGLAREA_HAS_GL2PS
|
||||
|
||||
#include <tools/c_gl2ps.h>
|
||||
|
||||
int OpenGLAreaWrite_gl2ps(Widget This,const char* aFileName,const char* opts) {
|
||||
FILE* file;
|
||||
int options;
|
||||
int sort;
|
||||
inlib_GLint vp[4];
|
||||
int bufsize = 0;
|
||||
static inlib_gl2ps_gl_funcs_t s_OpenGL_funcs = {
|
||||
glIsEnabled,
|
||||
glBegin,
|
||||
glEnd,
|
||||
glGetFloatv,
|
||||
glVertex3f,
|
||||
glGetBooleanv,
|
||||
glGetIntegerv,
|
||||
glRenderMode,
|
||||
glFeedbackBuffer,
|
||||
glPassThrough
|
||||
};
|
||||
|
||||
file = fopen(aFileName,"w");
|
||||
if(!file) return 1;
|
||||
|
||||
inlib_c_gl2ps_set_gl_funcs(&s_OpenGL_funcs);
|
||||
|
||||
options = TOOLS_GL2PS_OCCLUSION_CULL
|
||||
| TOOLS_GL2PS_BEST_ROOT
|
||||
| TOOLS_GL2PS_SILENT
|
||||
| TOOLS_GL2PS_DRAW_BACKGROUND;
|
||||
sort = TOOLS_GL2PS_BSP_SORT;
|
||||
//sort = TOOLS_GL2PS_SIMPLE_SORT;
|
||||
|
||||
vp[0] = 0;
|
||||
vp[1] = 0;
|
||||
vp[2] = This->core.width;
|
||||
vp[3] = This->core.height;
|
||||
|
||||
inlib_c_gl2psBeginPage("title","exlib_Xt_OpenGLArea",
|
||||
vp,TOOLS_GL2PS_EPS,sort,options,
|
||||
TOOLS_GL_RGBA,0, NULL,0,0,0,bufsize,
|
||||
file,aFileName);
|
||||
|
||||
{XoAnyCallbackStruct value;
|
||||
value.reason = XoCR_PAINT;
|
||||
value.event = 0;
|
||||
XtCallCallbacks(This,XoNpaintCallback,(XtPointer)&value);}
|
||||
|
||||
inlib_c_gl2psEndPage();
|
||||
|
||||
inlib_c_gl2ps_reset_gl_funcs();
|
||||
|
||||
fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
int OpenGLAreaWrite_gl2ps(Widget,const char*,const char*) {return 1;}
|
||||
#else
|
||||
int OpenGLAreaWrite_gl2ps(Widget w,const char* f,const char* o) {return 1;}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/*------------------------------------------------------------------------*/
|
||||
/*------------------------------------------------------------------------*/
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int MakeCurrent(Widget This) {
|
||||
if(This==NULL) return 0;
|
||||
if(!XtIsRealized(This)) return 0;
|
||||
if(athis.glContext==NULL) return 0;
|
||||
return (int)glXMakeCurrent(XtDisplay(This),XtWindow(This),athis.glContext);
|
||||
}
|
||||
|
||||
static void EventHandler(Widget This,XtPointer a_tag,XEvent* a_event ,Boolean* a_continue) {
|
||||
XoAnyCallbackStruct value;
|
||||
value.reason = XoCR_EVENT;
|
||||
value.event = a_event;
|
||||
XtCallCallbacks(This,XoNeventCallback,(XtPointer)&value);
|
||||
a_tag = NULL;
|
||||
a_continue = NULL;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/*------------------------------------------------------------------------*/
|
||||
/*------------------------------------------------------------------------*/
|
||||
static void XWidgetInstallColormap(Widget This) {
|
||||
/*
|
||||
From Mesa/widgets/GLwDrawingArea.c/post_colormap routine.
|
||||
Could use also XtSetWMColormapWindows.
|
||||
*/
|
||||
Display* display;
|
||||
XWindowAttributes watbs;
|
||||
Widget shell;
|
||||
Window* ws = NULL;
|
||||
int wn = 0,found,count;
|
||||
Window wshell,wthis;
|
||||
Colormap cmapthis;
|
||||
/*.........................................................................*/
|
||||
if(This==NULL) return;
|
||||
if( !XtIsWidget(This) || !XtIsRealized(This) ) return;
|
||||
shell = XWidgetGetShell (This);
|
||||
if(shell==NULL) return;
|
||||
display = XtDisplay (This);
|
||||
wthis = XtWindow (This);
|
||||
wshell = XtWindow (shell);
|
||||
XGetWMColormapWindows (display,wshell, &ws, &wn);
|
||||
/* Check if colormap of this is a colormap of a Window in list.*/
|
||||
XGetWindowAttributes (display,wthis,&watbs);
|
||||
cmapthis = watbs.colormap;
|
||||
found = -1;
|
||||
for(count=0;count<wn;count++) {
|
||||
Colormap cmap;
|
||||
XGetWindowAttributes (display,ws[count],&watbs);
|
||||
cmap = watbs.colormap;
|
||||
if(cmap==cmapthis) {
|
||||
XFree (ws);
|
||||
return; /*done*/
|
||||
}
|
||||
if(ws[count]==wshell) {
|
||||
found = count;
|
||||
}
|
||||
}
|
||||
/*Have to add window of this in list.*/
|
||||
if(wn==0) {
|
||||
if(ws!=NULL) XFree(ws);
|
||||
ws = (Window*)malloc ( 2 * sizeof(Window));
|
||||
} else {
|
||||
ws = (Window*)realloc (ws,(wn + 2) * sizeof(Window));
|
||||
}
|
||||
if(ws==NULL) return;
|
||||
if(found==-1) {
|
||||
/*Window of shell not in list.*/
|
||||
ws[wn] = wthis; wn++;
|
||||
ws[wn] = wshell;wn++;
|
||||
} else {
|
||||
ws[found] = wthis;
|
||||
ws[wn] = wshell; wn++; /*Shell must be last.*/
|
||||
}
|
||||
if (XSetWMColormapWindows(display,wshell, ws, wn)==0) {
|
||||
CWarnF ("XWidgetInstallColormap: can't install colormap of %s in %s.\n",XtName(This),XtName(shell));
|
||||
}
|
||||
XFree (ws);
|
||||
}
|
||||
|
||||
static void XWidgetUninstallColormap(Widget This) {
|
||||
int count;
|
||||
Widget shell;
|
||||
Display* display;
|
||||
Window wthis,wshell;
|
||||
Window* ws = NULL;
|
||||
int wn = 0;
|
||||
Window* nws = NULL;
|
||||
int nwn = 0;
|
||||
/*.........................................................................*/
|
||||
if(This==NULL) return;
|
||||
if( !XtIsWidget(This) || !XtIsRealized(This) ) return;
|
||||
shell = XWidgetGetShell (This);
|
||||
if(shell==NULL) return;
|
||||
display = XtDisplay (This);
|
||||
wthis = XtWindow (This);
|
||||
wshell = XtWindow (shell);
|
||||
XGetWMColormapWindows (display,wshell, &ws, &wn);
|
||||
if( (wn==0) || (ws==NULL) ) return;
|
||||
nws = (Window*)malloc ( wn * sizeof(Window));
|
||||
if(nws==NULL) {
|
||||
XFree (ws);
|
||||
return;
|
||||
}
|
||||
nwn = 0;
|
||||
for(count=0;count<wn;count++) {
|
||||
if(ws[count]!=wthis) {
|
||||
nws[nwn] = ws[count];
|
||||
nwn++;
|
||||
}
|
||||
}
|
||||
if(wn!=nwn) {
|
||||
if (XSetWMColormapWindows(display,wshell, nws, nwn)==0) {
|
||||
CWarnF("XWidgetUninstallColormap: can't install colormap of %s in %s.\n",XtName(This),XtName(shell));
|
||||
}
|
||||
}
|
||||
XFree (ws);
|
||||
XFree (nws);
|
||||
}
|
||||
|
||||
Widget XWidgetGetShell(Widget This) {
|
||||
Widget widget;
|
||||
if(This==NULL) return NULL;
|
||||
widget = This;
|
||||
while(1) {
|
||||
if(widget==NULL) return NULL;
|
||||
if(XtIsShell(widget)) return widget;
|
||||
widget = XtParent(widget);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
exlib_build_use Xt inlib
|
||||
*/
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef tools_Xt_OpenGLArea_h
|
||||
#define tools_Xt_OpenGLArea_h
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
typedef struct _OpenGLAreaClassRec* OpenGLAreaWidgetClass;
|
||||
typedef struct _OpenGLAreaRec* OpenGLAreaWidget;
|
||||
|
||||
typedef struct {
|
||||
int reason;
|
||||
XEvent* event;
|
||||
} XoAnyCallbackStruct;
|
||||
|
||||
/* OpenGLArea */
|
||||
#define XoNdoubleBufferOn "doubleBufferOn"
|
||||
#define XoNpaintCallback "paintCallback"
|
||||
#define XoNeventCallback "eventCallback"
|
||||
|
||||
#define XoCR_PAINT 1
|
||||
#define XoCR_EVENT 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
extern WidgetClass openGLAreaWidgetClass;
|
||||
|
||||
void OpenGLAreaPaint(Widget);
|
||||
int OpenGLAreaWrite_gl2ps(Widget,const char*,const char*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
exlib_build_use Xt
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef tools_Xt_OpenGLAreaP_h
|
||||
#define tools_Xt_OpenGLAreaP_h
|
||||
|
||||
#include "OpenGLArea.h"
|
||||
|
||||
#include <X11/IntrinsicP.h>
|
||||
#include <X11/CoreP.h>
|
||||
#include <X11/CompositeP.h>
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void* extension;
|
||||
} OpenGLAreaClassPart;
|
||||
|
||||
typedef struct _OpenGLAreaClassRec
|
||||
{
|
||||
CoreClassPart core_class;
|
||||
CompositeClassPart composite_class;
|
||||
OpenGLAreaClassPart openGLArea_class;
|
||||
} OpenGLAreaClassRec;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
extern OpenGLAreaClassRec openGLAreaClassRec;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*Resources :*/
|
||||
Boolean doubleBufferOn;
|
||||
XtCallbackList paintCallback;
|
||||
XtCallbackList eventCallback;
|
||||
/**/
|
||||
Visual* visual;
|
||||
Boolean installColormap;
|
||||
GLXContext glContext;
|
||||
} OpenGLAreaPart;
|
||||
|
||||
typedef struct _OpenGLAreaRec
|
||||
{
|
||||
CorePart core;
|
||||
CompositePart composite;
|
||||
OpenGLAreaPart openGLArea;
|
||||
} OpenGLAreaRec;
|
||||
|
||||
#endif
|
||||
/*
|
||||
exlib_build_use Xt
|
||||
*/
|
||||
@@ -0,0 +1,204 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Xt_tools
|
||||
#define tools_Xt_tools
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/StringDefs.h>
|
||||
#include <string>
|
||||
|
||||
inline Widget XWidgetGetShell(Widget aWidget){
|
||||
Widget widget = aWidget;
|
||||
while(1) {
|
||||
if(!widget) return 0;
|
||||
if(XtIsShell(widget)) return widget;
|
||||
widget = XtParent(widget);
|
||||
}
|
||||
}
|
||||
|
||||
inline Pixel XWidgetGetPixelResource(Widget aWidget,const std::string& aName){
|
||||
Pixel pixel = 0L;
|
||||
Arg args[1];
|
||||
XtSetArg(args[0],(char*)aName.c_str(),&pixel);
|
||||
XtGetValues(aWidget,args,1);
|
||||
return pixel;
|
||||
}
|
||||
|
||||
inline Pixel XWidgetConvertStringToPixel(Widget aWidget,const std::string& aString){
|
||||
if(aString.empty()) return 0L;
|
||||
if( (aString=="None") || (aString=="none") )
|
||||
return XWidgetGetPixelResource(aWidget,std::string(XtNbackground));
|
||||
XrmValue from,to;
|
||||
from.size = aString.size()+1;
|
||||
from.addr = (XPointer)aString.c_str();
|
||||
XtConvert(aWidget,XtRString,&from,XtRPixel,&to);
|
||||
if(to.addr==NULL) return 0L;
|
||||
return (*((Pixel*)to.addr));
|
||||
}
|
||||
inline void XWidgetSetString(Widget aWidget,const std::string& aName,const std::string& aValue,bool aFreePrevious = false){
|
||||
if(aFreePrevious) {
|
||||
char* s = NULL;
|
||||
Arg args[1];
|
||||
XtSetArg(args[0],(char*)aName.c_str(),&s);
|
||||
XtGetValues(aWidget,args,1);
|
||||
if(s!=NULL) XtFree(s);
|
||||
}
|
||||
Arg args[1];
|
||||
XtSetArg(args[0],(char*)aName.c_str(),XtNewString(aValue.c_str()));
|
||||
XtSetValues(aWidget,args,1);
|
||||
}
|
||||
inline bool XWidgetGetString(Widget aWidget,const std::string& aName,std::string& a_value){
|
||||
// XtNgeometry, XtNtitle.
|
||||
char* s = NULL;
|
||||
Arg args[1];
|
||||
XtSetArg(args[0],(char*)aName.c_str(),&s);
|
||||
XtGetValues(aWidget,args,1);
|
||||
if(s==NULL) {a_value.clear();return false;}
|
||||
a_value = std::string(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
inline bool XWidgetSendMessage(Widget aWidget,long a_1,long a_2) {
|
||||
XClientMessageEvent event;
|
||||
if(!XtIsRealized(aWidget)) return 0;
|
||||
event.type = ClientMessage;
|
||||
event.display = XtDisplay(aWidget);
|
||||
event.window = XtWindow(aWidget);
|
||||
event.message_type = XA_INTEGER;
|
||||
event.format = 8;
|
||||
event.data.l[0] = a_1;
|
||||
event.data.l[1] = a_2;
|
||||
event.data.l[2] = 0L;
|
||||
event.data.l[3] = 0L;
|
||||
event.data.l[4] = 0L;
|
||||
if(XSendEvent(event.display,event.window,False,0L,(XEvent*)&event)==0)
|
||||
return false;
|
||||
XFlush(event.display);
|
||||
return true;
|
||||
}
|
||||
|
||||
#include <X11/IntrinsicP.h>
|
||||
|
||||
inline void XClassGetName(WidgetClass aClass,std::string& a_value){
|
||||
a_value = std::string((char*)aClass->core_class.class_name);
|
||||
}
|
||||
inline Boolean XClassIsSubclass(WidgetClass aClass,WidgetClass aParent){
|
||||
for (WidgetClass wc = aClass; wc != NULL; wc = wc->core_class.superclass)
|
||||
if (wc == aParent) return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
inline Position XWidgetGetX(Widget aWidget){return aWidget->core.x;}
|
||||
inline Position XWidgetGetY(Widget aWidget){return aWidget->core.y;}
|
||||
inline Dimension XWidgetGetWidth(Widget aWidget){return aWidget->core.width;}
|
||||
inline Dimension XWidgetGetHeight(Widget aWidget){return aWidget->core.height;}
|
||||
inline void XWidgetGetClassName(Widget aWidget,std::string& a_value) {
|
||||
WidgetClass wc = XtClass(aWidget);
|
||||
a_value = std::string((char*)wc->core_class.class_name);
|
||||
}
|
||||
inline void XWidgetCompellResize(Widget aWidget){
|
||||
if(aWidget->core.widget_class->core_class.resize==NULL) return;
|
||||
(aWidget->core.widget_class->core_class.resize)(aWidget);
|
||||
}
|
||||
|
||||
#include <X11/CompositeP.h>
|
||||
inline int XWidgetGetChildrenNumber(Widget aWidget){
|
||||
if(!XtIsComposite(aWidget)) return 0;
|
||||
CompositePart* cwp = &(((CompositeWidget)aWidget)->composite);
|
||||
return cwp->num_children;
|
||||
}
|
||||
inline Widget XWidgetGetChild(Widget aWidget,unsigned int aIndex){
|
||||
if(!XtIsComposite(aWidget)) return 0;
|
||||
CompositePart* cwp = &(((CompositeWidget)aWidget)->composite);
|
||||
if(aIndex>=cwp->num_children) return 0;
|
||||
return cwp->children[aIndex];
|
||||
}
|
||||
inline Widget XWidgetGetFirstChild(Widget aWidget){
|
||||
if(!XtIsComposite(aWidget)) return 0;
|
||||
CompositePart* cwp = &(((CompositeWidget)aWidget)->composite);
|
||||
return (cwp->num_children?cwp->children[0]:0);
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
|
||||
inline void XWidgetGetChildren(Widget aWidget,std::vector<Widget>& aList){
|
||||
aList.clear();
|
||||
if(!XtIsComposite(aWidget)) return;
|
||||
CompositePart* cwp = &(((CompositeWidget)aWidget)->composite);
|
||||
for (unsigned int count=0;count<cwp->num_children;count++)
|
||||
aList.push_back(cwp->children[count]);
|
||||
}
|
||||
inline void XWidgetGetPopupChildren(Widget aWidget,std::vector<Widget>& aList){
|
||||
aList.clear();
|
||||
if(!XtIsWidget(aWidget)) return;
|
||||
for(int count=0;count<aWidget->core.num_popups;count++) {
|
||||
aList.push_back(aWidget->core.popup_list[count]);
|
||||
}
|
||||
}
|
||||
inline Widget XWidgetFindChild(Widget aWidget,const std::string& aName){
|
||||
if(!XtIsComposite(aWidget)) return 0;
|
||||
CompositePart* cwp = &(((CompositeWidget)aWidget)->composite);
|
||||
for (unsigned int count=0;count<cwp->num_children;count++) {
|
||||
if(aName==std::string(XtName(cwp->children[count])))
|
||||
return cwp->children[count];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <ostream>
|
||||
|
||||
inline void XWidgetPrintChildren(Widget aWidget,std::ostream& a_out){
|
||||
int number = XWidgetGetChildrenNumber(aWidget);
|
||||
a_out << "XWidgetPrintChildren :"
|
||||
<< " " << (unsigned long)aWidget
|
||||
<< " number " << number
|
||||
<< std::endl;
|
||||
std::string scls;
|
||||
for(int index=0;index<number;index++) {
|
||||
Widget child = XWidgetGetChild(aWidget,index);
|
||||
XWidgetGetClassName(child,scls);
|
||||
a_out << " index = " << index
|
||||
<< ", child = " << (unsigned long)child
|
||||
<< ", class = " << scls
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
inline void XWidgetDumpPopupChildren(Widget aWidget,std::ostream& a_out){
|
||||
a_out << "XWidgetDumpPopupChildren :"
|
||||
<< " " << std::string(XtName(aWidget))
|
||||
<< std::endl;
|
||||
if(!XtIsWidget(aWidget)) return;
|
||||
a_out << " " << aWidget->core.num_popups << " popup children." << std::endl;
|
||||
std::string scls;
|
||||
for (unsigned int count=0;count<aWidget->core.num_popups;count++) {
|
||||
Widget w = aWidget->core.popup_list[count];
|
||||
XWidgetGetClassName(w,scls);
|
||||
a_out << " " << count
|
||||
<< " child class " << scls
|
||||
<< " name " << std::string(XtName(w))
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
inline void XWidgetDumpChildren(Widget aWidget,std::ostream& a_out){
|
||||
a_out << "XWidgetDumpChildren :"
|
||||
<< " " << std::string(XtName(aWidget))
|
||||
<< std::endl;
|
||||
if(!XtIsComposite(aWidget)) return;
|
||||
CompositePart* cwp = &(((CompositeWidget)aWidget)->composite);
|
||||
a_out << " " << cwp->num_children << " children." << std::endl;
|
||||
std::string scls;
|
||||
for (unsigned int count=0;count<cwp->num_children;count++) {
|
||||
Widget w = cwp->children[count];
|
||||
XWidgetGetClassName(w,scls);
|
||||
a_out << " " << count
|
||||
<< " child class " << scls
|
||||
<< " name " << std::string(XtName(w))
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -150,8 +150,12 @@ protected:
|
||||
}
|
||||
public:
|
||||
std::ostream& out() const {return m_out;}
|
||||
const std::vector<base_col*>& cols() const {return m_cols;}
|
||||
size_t columns() const {return m_cols.size();}
|
||||
const std::vector<base_col*>& columns() const {return m_cols;}
|
||||
size_t number_of_columns() const {return m_cols.size();}
|
||||
|
||||
#ifdef tools_aida_ntuple
|
||||
const std::vector<base_col*>& cols() const {return m_cols;} //deprecated : use columns().
|
||||
#endif
|
||||
|
||||
void column_names(std::vector<std::string>& a_names) const {
|
||||
a_names.clear();
|
||||
@@ -165,6 +169,11 @@ public:
|
||||
if(m_cols.empty()) return 0;
|
||||
return m_cols.front()->num_elems();
|
||||
}
|
||||
bool number_of_entries(uint64& a_value) const {
|
||||
if(m_cols.empty()) {a_value = 0;return false;}
|
||||
a_value = m_cols.front()->num_elems();
|
||||
return true;
|
||||
}
|
||||
|
||||
void clear() { //must not be confused with reset().
|
||||
safe_clear<base_col>(m_cols);
|
||||
@@ -214,6 +223,7 @@ public:
|
||||
void add_column(base_col* a_col) { //we take ownership.
|
||||
m_cols.push_back(a_col);
|
||||
}
|
||||
|
||||
protected:
|
||||
void set_columns_index(uint64 a_index) {
|
||||
tools_vforit(base_col*,m_cols,it) {
|
||||
@@ -582,6 +592,52 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool column_min(unsigned int a_col,T& a_value) {
|
||||
a_value = T();
|
||||
if(m_cols.empty()) return false;
|
||||
if(a_col>=m_cols.size()) return false;
|
||||
base_col* _base_col = m_cols[a_col];
|
||||
aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
|
||||
if(!_col) return false;
|
||||
start();
|
||||
uint64 _rows = rows();
|
||||
T v;
|
||||
{for(uint64 row=0;row<_rows;row++) {
|
||||
if(!next()) {a_value = T();return false;}
|
||||
if(!_col->get_entry(v)) {}
|
||||
if(!row) {
|
||||
a_value = v;
|
||||
} else {
|
||||
a_value = mn<T>(a_value,v);
|
||||
}
|
||||
}}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool column_max(unsigned int a_col,T& a_value) {
|
||||
a_value = T();
|
||||
if(m_cols.empty()) return false;
|
||||
if(a_col>=m_cols.size()) return false;
|
||||
base_col* _base_col = m_cols[a_col];
|
||||
aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
|
||||
if(!_col) return false;
|
||||
start();
|
||||
uint64 _rows = rows();
|
||||
T v;
|
||||
{for(uint64 row=0;row<_rows;row++) {
|
||||
if(!next()) {a_value = T();return false;}
|
||||
if(!_col->get_entry(v)) {}
|
||||
if(!row) {
|
||||
a_value = v;
|
||||
} else {
|
||||
a_value = mx<T>(a_value,v);
|
||||
}
|
||||
}}
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -1064,7 +1120,7 @@ inline bool create_cols_from_string(ntuple& a_ntu,
|
||||
}
|
||||
|
||||
inline aida_col_ntu* find_col_ntu(ntuple& a_ntu,const std::string& a_name){
|
||||
base_col* col = find_named<base_col>(a_ntu.cols(),a_name);
|
||||
base_col* col = find_named<base_col>(a_ntu.columns(),a_name);
|
||||
if(!col) return 0;
|
||||
return safe_cast<base_col, aida_col_ntu >(*col);
|
||||
}
|
||||
@@ -1138,7 +1194,7 @@ protected:
|
||||
// Note : it is assumed that a_is is empty and a_found = false before
|
||||
// calling with function.
|
||||
|
||||
const std::vector<base_col*>& cols = a_ntu.cols();
|
||||
const std::vector<base_col*>& cols = a_ntu.columns();
|
||||
|
||||
// look if a_col is a leaf col of a_ntu :
|
||||
{unsigned int index = 0;
|
||||
@@ -1175,7 +1231,7 @@ protected:
|
||||
if(a_depth>=a_is.size()) return false;
|
||||
|
||||
unsigned int coli = a_is[a_depth];
|
||||
const std::vector<base_col*>& cols = a_sub.cols();
|
||||
const std::vector<base_col*>& cols = a_sub.columns();
|
||||
if(coli>=cols.size()) return false;
|
||||
|
||||
if(a_depth==(a_is.size()-1)) { //we reach the leaf.
|
||||
@@ -1312,7 +1368,7 @@ inline bool column_infos(base_ntu& a_ntu,
|
||||
}
|
||||
|
||||
inline base_col* find_leaf_column(const base_ntu& a_ntu,const std::string& a_name){
|
||||
const std::vector<base_col*>& cols = a_ntu.cols();
|
||||
const std::vector<base_col*>& cols = a_ntu.columns();
|
||||
tools_vforcit(base_col*,cols,it) {
|
||||
aida_col_ntu* col = safe_cast<base_col,aida_col_ntu>(*(*it));
|
||||
if(col) {
|
||||
@@ -1330,7 +1386,7 @@ inline base_col* find_leaf_column(const base_ntu& a_ntu,const std::string& a_nam
|
||||
template <class T>
|
||||
inline bool to_vector(base_ntu& a_ntu,std::vector<double>& a_vec,unsigned int a_col = 0) {
|
||||
a_vec.clear();
|
||||
const std::vector<base_col*>& cols = a_ntu.cols();
|
||||
const std::vector<base_col*>& cols = a_ntu.columns();
|
||||
if(cols.empty()) return false;
|
||||
if(a_col>=cols.size()) return false;
|
||||
base_col* _base_col = cols[a_col];
|
||||
@@ -1349,51 +1405,13 @@ inline bool to_vector(base_ntu& a_ntu,std::vector<double>& a_vec,unsigned int a_
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool column_min(base_ntu& a_ntu,unsigned int a_col,T& a_value) {
|
||||
a_value = T();
|
||||
const std::vector<base_col*>& cols = a_ntu.cols();
|
||||
if(cols.empty()) return false;
|
||||
if(a_col>=cols.size()) return false;
|
||||
base_col* _base_col = cols[a_col];
|
||||
aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
|
||||
if(!_col) return false;
|
||||
a_ntu.start();
|
||||
uint64 _rows = a_ntu.rows();
|
||||
T v;
|
||||
{for(uint64 row=0;row<_rows;row++) {
|
||||
if(!a_ntu.next()) {a_value = T();return false;}
|
||||
if(!_col->get_entry(v)) {}
|
||||
if(!row) {
|
||||
a_value = v;
|
||||
} else {
|
||||
a_value = mn<T>(a_value,v);
|
||||
}
|
||||
}}
|
||||
return true;
|
||||
inline bool column_min(ntuple& a_ntu,unsigned int a_col,T& a_value) {
|
||||
return a_ntu.column_min(a_col,a_value);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool column_max(base_ntu& a_ntu,unsigned int a_col,T& a_value) {
|
||||
a_value = T();
|
||||
const std::vector<base_col*>& cols = a_ntu.cols();
|
||||
if(cols.empty()) return false;
|
||||
if(a_col>=cols.size()) return false;
|
||||
base_col* _base_col = cols[a_col];
|
||||
aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
|
||||
if(!_col) return false;
|
||||
a_ntu.start();
|
||||
uint64 _rows = a_ntu.rows();
|
||||
T v;
|
||||
{for(uint64 row=0;row<_rows;row++) {
|
||||
if(!a_ntu.next()) {a_value = T();return false;}
|
||||
if(!_col->get_entry(v)) {}
|
||||
if(!row) {
|
||||
a_value = v;
|
||||
} else {
|
||||
a_value = mx<T>(a_value,v);
|
||||
}
|
||||
}}
|
||||
return true;
|
||||
inline bool column_max(ntuple& a_ntu,unsigned int a_col,T& a_value) {
|
||||
return a_ntu.column_max(a_col,a_value);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "sto"
|
||||
#include "forit"
|
||||
#include "mnmx"
|
||||
//#include "squote"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
@@ -49,18 +50,17 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
args(const std::vector<std::string>& a_args){
|
||||
args(const std::vector<std::string>& a_args,bool a_strip = false){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
add(a_args);
|
||||
add(a_args,a_strip);
|
||||
}
|
||||
args(const std::vector<arg>& a_args):m_args(a_args){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
//args(const std::string& a_args,const std::string& a_sep = " ",bool a_strip = false){
|
||||
args(const std::string& a_args,const std::string& a_sep,bool a_strip){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
}
|
||||
public:
|
||||
const std::vector<arg>& get_args() const {return m_args;}
|
||||
//std::vector<arg>& get_args() {return m_args;}
|
||||
|
||||
bool is_arg(const std::string& a_string) const {
|
||||
tools_vforcit(arg,m_args,it) {
|
||||
@@ -96,7 +97,7 @@ public:
|
||||
bool is_empty() const {return m_args.size()?false:true;}
|
||||
size_t size() const {return m_args.size();}
|
||||
size_t number() const {return m_args.size();} //back comp.
|
||||
bool find(const std::string& a_key,std::string& a_value,const std::string& a_def = "") const {
|
||||
bool find(const std::string& a_key,std::string& a_value,const std::string& a_def = std::string()) const {
|
||||
tools_vforcit(arg,m_args,it) {
|
||||
if((*it).first==a_key) {
|
||||
a_value = (*it).second;
|
||||
@@ -115,8 +116,8 @@ public:
|
||||
return vals;
|
||||
}
|
||||
#endif
|
||||
void find(const std::string& a_key,std::vector<std::string>& a_vals) const {
|
||||
a_vals.clear();
|
||||
void find(const std::string& a_key,std::vector<std::string>& a_vals,bool a_clear=true) const {
|
||||
if(a_clear) a_vals.clear();
|
||||
tools_vforcit(arg,m_args,it) {
|
||||
if((*it).first==a_key) a_vals.push_back((*it).second);
|
||||
}
|
||||
@@ -166,7 +167,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool add(const std::string& a_key,const std::string& a_value = "",bool a_override = true){
|
||||
bool add(const std::string& a_key,const std::string& a_value = std::string(),bool a_override = true){
|
||||
if(a_override) {
|
||||
tools_vforit(arg,m_args,it) {
|
||||
if((*it).first==a_key) {
|
||||
@@ -180,19 +181,40 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool insert_begin(const std::string& a_key,const std::string& a_value = std::string(),bool a_override = true){
|
||||
if(a_override) {
|
||||
tools_vforit(arg,m_args,it) {
|
||||
if((*it).first==a_key) {
|
||||
(*it).second = a_value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(a_key.empty()) return false;
|
||||
m_args.insert(m_args.begin(),arg(a_key,a_value));
|
||||
return true;
|
||||
}
|
||||
|
||||
void add(const std::vector<std::string>& a_args,bool a_strip = false) {
|
||||
tools_vforcit(std::string,a_args,it) {
|
||||
std::vector<std::string> ws;
|
||||
words((*it),"=",false,ws);
|
||||
if(ws.size()==1) {
|
||||
if(a_strip) strip(ws[0],both,' ');
|
||||
m_args.push_back(arg(ws[0],""));
|
||||
} else if(ws.size()>=2) {
|
||||
const std::string& sarg = *it;
|
||||
std::string::size_type pos = sarg.find('=');
|
||||
if(pos==std::string::npos) {
|
||||
if(a_strip) {
|
||||
strip(ws[0],both,' ');
|
||||
strip(ws[1],both,' ');
|
||||
std::string left = sarg;
|
||||
strip(left,both,' ');
|
||||
m_args.push_back(arg(left,""));
|
||||
} else {
|
||||
m_args.push_back(arg(sarg,""));
|
||||
}
|
||||
m_args.push_back(arg(ws[0],ws[1]));
|
||||
} else {
|
||||
std::string left = sarg.substr(0,pos);
|
||||
std::string right = sarg.substr((pos+1),sarg.size()-(pos+1));
|
||||
if(a_strip) {
|
||||
strip(left,both,' ');
|
||||
strip(right,both,' ');
|
||||
}
|
||||
m_args.push_back(arg(left,right));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,6 +240,11 @@ public:
|
||||
tools_vforcit(arg,a_args,it) m_args.push_back(*it);
|
||||
}
|
||||
|
||||
void add(const args& a_from){
|
||||
tools_vforcit(arg,a_from.m_args,it) m_args.push_back(*it);
|
||||
}
|
||||
|
||||
|
||||
int remove(const std::string& a_key){
|
||||
size_t nbeg = m_args.size();
|
||||
for(std::vector<arg>::iterator it = m_args.begin();it!=m_args.end();) {
|
||||
@@ -262,9 +289,25 @@ public:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool file(std::string& a_file,bool a_remove) {
|
||||
std::string slast;
|
||||
std::string s;
|
||||
if((m_args.size()>1) //first arg is the program name !
|
||||
&& last(slast,s)
|
||||
&& (slast.find('-')!=0)
|
||||
&& (s.empty()) ) {
|
||||
a_file = slast; //Last argument is not an option.
|
||||
if(a_remove) m_args.erase(m_args.end()-1);
|
||||
return true;
|
||||
} else {
|
||||
a_file.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void files(std::vector<std::string>& a_files,bool a_skip_first = true) const {
|
||||
a_files.clear();
|
||||
void not_hyphens(std::vector<std::string>& a_not_hyphens,bool a_skip_first = false) const {
|
||||
a_not_hyphens.clear();
|
||||
// Get the serie of trailing args not beginning with '-'
|
||||
// and without a value (not of the form [-]xxx=yyy).
|
||||
// Note that an argument like that in between arguments
|
||||
@@ -274,12 +317,26 @@ public:
|
||||
if(a_skip_first) it++;
|
||||
for(;it!=m_args.end();++it) {
|
||||
if( ((*it).first.find('-')==0) || (*it).second.size() ) {
|
||||
a_files.clear();
|
||||
a_not_hyphens.clear();
|
||||
} else {
|
||||
a_files.push_back((*it).first);
|
||||
a_not_hyphens.push_back((*it).first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void files(std::vector<std::string>& a_files,bool a_skip_first = true) const { //true and not false as in the upper.
|
||||
return not_hyphens(a_files,a_skip_first);
|
||||
}
|
||||
|
||||
bool first_not_hyphen(std::string& a_first,bool a_skip_first = false) const {
|
||||
std::vector<std::string> _ss;
|
||||
not_hyphens(_ss,a_skip_first);
|
||||
if(_ss.empty()) {a_first.clear();return false;}
|
||||
a_first = _ss[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
//bool first_of_files(std::string& a_file,bool a_skip_first) const {return first_of_hyphen(a_file,a_skip_first);}
|
||||
|
||||
bool argcv(int& a_argc,char**& a_argv) const {
|
||||
// If using with :
|
||||
@@ -319,22 +376,44 @@ public:
|
||||
a_argc = 0;
|
||||
a_argv = 0;
|
||||
}
|
||||
bool known_options(const std::vector<std::string>& a_opts) const {
|
||||
|
||||
bool known_options(const std::vector<std::string>& a_knowns) const {
|
||||
tools_vforcit(arg,m_args,it) {
|
||||
if((*it).first.find('-')==0) { //find '-' at first pos.
|
||||
bool found = false;
|
||||
tools_vforcit(std::string,a_opts,it2) {
|
||||
tools_vforcit(std::string,a_knowns,it2) {
|
||||
if((*it).first==(*it2)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found) return false;
|
||||
if(!found) return false; //one option not in a_knowns.
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true; //all options are in a_knowns.
|
||||
}
|
||||
|
||||
bool known_options(const std::string& a_known) const {
|
||||
tools_vforcit(arg,m_args,it) {
|
||||
if((*it).first.find('-')==0) { //find '-' at first pos.
|
||||
if((*it).first!=a_known) return false; //one option not a_known.
|
||||
}
|
||||
}
|
||||
return true; //all options are a_known.
|
||||
}
|
||||
|
||||
//void remove_string_delimiters_in_keys() {
|
||||
// tools_vforit(arg,m_args,it) {
|
||||
// if(!rm_quotes((*it).first)) rm_double_quotes((*it).first);
|
||||
// }
|
||||
//}
|
||||
|
||||
//void remove_string_delimiters_in_values() {
|
||||
// tools_vforit(arg,m_args,it) {
|
||||
// if(!rm_quotes((*it).second)) rm_double_quotes((*it).second);
|
||||
// }
|
||||
//}
|
||||
|
||||
void files_at_end(bool a_skip_first = true) {
|
||||
// reorder to have "file" arguments at end.
|
||||
if(m_args.empty()) return;
|
||||
@@ -361,7 +440,7 @@ public:
|
||||
}
|
||||
|
||||
//NOTE : print is a Python keyword.
|
||||
void dump(std::ostream& a_out,const std::string& a_comment = "",const std::string& a_prefix = "") const {
|
||||
void dump(std::ostream& a_out,const std::string& a_comment = std::string(),const std::string& a_prefix = std::string()) const {
|
||||
if(a_comment.size()) a_out << a_comment << std::endl;
|
||||
tools_vforcit(arg,m_args,it) {
|
||||
a_out << a_prefix << "key = " << sout((*it).first) << ", value = " << sout((*it).second) << std::endl;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace tools {
|
||||
|
||||
class colorf : public vec4f {
|
||||
typedef vec4f parent;
|
||||
public: //for swig
|
||||
public: //for SWIG
|
||||
typedef unsigned char uchar;
|
||||
public:
|
||||
TOOLS_SCLASS(tools::colorf) //for stype()
|
||||
@@ -155,7 +155,7 @@ struct cmp_colorf {
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef TOOLS_MEM
|
||||
#if defined(TOOLS_MEM) && !defined(TOOLS_MEM_ATEXIT)
|
||||
inline const colorf& colorf_default() {static const colorf s_v(0.8f,0.8f,0.8f,1,false);return s_v;}
|
||||
#else
|
||||
inline const colorf& colorf_default() {static const colorf s_v(0.8f,0.8f,0.8f,1);return s_v;}
|
||||
|
||||
@@ -9,89 +9,104 @@
|
||||
|
||||
namespace tools {
|
||||
|
||||
#define TOOLS_COLORFS_STAT(a__name,a__r,a__g,a__b) \
|
||||
#define TOOLS_COLORFS_STAT(a__name) \
|
||||
inline const colorf& colorf_##a__name() {return get_color_##a__name<colorf>();}
|
||||
|
||||
//NOTE : false in the upper so that mem balance is ok at exit.
|
||||
|
||||
//0-9
|
||||
TOOLS_COLORFS_STAT(aquamarine,0.496101F,0.996109F,0.828138F)
|
||||
TOOLS_COLORFS_STAT(mediumaquamarine,0.398444F,0.800793F,0.664073F)
|
||||
TOOLS_COLORFS_STAT(black,0,0,0)
|
||||
TOOLS_COLORFS_STAT(blue,0,0,1)
|
||||
TOOLS_COLORFS_STAT(cadetblue,0.371099F,0.617197F,0.62501F)
|
||||
TOOLS_COLORFS_STAT(cornflowerblue,0.390631F,0.58204F,0.925795F)
|
||||
TOOLS_COLORFS_STAT(darkslateblue,0.281254F,0.238285F,0.542977F)
|
||||
TOOLS_COLORFS_STAT(lightblue,0.675792F,0.843763F,0.898451F)
|
||||
TOOLS_COLORFS_STAT(lightsteelblue,0.68751F,0.765637F,0.867201F)
|
||||
TOOLS_COLORFS_STAT(mediumblue,0,0,0.800793F)
|
||||
TOOLS_COLORFS_STAT(aquamarine)
|
||||
TOOLS_COLORFS_STAT(mediumaquamarine)
|
||||
TOOLS_COLORFS_STAT(black)
|
||||
TOOLS_COLORFS_STAT(blue)
|
||||
TOOLS_COLORFS_STAT(cadetblue)
|
||||
TOOLS_COLORFS_STAT(cornflowerblue)
|
||||
TOOLS_COLORFS_STAT(darkslateblue)
|
||||
TOOLS_COLORFS_STAT(lightblue)
|
||||
TOOLS_COLORFS_STAT(lightsteelblue)
|
||||
TOOLS_COLORFS_STAT(mediumblue)
|
||||
|
||||
//10-19
|
||||
TOOLS_COLORFS_STAT(mediumslateblue,0.480476F,0.406256F,0.929702F)
|
||||
TOOLS_COLORFS_STAT(midnightblue,0.0976577F,0.0976577F,0.437507F)
|
||||
TOOLS_COLORFS_STAT(navyblue,0,0,0.500008F)
|
||||
TOOLS_COLORFS_STAT(navy,0,0,0.500008F)
|
||||
TOOLS_COLORFS_STAT(skyblue,0.527352F,0.8047F,0.917983F)
|
||||
TOOLS_COLORFS_STAT(slateblue,0.414069F,0.351568F,0.800793F)
|
||||
TOOLS_COLORFS_STAT(steelblue,0.273442F,0.50782F,0.703136F)
|
||||
TOOLS_COLORFS_STAT(coral,0.996109F,0.496101F,0.312505F)
|
||||
TOOLS_COLORFS_STAT(cyan,0,1,1)
|
||||
TOOLS_COLORFS_STAT(firebrick,0.695323F,0.132815F,0.132815F)
|
||||
TOOLS_COLORFS_STAT(mediumslateblue)
|
||||
TOOLS_COLORFS_STAT(midnightblue)
|
||||
TOOLS_COLORFS_STAT(navyblue)
|
||||
TOOLS_COLORFS_STAT(navy)
|
||||
TOOLS_COLORFS_STAT(skyblue)
|
||||
TOOLS_COLORFS_STAT(slateblue)
|
||||
TOOLS_COLORFS_STAT(steelblue)
|
||||
TOOLS_COLORFS_STAT(coral)
|
||||
TOOLS_COLORFS_STAT(cyan)
|
||||
TOOLS_COLORFS_STAT(firebrick)
|
||||
|
||||
//20-29
|
||||
TOOLS_COLORFS_STAT(brown,0.644541F,0.164065F,0.164065F)
|
||||
TOOLS_COLORFS_STAT(gold,0.996109F,0.839857F,0)
|
||||
TOOLS_COLORFS_STAT(goldenrod,0.851575F,0.644541F,0.125002F)
|
||||
TOOLS_COLORFS_STAT(green,0,1,0)
|
||||
TOOLS_COLORFS_STAT(darkgreen,0,0.390631F,0)
|
||||
TOOLS_COLORFS_STAT(darkolivegreen,0.332036F,0.417975F,0.183597F)
|
||||
TOOLS_COLORFS_STAT(forestgreen,0.132815F,0.542977F,0.132815F)
|
||||
TOOLS_COLORFS_STAT(limegreen,0.195315F,0.800793F,0.195315F)
|
||||
TOOLS_COLORFS_STAT(mediumseagreen,0.234379F,0.699229F,0.441413F)
|
||||
TOOLS_COLORFS_STAT(mediumspringgreen,0,0.976577F,0.601572F)
|
||||
TOOLS_COLORFS_STAT(brown)
|
||||
TOOLS_COLORFS_STAT(gold)
|
||||
TOOLS_COLORFS_STAT(goldenrod)
|
||||
TOOLS_COLORFS_STAT(green)
|
||||
TOOLS_COLORFS_STAT(darkgreen)
|
||||
TOOLS_COLORFS_STAT(darkolivegreen)
|
||||
TOOLS_COLORFS_STAT(forestgreen)
|
||||
TOOLS_COLORFS_STAT(limegreen)
|
||||
TOOLS_COLORFS_STAT(mediumseagreen)
|
||||
TOOLS_COLORFS_STAT(mediumspringgreen)
|
||||
|
||||
//30-39
|
||||
TOOLS_COLORFS_STAT(palegreen,0.593759F,0.980484F,0.593759F)
|
||||
TOOLS_COLORFS_STAT(seagreen,0.17969F,0.542977F,0.339849F)
|
||||
TOOLS_COLORFS_STAT(springgreen,0,0.996109F,0.496101F)
|
||||
TOOLS_COLORFS_STAT(yellowgreen,0.601572F,0.800793F,0.195315F)
|
||||
TOOLS_COLORFS_STAT(darkslategrey,0.183597F,0.308598F,0.308598F)
|
||||
TOOLS_COLORFS_STAT(dimgrey,0.410163F,0.410163F,0.410163F)
|
||||
TOOLS_COLORFS_STAT(lightgrey,0.824231F,0.824231F,0.824231F)
|
||||
TOOLS_COLORFS_STAT(grey,0.750011F,0.750011F,0.750011F)
|
||||
TOOLS_COLORFS_STAT(khaki,0.937514F,0.898451F,0.546883F)
|
||||
TOOLS_COLORFS_STAT(magenta,1,0,1)
|
||||
TOOLS_COLORFS_STAT(palegreen)
|
||||
TOOLS_COLORFS_STAT(seagreen)
|
||||
TOOLS_COLORFS_STAT(springgreen)
|
||||
TOOLS_COLORFS_STAT(yellowgreen)
|
||||
TOOLS_COLORFS_STAT(darkslategrey)
|
||||
TOOLS_COLORFS_STAT(dimgrey)
|
||||
TOOLS_COLORFS_STAT(lightgrey)
|
||||
TOOLS_COLORFS_STAT(grey)
|
||||
TOOLS_COLORFS_STAT(khaki)
|
||||
TOOLS_COLORFS_STAT(magenta)
|
||||
|
||||
//40-49
|
||||
TOOLS_COLORFS_STAT(maroon,0.68751F,0.187503F,0.375006F)
|
||||
TOOLS_COLORFS_STAT(orange,0.996109F,0.644541F,0)
|
||||
TOOLS_COLORFS_STAT(orchid,0.851575F,0.437507F,0.83595F)
|
||||
TOOLS_COLORFS_STAT(darkorchid,0.597665F,0.195315F,0.796887F)
|
||||
TOOLS_COLORFS_STAT(mediumorchid,0.726574F,0.332036F,0.824231F)
|
||||
TOOLS_COLORFS_STAT(pink,0.996109F,0.750011F,0.792981F)
|
||||
TOOLS_COLORFS_STAT(plum,0.863294F,0.62501F,0.863294F)
|
||||
TOOLS_COLORFS_STAT(red,1,0,0)
|
||||
TOOLS_COLORFS_STAT(indianred,0.800793F,0.35938F,0.35938F)
|
||||
TOOLS_COLORFS_STAT(mediumvioletred,0.777356F,0.0820325F,0.519539F)
|
||||
TOOLS_COLORFS_STAT(maroon)
|
||||
TOOLS_COLORFS_STAT(orange)
|
||||
TOOLS_COLORFS_STAT(orchid)
|
||||
TOOLS_COLORFS_STAT(darkorchid)
|
||||
TOOLS_COLORFS_STAT(mediumorchid)
|
||||
TOOLS_COLORFS_STAT(pink)
|
||||
TOOLS_COLORFS_STAT(plum)
|
||||
TOOLS_COLORFS_STAT(red)
|
||||
TOOLS_COLORFS_STAT(indianred)
|
||||
TOOLS_COLORFS_STAT(mediumvioletred)
|
||||
|
||||
//50-59
|
||||
TOOLS_COLORFS_STAT(orangered,0.996109F,0.269535F,0)
|
||||
TOOLS_COLORFS_STAT(violetred,0.812512F,0.125002F,0.562509F)
|
||||
TOOLS_COLORFS_STAT(salmon,0.976577F,0.500008F,0.445319F)
|
||||
TOOLS_COLORFS_STAT(sienna,0.62501F,0.320317F,0.175784F)
|
||||
TOOLS_COLORFS_STAT(tan,0.820325F,0.703136F,0.546883F)
|
||||
TOOLS_COLORFS_STAT(thistle,0.843763F,0.746105F,0.843763F)
|
||||
TOOLS_COLORFS_STAT(turquoise,0.250004F,0.875013F,0.812512F)
|
||||
TOOLS_COLORFS_STAT(darkturquoise,0,0.8047F,0.816419F)
|
||||
TOOLS_COLORFS_STAT(mediumturquoise,0.281254F,0.816419F,0.796887F)
|
||||
TOOLS_COLORFS_STAT(violet,0.929702F,0.50782F,0.929702F)
|
||||
TOOLS_COLORFS_STAT(orangered)
|
||||
TOOLS_COLORFS_STAT(violetred)
|
||||
TOOLS_COLORFS_STAT(salmon)
|
||||
TOOLS_COLORFS_STAT(sienna)
|
||||
TOOLS_COLORFS_STAT(tan)
|
||||
TOOLS_COLORFS_STAT(thistle)
|
||||
TOOLS_COLORFS_STAT(turquoise)
|
||||
TOOLS_COLORFS_STAT(darkturquoise)
|
||||
TOOLS_COLORFS_STAT(mediumturquoise)
|
||||
TOOLS_COLORFS_STAT(violet)
|
||||
|
||||
//60-64
|
||||
TOOLS_COLORFS_STAT(blueviolet,0.539071F,0.167971F,0.882826F)
|
||||
TOOLS_COLORFS_STAT(wheat,0.957046F,0.867201F,0.699229F)
|
||||
TOOLS_COLORFS_STAT(white,1,1,1)
|
||||
TOOLS_COLORFS_STAT(yellow,1,1,0)
|
||||
TOOLS_COLORFS_STAT(greenyellow,0.675792F,0.996109F,0.18359F)
|
||||
TOOLS_COLORFS_STAT(blueviolet)
|
||||
TOOLS_COLORFS_STAT(wheat)
|
||||
TOOLS_COLORFS_STAT(white)
|
||||
TOOLS_COLORFS_STAT(yellow)
|
||||
TOOLS_COLORFS_STAT(greenyellow)
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
/// CERN-ROOT colors : /////////////////////////////////
|
||||
////////////////////////////////////////////////////////
|
||||
TOOLS_COLORFS_STAT(ROOT_Color8)
|
||||
TOOLS_COLORFS_STAT(ROOT_Color9)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey12)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey13)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey14)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey15)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey16)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey17)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey18)
|
||||
TOOLS_COLORFS_STAT(ROOT_grey19)
|
||||
TOOLS_COLORFS_STAT(ROOT_Color50)
|
||||
|
||||
#undef TOOLS_COLORFS_STAT
|
||||
|
||||
|
||||
@@ -182,6 +182,22 @@ TOOLS_COLORS_STAT(white,1,1,1)
|
||||
TOOLS_COLORS_STAT(yellow,1,1,0)
|
||||
TOOLS_COLORS_STAT(greenyellow,0.675792F,0.996109F,0.18359F)
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
/// CERN-ROOT colors : /////////////////////////////////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
TOOLS_COLORS_STAT(ROOT_Color8, 0.35F,0.83F,0.33F)
|
||||
TOOLS_COLORS_STAT(ROOT_Color9, 0.35F,0.33F,0.85F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey12, 0.3F,0.3F,0.3F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey13, 0.4F,0.4F,0.4F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey14, 0.5F,0.5F,0.5F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey15, 0.6F,0.6F,0.6F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey16, 0.7F,0.7F,0.7F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey17, 0.8F,0.8F,0.8F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey18, 0.9F,0.9F,0.9F)
|
||||
TOOLS_COLORS_STAT(ROOT_grey19 , 0.95F,0.95F,0.95F)
|
||||
TOOLS_COLORS_STAT(ROOT_Color50, 0.83F,0.35F,0.33F)
|
||||
|
||||
#undef TOOLS_COLORS_STAT
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
#ifndef tools_columns
|
||||
#define tools_columns
|
||||
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
#include "vmanip"
|
||||
|
||||
#include "forit"
|
||||
#include "sout"
|
||||
@@ -24,48 +23,36 @@ class tree {
|
||||
TOOLS_SCLASS(tools::columns::tree)
|
||||
#endif
|
||||
public:
|
||||
tree(tree* a_parent):m_parent(a_parent){
|
||||
tree(tree* a_parent,const std::string& a_dcl):m_parent(a_parent),m_dcl(a_dcl){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
if(a_parent) a_parent->m_sub.push_back(this);
|
||||
}
|
||||
virtual ~tree(){
|
||||
clear();
|
||||
#ifdef TOOLS_MEM
|
||||
mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
protected:
|
||||
tree(const tree&) {}
|
||||
tree& operator=(const tree&) {return *this;}
|
||||
public:
|
||||
tree(const tree& a_from)
|
||||
:m_dcl(a_from.m_dcl)
|
||||
,m_sub(a_from.m_sub)
|
||||
,m_parent(a_from.m_parent)
|
||||
{
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
tree& operator=(const tree& a_from) {
|
||||
if(&a_from==this) return *this;
|
||||
m_dcl = a_from.m_dcl;
|
||||
m_sub = a_from.m_sub;
|
||||
m_parent = a_from.m_parent;
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
void clear(){
|
||||
void clear() {
|
||||
m_dcl.clear();
|
||||
tools_vforit(tree,m_sub,it) (*it).clear();
|
||||
safe_reverse_clear(m_sub);
|
||||
}
|
||||
void dump_tree(std::ostream& a_out,const std::string& a_margin) {
|
||||
if(m_dcl.size()) a_out << a_margin << m_dcl << std::endl;
|
||||
{tools_vforit(tree,m_sub,it) {
|
||||
(*it).dump_tree(a_out,a_margin+" ");
|
||||
{tools_vforit(tree*,m_sub,it) {
|
||||
(*it)->dump_tree(a_out,a_margin+" ");
|
||||
}}
|
||||
}
|
||||
public:
|
||||
std::string m_dcl;
|
||||
std::vector<tree> m_sub;
|
||||
tree* m_parent;
|
||||
std::string m_dcl;
|
||||
std::vector<tree*> m_sub;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -77,54 +64,40 @@ namespace columns {
|
||||
|
||||
class parser {
|
||||
public:
|
||||
parser():m_top(0){}
|
||||
parser():m_top(0,""){}
|
||||
virtual ~parser(){m_top.clear();}
|
||||
protected:
|
||||
parser(const parser& a_from):m_top(a_from.m_top){}
|
||||
parser(const parser&):m_top(0,"") {}
|
||||
parser& operator=(const parser&){return *this;}
|
||||
public:
|
||||
bool parse(const std::string& a_s){
|
||||
m_top.clear();
|
||||
tree* prev = &m_top;
|
||||
{tree tmp(0);
|
||||
std::string s;
|
||||
{std::string s;
|
||||
for(std::string::const_iterator it=a_s.begin();;++it) {
|
||||
if(it==a_s.end()) {
|
||||
if(s.size()) {
|
||||
tmp.m_dcl = s;
|
||||
tmp.m_parent = prev;
|
||||
prev->m_sub.push_back(tmp);
|
||||
new tree(prev,s);
|
||||
s.clear();
|
||||
}
|
||||
tmp.clear();
|
||||
break;
|
||||
} else {
|
||||
const char& c = *it;
|
||||
if(c==',') {
|
||||
if(s.size()) {
|
||||
tmp.m_dcl = s;
|
||||
tmp.m_parent = prev;
|
||||
prev->m_sub.push_back(tmp);
|
||||
new tree(prev,s);
|
||||
s.clear();
|
||||
}
|
||||
tmp.clear();
|
||||
} else if(c=='{') {
|
||||
tmp.clear();
|
||||
if(s.size()) {
|
||||
tmp.m_dcl = s;
|
||||
s.clear();
|
||||
}
|
||||
tmp.m_parent = prev;
|
||||
prev->m_sub.push_back(tmp);
|
||||
prev = &(prev->m_sub.back());
|
||||
tree* _tree = new tree(prev,s);
|
||||
s.clear();
|
||||
|
||||
prev = _tree;
|
||||
} else if(c=='}') {
|
||||
if(s.size()) {
|
||||
tmp.m_dcl = s;
|
||||
tmp.m_parent = prev;
|
||||
prev->m_sub.push_back(tmp);
|
||||
new tree(prev,s);
|
||||
s.clear();
|
||||
}
|
||||
tmp.clear();
|
||||
prev = prev->m_parent;
|
||||
if(!prev) return false; //should not happen.
|
||||
} else {
|
||||
@@ -205,6 +178,7 @@ inline void dump_columns(std::ostream& a_out,const std::vector<value>& a_vars,co
|
||||
}
|
||||
|
||||
class finder : public columns::parser {
|
||||
typedef columns::parser parent;
|
||||
public:
|
||||
finder(std::ostream& a_out,const std::string& a_script)
|
||||
:m_out(a_out)
|
||||
@@ -214,7 +188,7 @@ public:
|
||||
{}
|
||||
virtual ~finder() {clear();}
|
||||
protected:
|
||||
finder(const finder& a_from):parser(a_from),m_out(a_from.m_out){}
|
||||
finder(const finder& a_from):parent(a_from),m_out(a_from.m_out){}
|
||||
finder& operator=(const finder&){return *this;}
|
||||
public:
|
||||
//void setScript(const std::string& a_string) { m_script = a_string;}
|
||||
@@ -247,8 +221,8 @@ protected:
|
||||
bool analyse(columns::tree& a_tree,std::vector<value>& a_stack) {
|
||||
if(a_tree.m_dcl.empty()) { //top
|
||||
//std::cout << "debug : dcl empty" << std::endl;
|
||||
tools_vforit(columns::tree,a_tree.m_sub,it) {
|
||||
if(!analyse(*it,a_stack)) return false;
|
||||
tools_vforit(columns::tree*,a_tree.m_sub,it) {
|
||||
if(!analyse(*(*it),a_stack)) return false;
|
||||
}
|
||||
} else {
|
||||
//std::cout << "debug : dcl not empty" << std::endl;
|
||||
@@ -266,8 +240,8 @@ protected:
|
||||
}
|
||||
m_cur_type = value::NONE;
|
||||
std::vector<value>* stk = new std::vector<value>();
|
||||
tools_vforit(columns::tree,a_tree.m_sub,it) {
|
||||
if(!analyse(*it,*stk)) {
|
||||
tools_vforit(columns::tree*,a_tree.m_sub,it) {
|
||||
if(!analyse(*(*it),*stk)) {
|
||||
delete v;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
#ifdef TOOLS_MEM
|
||||
#include "mem"
|
||||
//#define TOOLS_CSTR_DEBUG_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
#include <cstdio>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace tools {
|
||||
@@ -29,17 +33,45 @@ inline char* str_dup(const char* a_cstr
|
||||
#endif
|
||||
) {
|
||||
#ifdef TOOLS_MEM
|
||||
if(a_inc) mem::increment(s_cstr().c_str());
|
||||
if(a_inc) {
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_dup \"%s\"\n",a_cstr);
|
||||
#endif
|
||||
mem::increment(s_cstr().c_str());
|
||||
}
|
||||
#endif
|
||||
return ::strcpy((char*)::malloc(::strlen(a_cstr)+1),a_cstr);
|
||||
}
|
||||
|
||||
inline char* str_from_buffer(const char* a_buffer,size_t a_len
|
||||
#ifdef TOOLS_MEM
|
||||
,bool a_inc = true
|
||||
#endif
|
||||
) {
|
||||
#ifdef TOOLS_MEM
|
||||
if(a_inc) {
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_from_buffer.\n");
|
||||
#endif
|
||||
mem::increment(s_cstr().c_str());
|
||||
}
|
||||
#endif
|
||||
char* s = (char*)::malloc(a_len+1);
|
||||
if(s==NULL) return NULL;
|
||||
s = ::strncpy(s,a_buffer,a_len);
|
||||
s[a_len] = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline void str_del(char*& a_cstr) {
|
||||
if(a_cstr==NULL) return;
|
||||
::free(a_cstr);
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_del \"%s\"\n",a_cstr);
|
||||
#endif
|
||||
mem::decrement(s_cstr().c_str());
|
||||
#endif
|
||||
::free(a_cstr);
|
||||
a_cstr = NULL;
|
||||
}
|
||||
|
||||
@@ -47,6 +79,9 @@ inline char* str_new(size_t a_l = 0,char a_char = ' ') {
|
||||
char* s = (char*)::malloc((a_l+1)*sizeof(char));
|
||||
if(s==NULL) return NULL;
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_new : len %lu\n",a_l);
|
||||
#endif
|
||||
mem::increment(s_cstr().c_str());
|
||||
#endif
|
||||
char* pos = s;
|
||||
@@ -60,6 +95,9 @@ inline bool str_cat(char*& a_1,const char a_c) {
|
||||
char* s = (char*)::malloc(l1+1+1);
|
||||
if(!s) return false;
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_cat \"%s\", char %d\n",a_1,a_c);
|
||||
#endif
|
||||
mem::increment(s_cstr().c_str());
|
||||
#endif
|
||||
::memcpy(s,a_1,l1);
|
||||
@@ -67,6 +105,9 @@ inline bool str_cat(char*& a_1,const char a_c) {
|
||||
*(s+l1+1) = 0;
|
||||
::free(a_1);
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_cat : dec\n");
|
||||
#endif
|
||||
mem::decrement(s_cstr().c_str());
|
||||
#endif
|
||||
a_1 = s;
|
||||
@@ -79,6 +120,9 @@ inline bool str_cat(char*& a_1,const char* a_2) {
|
||||
char* s = (char*)::malloc(l1+l2+1);
|
||||
if(!s) return false;
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_cat \"%s\" \"%s\"\n",a_1,a_2);
|
||||
#endif
|
||||
mem::increment(s_cstr().c_str());
|
||||
#endif
|
||||
::memcpy(s,a_1,l1);
|
||||
@@ -86,6 +130,9 @@ inline bool str_cat(char*& a_1,const char* a_2) {
|
||||
*(s+l1+l2) = 0;
|
||||
::free(a_1);
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_cat : dec\n");
|
||||
#endif
|
||||
mem::decrement(s_cstr().c_str());
|
||||
#endif
|
||||
a_1 = s;
|
||||
@@ -119,6 +166,9 @@ inline char* str_sub(const char* a_s,
|
||||
char* s = (char*)::malloc(ls+1);
|
||||
if(!s) return 0;
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_sub \"%s\"\n",a_s);
|
||||
#endif
|
||||
mem::increment(s_cstr().c_str());
|
||||
#endif
|
||||
//abcdefgh l=8
|
||||
@@ -143,6 +193,9 @@ inline char* str_rep(const char* a_s,unsigned int a_pos,unsigned int a_sz,const
|
||||
char* s = (char*)::malloc(ls+1);
|
||||
if(!s) return 0;
|
||||
#ifdef TOOLS_MEM
|
||||
#ifdef TOOLS_CSTR_DEBUG_MEM
|
||||
::printf("debug : str_rep \"%s\"\n",a_s);
|
||||
#endif
|
||||
mem::increment(s_cstr().c_str());
|
||||
#endif
|
||||
::memcpy(s,a_s,a_pos);
|
||||
@@ -216,6 +269,84 @@ inline bool str_2d(const char* a_s,double& a_v) {
|
||||
}
|
||||
*/
|
||||
|
||||
inline size_t str_lcpy(char *dst, const char *src, size_t siz) {
|
||||
// Copy src to string dst of size siz. At most siz-1 characters
|
||||
// will be copied. Always NUL terminates (unless siz == 0).
|
||||
// Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
|
||||
// code taken from CERN-ROOT/core/clib to compile exlib/tests/h2root.cpp.
|
||||
// strlcpy, strlcat are in string.h on BSD based systems.
|
||||
|
||||
// Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>.
|
||||
|
||||
/*register*/ char* d = dst;
|
||||
/*register*/ const char* s = src;
|
||||
/*register*/ size_t n = siz;
|
||||
|
||||
// Copy as many bytes as will fit :
|
||||
if (n != 0 && --n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0) break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
// Not enough room in dst, add NUL and traverse rest of src :
|
||||
if (n == 0) {
|
||||
if (siz != 0) *d = '\0'; // NUL-terminate dst.
|
||||
while (*s++);
|
||||
}
|
||||
|
||||
return(s - src - 1); // count does not include NUL.
|
||||
}
|
||||
|
||||
inline size_t str_lcat(char *dst, const char *src, size_t siz) {
|
||||
// Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
// full size of dst, not space left). At most siz-1 characters
|
||||
// will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
// Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
// If retval >= siz, truncation occurred.
|
||||
|
||||
// code taken from CERN-ROOT/core/clib to compile exlib/tests/h2root.cpp.
|
||||
// strlcpy, strlcat are in string.h on BSD based systems.
|
||||
|
||||
// Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>.
|
||||
|
||||
/*register*/ char* d = dst;
|
||||
/*register*/ const char* s = src;
|
||||
/*register*/ size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
// Find the end of dst and adjust bytes left but don't go past end :
|
||||
while (n-- != 0 && *d != '\0') d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0) return(dlen + strlen(s));
|
||||
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); // count does not include NUL.
|
||||
}
|
||||
|
||||
template <class VECTOR>
|
||||
inline bool str_2ds(char* a_s,const char* a_sep,VECTOR& a_v) {
|
||||
a_v.clear();
|
||||
const char* tok;
|
||||
double d;
|
||||
for (tok = ::strtok(a_s,a_sep);tok && *tok;tok = ::strtok(NULL,a_sep)) {
|
||||
if(!str_2d(tok,d)) {a_v.clear();return false;}
|
||||
a_v.push_back(d);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_curve
|
||||
#define tools_curve
|
||||
|
||||
#include "scast"
|
||||
#include "S_STRING"
|
||||
|
||||
#ifdef TOOLS_MEM
|
||||
#include "mem"
|
||||
#endif
|
||||
|
||||
#include "lina/vec3f"
|
||||
#include "lina/mat4f"
|
||||
|
||||
namespace tools {
|
||||
|
||||
class curve {
|
||||
public:
|
||||
TOOLS_SCLASS(tools::curve)
|
||||
virtual void* cast(const std::string& a_class) const {
|
||||
if(void* p = cmp_cast<curve>(this,a_class)) {return p;}
|
||||
return 0;
|
||||
}
|
||||
public:
|
||||
virtual void copy(curve*&) const = 0;
|
||||
public:
|
||||
virtual bool pos_tan_nor(float a_s,
|
||||
vec3f& a_pos,
|
||||
vec3f& a_tan,
|
||||
vec3f& a_nor) const = 0;
|
||||
public:
|
||||
curve(){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
m_model.set_identity();
|
||||
}
|
||||
virtual ~curve(){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
curve(const curve& a_from):m_model(a_from.m_model){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
curve& operator=(const curve& a_from){
|
||||
m_model = a_from.m_model;
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
void set_model_matrix(const mat4f& a_m) {m_model = a_m;}
|
||||
protected:
|
||||
mat4f m_model;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -19,6 +19,40 @@ inline bool is_zero(const NUMBER& a_left,const PREC& a_prec,PREC(*a_fabs)(const
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class VEC,class PREC>
|
||||
inline bool vectors_are_equal(const VEC& a_1,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
//bool status = true;
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!numbers_are_equal(a_1[index],a_2[index],a_prec,a_fabs))
|
||||
//{ ::printf("debug : vectors_are_equals : %lu : %g %g\n",index,a_1[index],a_2[index]);
|
||||
return false;
|
||||
//status = false;
|
||||
//}
|
||||
}
|
||||
return true;
|
||||
//return status;
|
||||
}
|
||||
|
||||
template <class VECVEC,class PREC>
|
||||
inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VECVEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!vectors_are_equal(a_1[index],a_2[index],a_prec,a_fabs)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// PREC(*a_fabs)(PREC) : /////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// for histo equals functions.
|
||||
|
||||
template <class NUMBER,class PREC>
|
||||
inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(NUMBER)) {
|
||||
NUMBER diff = a_left - a_right;
|
||||
@@ -54,6 +88,10 @@ inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -52,6 +52,13 @@ inline bool write(const std::string& a_file,const std::vector<std::string>& a_te
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool make_empty(const std::string& a_file) {
|
||||
FILE* file = ::fopen(a_file.c_str(),"wb");
|
||||
if(!file) return false;
|
||||
::fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read_buff(FILE* a_file,char* a_buff,unsigned int a_lbuf,size_t& a_length) {
|
||||
a_length = ::fread(a_buff,1,a_lbuf,a_file);
|
||||
return true;
|
||||
@@ -79,23 +86,28 @@ inline bool read_cstring(FILE* a_file,char* a_buff,unsigned int a_lbuf,size_t& a
|
||||
}
|
||||
|
||||
|
||||
inline bool read(const std::string& a_file,std::vector<std::string>& a_text){
|
||||
inline bool read(FILE* a_FILE,std::vector<std::string>& a_text){
|
||||
a_text.clear();
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) return false;
|
||||
unsigned int BUFSIZE = 65536;
|
||||
char* buffer = new char[BUFSIZE+1];
|
||||
if(!buffer) {::fclose(file);return false;}
|
||||
if(!buffer) return false;
|
||||
while(true) {
|
||||
size_t l;
|
||||
if(!read_cstring(file,buffer,BUFSIZE,l)) break; // EOF.
|
||||
if(!read_cstring(a_FILE,buffer,BUFSIZE,l)) break; // EOF.
|
||||
a_text.push_back(buffer);
|
||||
}
|
||||
delete [] buffer;
|
||||
::fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read(const std::string& a_file,std::vector<std::string>& a_text){
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) {a_text.clear();return false;}
|
||||
bool status = read(file,a_text);
|
||||
::fclose(file);
|
||||
return status;
|
||||
}
|
||||
|
||||
inline bool read_num(const std::string& a_file,std::vector<std::string>::size_type a_num,std::vector<std::string>& a_text,const std::string& a_cmt = ""){
|
||||
a_text.clear();
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
@@ -337,6 +349,23 @@ inline bool is_py(const std::string& a_file,bool& a_is){
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool is_kumac(const std::string& a_file,bool& a_is){
|
||||
// look at suffix. Some file can't be guessed.
|
||||
if(suffix(a_file)=="kumac") {a_is = true;return true;}
|
||||
//try to guess ?
|
||||
a_is = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool is_insh(const std::string& a_file,bool& a_is){
|
||||
// look at suffix. Some file can't be guessed.
|
||||
if(suffix(a_file)=="insh") {a_is = true;return true;}
|
||||
//try to guess ?
|
||||
// have a first line : #!insh ?
|
||||
a_is = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include "fileis"
|
||||
@@ -498,7 +527,7 @@ inline bool std_rename(const std::string& a_from,const std::string& a_to) {
|
||||
//NOTE : a_from must not be a path !
|
||||
// Darwin is ok with a path but not Linux !
|
||||
// For example :
|
||||
// ::rename("/tmp/tmp01"."x");
|
||||
// ::rename("/tmp/tmp01","x");
|
||||
// return -1 on Linux.
|
||||
// To do the upper then someone must use move.
|
||||
// But there is no move in the standard lib C !
|
||||
|
||||
@@ -23,6 +23,7 @@ TOOLS_GLOBAL_STRING(format_wrl)
|
||||
TOOLS_GLOBAL_STRING(format_jpeg)
|
||||
TOOLS_GLOBAL_STRING(format_png)
|
||||
TOOLS_GLOBAL_STRING(format_root)
|
||||
TOOLS_GLOBAL_STRING(format_dst) //pmx,agora.
|
||||
TOOLS_GLOBAL_STRING(format_csv)
|
||||
TOOLS_GLOBAL_STRING(format_hippo)
|
||||
TOOLS_GLOBAL_STRING(format_scenarios)
|
||||
@@ -39,6 +40,8 @@ TOOLS_GLOBAL_STRING(format_heprep)
|
||||
TOOLS_GLOBAL_STRING(format_zheprep)
|
||||
TOOLS_GLOBAL_STRING(format_lua)
|
||||
TOOLS_GLOBAL_STRING(format_py)
|
||||
TOOLS_GLOBAL_STRING(format_kumac)
|
||||
TOOLS_GLOBAL_STRING(format_insh)
|
||||
|
||||
#define TOOLS_GLOBAL_EXT(a_name)\
|
||||
inline const std::string& s_ext_##a_name() {\
|
||||
@@ -54,9 +57,11 @@ TOOLS_GLOBAL_EXT(dcm)
|
||||
TOOLS_GLOBAL_EXT(iv)
|
||||
TOOLS_GLOBAL_EXT(hiv)
|
||||
TOOLS_GLOBAL_EXT(wrl)
|
||||
TOOLS_GLOBAL_EXT(jpeg)
|
||||
TOOLS_GLOBAL_EXT(jpg)
|
||||
TOOLS_GLOBAL_EXT(png)
|
||||
TOOLS_GLOBAL_EXT(root)
|
||||
TOOLS_GLOBAL_EXT(dst)
|
||||
TOOLS_GLOBAL_EXT(csv)
|
||||
TOOLS_GLOBAL_EXT(hiptxt)
|
||||
TOOLS_GLOBAL_EXT(tnt)
|
||||
@@ -74,6 +79,8 @@ TOOLS_GLOBAL_EXT(heprep)
|
||||
TOOLS_GLOBAL_EXT(zheprep)
|
||||
TOOLS_GLOBAL_EXT(lua)
|
||||
TOOLS_GLOBAL_EXT(py)
|
||||
TOOLS_GLOBAL_EXT(kumac)
|
||||
TOOLS_GLOBAL_EXT(insh)
|
||||
|
||||
#undef TOOLS_GLOBAL_EXT
|
||||
|
||||
@@ -90,6 +97,7 @@ inline void formats(std::vector<std::string>& a_v) {
|
||||
a_v.push_back(s_format_jpeg());
|
||||
a_v.push_back(s_format_png());
|
||||
a_v.push_back(s_format_root());
|
||||
a_v.push_back(s_format_dst());
|
||||
a_v.push_back(s_format_csv());
|
||||
a_v.push_back(s_format_hippo());
|
||||
a_v.push_back(s_format_scenarios());
|
||||
@@ -106,16 +114,20 @@ inline void formats(std::vector<std::string>& a_v) {
|
||||
a_v.push_back(s_format_zheprep());
|
||||
a_v.push_back(s_format_lua());
|
||||
a_v.push_back(s_format_py());
|
||||
a_v.push_back(s_format_kumac());
|
||||
a_v.push_back(s_format_insh());
|
||||
}
|
||||
|
||||
inline std::string ext_fmt(const std::string& a_ext) {
|
||||
if(a_ext==s_ext_fits()) return s_format_fits();
|
||||
if(a_ext==s_ext_aida()) return s_format_aida();
|
||||
if(a_ext==s_ext_root()) return s_format_root();
|
||||
if(a_ext==s_ext_dst()) return s_format_dst();
|
||||
if(a_ext==s_ext_csv()) return s_format_csv();
|
||||
if(a_ext==s_ext_tnt()) return s_format_hippo();
|
||||
if(a_ext==s_ext_hiptxt()) return s_format_hippo();
|
||||
if(a_ext==s_ext_hdf5()) return s_format_hdf5();
|
||||
if(a_ext==s_ext_jpeg()) return s_format_jpeg();
|
||||
if(a_ext==s_ext_jpg()) return s_format_jpeg();
|
||||
if(a_ext==s_ext_png()) return s_format_png();
|
||||
if(a_ext==s_ext_fog()) return s_format_fog();
|
||||
@@ -137,9 +149,81 @@ inline std::string ext_fmt(const std::string& a_ext) {
|
||||
if(a_ext==s_ext_zheprep()) return s_format_zheprep();
|
||||
if(a_ext==s_ext_lua()) return s_format_lua();
|
||||
if(a_ext==s_ext_py()) return s_format_py();
|
||||
if(a_ext==s_ext_kumac()) return s_format_kumac();
|
||||
if(a_ext==s_ext_insh()) return s_format_insh();
|
||||
return s_format_guessed();
|
||||
}
|
||||
|
||||
inline bool need_placement(const std::string& a_format) {
|
||||
if(a_format==s_format_guessed()) return true;
|
||||
//if(a_format==s_format_hdf5()) return true;
|
||||
//if(a_format==s_format_fits()) return true;
|
||||
//if(a_format==s_format_fog()) return true; //load in static_sg.
|
||||
//if(a_format==s_format_dot()) return true;
|
||||
//if(a_format==s_format_dcm()) return true;
|
||||
//if(a_format==s_format_iv()) return true; //load in static_sg.
|
||||
//if(a_format==s_format_wrl()) return true; //load in static_sg.
|
||||
//if(a_format==s_format_jpeg()) return true;
|
||||
//if(a_format==s_format_png()) return true;
|
||||
//if(a_format==s_format_root()) return true;
|
||||
//if(a_format==s_format_dst()) return true;
|
||||
//if(a_format==s_format_csv()) return true;
|
||||
//if(a_format==s_format_hippo()) return true;
|
||||
//if(a_format==s_format_scenarios()) return true;
|
||||
//if(a_format==s_format_slides()) return true;
|
||||
//if(a_format==s_format_zvid()) return true;
|
||||
if(a_format==s_format_exsg()) return true;
|
||||
//if(a_format==s_format_gdml()) return true; //load in static_sg.
|
||||
//if(a_format==s_format_mac()) return true;
|
||||
//if(a_format==s_format_cmnd()) return true;
|
||||
//if(a_format==s_format_aida()) return true;
|
||||
if(a_format==s_format_bsg()) return true;
|
||||
//if(a_format==s_format_jive()) return true; //load in dynamic_sg.
|
||||
//if(a_format==s_format_heprep()) return true; //load in static_sg.
|
||||
//if(a_format==s_format_zheprep()) return true; //load in static_sg.
|
||||
//if(a_format==s_format_lua()) return true;
|
||||
//if(a_format==s_format_py()) return true;
|
||||
//if(a_format==s_format_kumac()) return true;
|
||||
//if(a_format==s_format_insh()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// related files : sg/write_paper, paper_format.
|
||||
|
||||
inline bool is_paper_format(const std::string& a_format) {
|
||||
if(a_format=="gl2ps_eps") return true;
|
||||
if(a_format=="gl2ps_ps") return true;
|
||||
if(a_format=="gl2ps_pdf") return true;
|
||||
if(a_format=="gl2ps_svg") return true;
|
||||
if(a_format=="gl2ps_tex") return true;
|
||||
if(a_format=="gl2ps_pgf") return true;
|
||||
if(a_format=="inzb_ps") return true;
|
||||
if(a_format=="inzb_jpeg") return true;
|
||||
if(a_format=="inzb_png") return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_inzb_format(const std::string& a_format) {
|
||||
if(a_format=="inzb_ps") return true;
|
||||
if(a_format=="inzb_jpeg") return true;
|
||||
if(a_format=="inzb_png") return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool paper_format_extension(const std::string& a_format,std::string& a_ext) {
|
||||
if(a_format=="gl2ps_eps") {a_ext = "eps";return true;}
|
||||
if(a_format=="gl2ps_ps") {a_ext = "ps";return true;}
|
||||
if(a_format=="gl2ps_pdf") {a_ext = "pdf";return true;}
|
||||
if(a_format=="gl2ps_svg") {a_ext = "svg";return true;}
|
||||
if(a_format=="gl2ps_tex") {a_ext = "tex";return true;}
|
||||
if(a_format=="gl2ps_pgf") {a_ext = "pgf";return true;}
|
||||
if(a_format=="inzb_ps") {a_ext = "ps";return true;}
|
||||
if(a_format=="inzb_jpeg") {a_ext = "jpeg";return true;}
|
||||
if(a_format=="inzb_png") {a_ext = "png";return true;}
|
||||
a_ext.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -71,7 +71,6 @@ inline bool is_root(const std::string& a_file,bool& a_is){
|
||||
if(head[1]!='o') {a_is = false;return true;}
|
||||
if(head[2]!='o') {a_is = false;return true;}
|
||||
if(head[3]!='t') {a_is = false;return true;}
|
||||
// Aie, we are in a mess.
|
||||
a_is = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,18 +69,19 @@ inline bool find_with_env(std::ostream& a_out,
|
||||
std::string PATH;
|
||||
if(!get_env(a_env,PATH)) {
|
||||
//look for a a_file in current directory.
|
||||
a_path = a_file;
|
||||
if(file::exists(a_path)) return true;
|
||||
a_out << "tools::find_with_path :"
|
||||
<< " env variable " << sout(a_env) << " not defined."
|
||||
<< std::endl;
|
||||
if(file::exists(a_file)) {
|
||||
//a_out << "tools::find_with_env :"
|
||||
// << " env variable " << sout(a_env) << " not defined, but file " << sout(a_file) << " exists."
|
||||
// << std::endl;
|
||||
a_path = a_file;
|
||||
return true;
|
||||
}
|
||||
a_out << "tools::find_with_env : env variable " << sout(a_env) << " not defined." << std::endl;
|
||||
a_path.clear();
|
||||
return false;
|
||||
}
|
||||
if(a_verbose) {
|
||||
a_out << "find_with_path :"
|
||||
<< " PATH is " << sout(PATH)
|
||||
<< std::endl;
|
||||
a_out << "find_with_env : env " << sout(a_env) << " is " << sout(PATH) << std::endl;
|
||||
}
|
||||
|
||||
std::vector<std::string> dirs;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#define tools_vforcit(a__T,a__v,a__it) \
|
||||
for(std::vector< a__T >::const_iterator a__it = (a__v).begin();(a__it)!=(a__v).end();++(a__it))
|
||||
|
||||
#define tools_vforcit_beg(a__T,a__v,a__beg,a__it) \
|
||||
for(std::vector< a__T >::const_iterator a__it = a__beg;(a__it)!=(a__v).end();++(a__it))
|
||||
|
||||
#define tools_vforit(a__T,a__v,a__it) \
|
||||
for(std::vector< a__T >::iterator a__it = (a__v).begin();(a__it)!=(a__v).end();++(a__it))
|
||||
|
||||
@@ -16,6 +19,9 @@
|
||||
#define tools_vforrit(a__T,a__v,a__it) \
|
||||
for(std::vector< a__T >::reverse_iterator a__it = (a__v).rbegin();(a__it)!=(a__v).rend();++(a__it))
|
||||
|
||||
#define tools_vforcit_npp(a__T,a__v,a__it) \
|
||||
for(std::vector< a__T >::const_iterator a__it = (a__v).begin();(a__it)!=(a__v).end();)
|
||||
|
||||
#define tools_vforit_npp(a__T,a__v,a__it) \
|
||||
for(std::vector< a__T >::iterator a__it = (a__v).begin();(a__it)!=(a__v).end();)
|
||||
|
||||
@@ -37,6 +43,9 @@
|
||||
#define tools_lforit(a__T,a__l,a__it) \
|
||||
for(std::list< a__T >::iterator a__it = (a__l).begin();(a__it)!=(a__l).end();++(a__it))
|
||||
|
||||
#define tools_lforit_npp(a__T,a__v,a__it) \
|
||||
for(std::list< a__T >::iterator a__it = (a__v).begin();(a__it)!=(a__v).end();)
|
||||
|
||||
#define tools_mforcit(a__K,a__V,a__m,a__it) \
|
||||
for(std::map< a__K , a__V >::const_iterator a__it = (a__m).begin();(a__it)!=(a__m).end();++(a__it))
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
|
||||
#include "gl2ps_def.h"
|
||||
|
||||
/*----------------------------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
|
||||
inline tools_GLboolean tools_dummy_glIsEnabled (tools_GLenum) {return TOOLS_GL_FALSE;}
|
||||
inline void tools_dummy_glBegin (tools_GLenum) {}
|
||||
inline void tools_dummy_glEnd () {}
|
||||
inline void tools_dummy_glGetFloatv (tools_GLenum,tools_GLfloat*) {}
|
||||
inline void tools_dummy_glVertex3f (tools_GLfloat,tools_GLfloat,tools_GLfloat) {}
|
||||
inline void tools_dummy_glGetBooleanv (tools_GLenum,tools_GLboolean*) {}
|
||||
inline void tools_dummy_glGetIntegerv (tools_GLenum,tools_GLint*) {}
|
||||
inline tools_GLint tools_dummy_glRenderMode (tools_GLenum) {return 0;}
|
||||
inline void tools_dummy_glFeedbackBuffer (tools_GLsizei,tools_GLenum,tools_GLfloat*) {}
|
||||
inline void tools_dummy_glPassThrough (tools_GLfloat ) {}
|
||||
|
||||
inline tools_gl2ps_gl_funcs_t& tools_gl2ps_get_s_funcs() {
|
||||
static tools_gl2ps_gl_funcs_t s_gl_funcs = {
|
||||
tools_dummy_glIsEnabled,
|
||||
tools_dummy_glBegin,
|
||||
tools_dummy_glEnd,
|
||||
tools_dummy_glGetFloatv,
|
||||
tools_dummy_glVertex3f,
|
||||
tools_dummy_glGetBooleanv,
|
||||
tools_dummy_glGetIntegerv,
|
||||
tools_dummy_glRenderMode,
|
||||
tools_dummy_glFeedbackBuffer,
|
||||
tools_dummy_glPassThrough
|
||||
};
|
||||
return s_gl_funcs;
|
||||
}
|
||||
|
||||
TOOLS_GL2PSDLL_API void tools_gl2ps_set_gl_funcs(tools_gl2ps_gl_funcs_t* a_funcs) {
|
||||
tools_gl2ps_gl_funcs_t& s_gl_funcs = tools_gl2ps_get_s_funcs();
|
||||
s_gl_funcs.m_glIsEnabled = a_funcs->m_glIsEnabled;
|
||||
s_gl_funcs.m_glBegin = a_funcs->m_glBegin;
|
||||
s_gl_funcs.m_glEnd = a_funcs->m_glEnd;
|
||||
s_gl_funcs.m_glGetFloatv = a_funcs->m_glGetFloatv;
|
||||
s_gl_funcs.m_glVertex3f = a_funcs->m_glVertex3f;
|
||||
s_gl_funcs.m_glGetBooleanv = a_funcs->m_glGetBooleanv;
|
||||
s_gl_funcs.m_glGetIntegerv = a_funcs->m_glGetIntegerv;
|
||||
s_gl_funcs.m_glRenderMode = a_funcs->m_glRenderMode;
|
||||
s_gl_funcs.m_glFeedbackBuffer = a_funcs->m_glFeedbackBuffer;
|
||||
s_gl_funcs.m_glPassThrough = a_funcs->m_glPassThrough;
|
||||
}
|
||||
|
||||
TOOLS_GL2PSDLL_API void tools_gl2ps_reset_gl_funcs() {
|
||||
tools_gl2ps_gl_funcs_t& s_gl_funcs = tools_gl2ps_get_s_funcs();
|
||||
s_gl_funcs.m_glIsEnabled = tools_dummy_glIsEnabled;
|
||||
s_gl_funcs.m_glBegin = tools_dummy_glBegin;
|
||||
s_gl_funcs.m_glEnd = tools_dummy_glEnd;
|
||||
s_gl_funcs.m_glGetFloatv = tools_dummy_glGetFloatv;
|
||||
s_gl_funcs.m_glVertex3f = tools_dummy_glVertex3f;
|
||||
s_gl_funcs.m_glGetBooleanv = tools_dummy_glGetBooleanv;
|
||||
s_gl_funcs.m_glGetIntegerv = tools_dummy_glGetIntegerv;
|
||||
s_gl_funcs.m_glRenderMode = tools_dummy_glRenderMode;
|
||||
s_gl_funcs.m_glFeedbackBuffer = tools_dummy_glFeedbackBuffer;
|
||||
s_gl_funcs.m_glPassThrough = tools_dummy_glPassThrough;
|
||||
}
|
||||
|
||||
#define tools_glIsEnabled (*(tools_gl2ps_get_s_funcs().m_glIsEnabled))
|
||||
#define tools_glBegin (*(tools_gl2ps_get_s_funcs().m_glBegin))
|
||||
#define tools_glEnd (*(tools_gl2ps_get_s_funcs().m_glEnd))
|
||||
#define tools_glGetFloatv (*(tools_gl2ps_get_s_funcs().m_glGetFloatv))
|
||||
#define tools_glVertex3f (*(tools_gl2ps_get_s_funcs().m_glVertex3f))
|
||||
#define tools_glGetBooleanv (*(tools_gl2ps_get_s_funcs().m_glGetBooleanv))
|
||||
#define tools_glGetIntegerv (*(tools_gl2ps_get_s_funcs().m_glGetIntegerv))
|
||||
#define tools_glRenderMode (*(tools_gl2ps_get_s_funcs().m_glRenderMode))
|
||||
#define tools_glFeedbackBuffer (*(tools_gl2ps_get_s_funcs().m_glFeedbackBuffer))
|
||||
#define tools_glPassThrough (*(tools_gl2ps_get_s_funcs().m_glPassThrough))
|
||||
|
||||
/*----------------------------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -0,0 +1,197 @@
|
||||
/* Copyright (C) 2010, Guy Barrand. All rights reserved. */
|
||||
/* See the file tools.license for terms. */
|
||||
|
||||
#ifndef tools_gl2ps_def_h
|
||||
#define tools_gl2ps_def_h
|
||||
|
||||
typedef int tools_GLint;
|
||||
typedef unsigned int tools_GLuint;
|
||||
typedef float tools_GLfloat;
|
||||
typedef unsigned int tools_GLenum;
|
||||
typedef short tools_GLshort;
|
||||
typedef unsigned short tools_GLushort;
|
||||
typedef int tools_GLsizei;
|
||||
typedef unsigned char tools_GLboolean;
|
||||
|
||||
/*----------------------------------------------------------*/
|
||||
/*--- from gl2ps.h : --------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
#define TOOLS_GL2PSDLL_API inline
|
||||
|
||||
#define TOOLS_GL2PS_MAJOR_VERSION 1
|
||||
#define TOOLS_GL2PS_MINOR_VERSION 4
|
||||
#define TOOLS_GL2PS_PATCH_VERSION 0
|
||||
#define TOOLS_GL2PS_EXTRA_VERSION ""
|
||||
|
||||
#define TOOLS_GL2PS_VERSION (TOOLS_GL2PS_MAJOR_VERSION + \
|
||||
0.01 * TOOLS_GL2PS_MINOR_VERSION + \
|
||||
0.0001 * TOOLS_GL2PS_PATCH_VERSION)
|
||||
|
||||
#define TOOLS_GL2PS_COPYRIGHT "(C) 1999-2017 C. Geuzaine"
|
||||
|
||||
/* Output file formats (the values and the ordering are important!) */
|
||||
|
||||
#define TOOLS_GL2PS_PS 0
|
||||
#define TOOLS_GL2PS_EPS 1
|
||||
#define TOOLS_GL2PS_TEX 2
|
||||
#define TOOLS_GL2PS_PDF 3
|
||||
#define TOOLS_GL2PS_SVG 4
|
||||
#define TOOLS_GL2PS_PGF 5
|
||||
|
||||
/* Sorting algorithms */
|
||||
|
||||
#define TOOLS_GL2PS_NO_SORT 1
|
||||
#define TOOLS_GL2PS_SIMPLE_SORT 2
|
||||
#define TOOLS_GL2PS_BSP_SORT 3
|
||||
|
||||
/* Message levels and error codes */
|
||||
|
||||
#define TOOLS_GL2PS_SUCCESS 0
|
||||
#define TOOLS_GL2PS_INFO 1
|
||||
#define TOOLS_GL2PS_WARNING 2
|
||||
#define TOOLS_GL2PS_ERROR 3
|
||||
#define TOOLS_GL2PS_NO_FEEDBACK 4
|
||||
#define TOOLS_GL2PS_OVERFLOW 5
|
||||
#define TOOLS_GL2PS_UNINITIALIZED 6
|
||||
|
||||
/* Options for tools_gl2psBeginPage */
|
||||
|
||||
#define TOOLS_GL2PS_NONE 0
|
||||
#define TOOLS_GL2PS_DRAW_BACKGROUND (1<<0)
|
||||
#define TOOLS_GL2PS_SIMPLE_LINE_OFFSET (1<<1)
|
||||
#define TOOLS_GL2PS_SILENT (1<<2)
|
||||
#define TOOLS_GL2PS_BEST_ROOT (1<<3)
|
||||
#define TOOLS_GL2PS_OCCLUSION_CULL (1<<4)
|
||||
#define TOOLS_GL2PS_NO_TEXT (1<<5)
|
||||
#define TOOLS_GL2PS_LANDSCAPE (1<<6)
|
||||
#define TOOLS_GL2PS_NO_PS3_SHADING (1<<7)
|
||||
#define TOOLS_GL2PS_NO_PIXMAP (1<<8)
|
||||
#define TOOLS_GL2PS_USE_CURRENT_VIEWPORT (1<<9)
|
||||
#define TOOLS_GL2PS_COMPRESS (1<<10)
|
||||
#define TOOLS_GL2PS_NO_BLENDING (1<<11)
|
||||
#define TOOLS_GL2PS_TIGHT_BOUNDING_BOX (1<<12)
|
||||
#define TOOLS_GL2PS_NO_OPENGL_CONTEXT (1<<13)
|
||||
|
||||
/* Arguments for tools_gl2psEnable/tools_gl2psDisable */
|
||||
|
||||
#define TOOLS_GL2PS_POLYGON_OFFSET_FILL 1
|
||||
#define TOOLS_GL2PS_POLYGON_BOUNDARY 2
|
||||
#define TOOLS_GL2PS_LINE_STIPPLE 3
|
||||
#define TOOLS_GL2PS_BLEND 4
|
||||
|
||||
|
||||
/* Arguments for tools_gl2psLineCap/Join */
|
||||
|
||||
#define TOOLS_GL2PS_LINE_CAP_BUTT 0
|
||||
#define TOOLS_GL2PS_LINE_CAP_ROUND 1
|
||||
#define TOOLS_GL2PS_LINE_CAP_SQUARE 2
|
||||
|
||||
#define TOOLS_GL2PS_LINE_JOIN_MITER 0
|
||||
#define TOOLS_GL2PS_LINE_JOIN_ROUND 1
|
||||
#define TOOLS_GL2PS_LINE_JOIN_BEVEL 2
|
||||
|
||||
/* Text alignment (o=raster position; default mode is BL):
|
||||
+---+ +---+ +---+ +---+ +---+ +---+ +-o-+ o---+ +---o
|
||||
| o | o | | o | | | | | | | | | | | |
|
||||
+---+ +---+ +---+ +-o-+ o---+ +---o +---+ +---+ +---+
|
||||
C CL CR B BL BR T TL TR */
|
||||
|
||||
#define TOOLS_GL2PS_TEXT_C 1
|
||||
#define TOOLS_GL2PS_TEXT_CL 2
|
||||
#define TOOLS_GL2PS_TEXT_CR 3
|
||||
#define TOOLS_GL2PS_TEXT_B 4
|
||||
#define TOOLS_GL2PS_TEXT_BL 5
|
||||
#define TOOLS_GL2PS_TEXT_BR 6
|
||||
#define TOOLS_GL2PS_TEXT_T 7
|
||||
#define TOOLS_GL2PS_TEXT_TL 8
|
||||
#define TOOLS_GL2PS_TEXT_TR 9
|
||||
|
||||
typedef tools_GLfloat tools_GL2PSrgba[4];
|
||||
typedef tools_GLfloat tools_GL2PSxyz[3];
|
||||
|
||||
typedef struct {
|
||||
tools_GL2PSxyz xyz;
|
||||
tools_GL2PSrgba rgba;
|
||||
} tools_GL2PSvertex;
|
||||
|
||||
/* Primitive types */
|
||||
#define TOOLS_GL2PS_NO_TYPE -1
|
||||
#define TOOLS_GL2PS_TEXT 1
|
||||
#define TOOLS_GL2PS_POINT 2
|
||||
#define TOOLS_GL2PS_LINE 3
|
||||
#define TOOLS_GL2PS_QUADRANGLE 4
|
||||
#define TOOLS_GL2PS_TRIANGLE 5
|
||||
#define TOOLS_GL2PS_PIXMAP 6
|
||||
#define TOOLS_GL2PS_IMAGEMAP 7
|
||||
#define TOOLS_GL2PS_IMAGEMAP_WRITTEN 8
|
||||
#define TOOLS_GL2PS_IMAGEMAP_VISIBLE 9
|
||||
#define TOOLS_GL2PS_SPECIAL 10
|
||||
|
||||
/*----------------------------------------------------------*/
|
||||
/*--- from OpenGL : ----------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
#define TOOLS_GL_TRUE 1
|
||||
#define TOOLS_GL_FALSE 0
|
||||
|
||||
#define TOOLS_GL_FLOAT 0x1406
|
||||
#define TOOLS_GL_BLEND 0x0BE2
|
||||
|
||||
#define TOOLS_GL_SRC_ALPHA 0x0302
|
||||
#define TOOLS_GL_ONE_MINUS_SRC_ALPHA 0x0303
|
||||
|
||||
#define TOOLS_GL_RGB 0x1907
|
||||
#define TOOLS_GL_RGBA 0x1908
|
||||
|
||||
#define TOOLS_GL_POINTS 0x0000
|
||||
|
||||
#define TOOLS_GL_CURRENT_RASTER_POSITION_VALID 0x0B08
|
||||
#define TOOLS_GL_CURRENT_RASTER_POSITION 0x0B07
|
||||
#define TOOLS_GL_CURRENT_RASTER_COLOR 0x0B04
|
||||
#define TOOLS_GL_ZERO 0
|
||||
#define TOOLS_GL_ONE 1
|
||||
#define TOOLS_GL_COLOR_INDEX 0x1900
|
||||
|
||||
#define TOOLS_GL_POINT_TOKEN 0x0701
|
||||
#define TOOLS_GL_LINE_TOKEN 0x0702
|
||||
#define TOOLS_GL_LINE_RESET_TOKEN 0x0707
|
||||
#define TOOLS_GL_POLYGON_TOKEN 0x0703
|
||||
#define TOOLS_GL_BITMAP_TOKEN 0x0704
|
||||
#define TOOLS_GL_DRAW_PIXEL_TOKEN 0x0705
|
||||
|
||||
#define TOOLS_GL_COPY_PIXEL_TOKEN 0x0706
|
||||
#define TOOLS_GL_PASS_THROUGH_TOKEN 0x0700
|
||||
|
||||
#define TOOLS_GL_FEEDBACK 0x1C01
|
||||
#define TOOLS_GL_COLOR_CLEAR_VALUE 0x0C22
|
||||
#define TOOLS_GL_INDEX_CLEAR_VALUE 0x0C20
|
||||
#define TOOLS_GL_RENDER 0x1C00
|
||||
#define TOOLS_GL_VIEWPORT 0x0BA2
|
||||
#define TOOLS_GL_BLEND_SRC 0x0BE1
|
||||
#define TOOLS_GL_BLEND_DST 0x0BE0
|
||||
#define TOOLS_GL_3D_COLOR 0x0602
|
||||
|
||||
#define TOOLS_GL_POLYGON_OFFSET_FACTOR 0x8038
|
||||
#define TOOLS_GL_POLYGON_OFFSET_UNITS 0x2A00
|
||||
#define TOOLS_GL_LINE_STIPPLE_PATTERN 0x0B25
|
||||
#define TOOLS_GL_LINE_STIPPLE_REPEAT 0x0B26
|
||||
|
||||
#define TOOLS_GL_ZOOM_X 0x0D16
|
||||
#define TOOLS_GL_ZOOM_Y 0x0D17
|
||||
|
||||
/*----------------------------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
/*----------------------------------------------------------*/
|
||||
typedef struct {
|
||||
tools_GLboolean (*m_glIsEnabled) (tools_GLenum);
|
||||
void (*m_glBegin) (tools_GLenum);
|
||||
void (*m_glEnd) ();
|
||||
void (*m_glGetFloatv) (tools_GLenum,tools_GLfloat*);
|
||||
void (*m_glVertex3f) (tools_GLfloat,tools_GLfloat,tools_GLfloat);
|
||||
void (*m_glGetBooleanv) (tools_GLenum,tools_GLboolean*);
|
||||
void (*m_glGetIntegerv) (tools_GLenum,tools_GLint*);
|
||||
tools_GLint (*m_glRenderMode) (tools_GLenum);
|
||||
void (*m_glFeedbackBuffer) (tools_GLsizei,tools_GLenum,tools_GLfloat*);
|
||||
void (*m_glPassThrough) (tools_GLfloat);
|
||||
} tools_gl2ps_gl_funcs_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
TOOLS_GL2PSDLL_API tools_GLint tools_gl2psSetBackgroundColor(float a_r,float a_g,float a_b)
|
||||
{
|
||||
if(!tools_gl2ps_context) return TOOLS_GL2PS_UNINITIALIZED;
|
||||
|
||||
tools_gl2ps_context->bgcolor[0] = a_r;
|
||||
tools_gl2ps_context->bgcolor[1] = a_g;
|
||||
tools_gl2ps_context->bgcolor[2] = a_b;
|
||||
tools_gl2ps_context->bgcolor[3] = 1.0F;
|
||||
|
||||
return TOOLS_GL2PS_SUCCESS;
|
||||
}
|
||||
|
||||
#undef TOOLS_GL2PS_EPSILON
|
||||
#undef TOOLS_GL2PS_ZSCALE
|
||||
#undef TOOLS_GL2PS_ZOFFSET
|
||||
#undef TOOLS_GL2PS_ZOFFSET_LARGE
|
||||
#undef TOOLS_GL2PS_ZERO
|
||||
#undef TOOLS_GL2PS_COINCIDENT
|
||||
#undef TOOLS_GL2PS_IN_FRONT_OF
|
||||
#undef TOOLS_GL2PS_IN_BACK_OF
|
||||
#undef TOOLS_GL2PS_SPANNING
|
||||
#undef TOOLS_GL2PS_POINT_COINCIDENT
|
||||
#undef TOOLS_GL2PS_POINT_INFRONT
|
||||
#undef TOOLS_GL2PS_POINT_BACK
|
||||
#undef TOOLS_GL2PS_BEGIN_OFFSET_TOKEN
|
||||
#undef TOOLS_GL2PS_END_OFFSET_TOKEN
|
||||
#undef TOOLS_GL2PS_BEGIN_BOUNDARY_TOKEN
|
||||
#undef TOOLS_GL2PS_END_BOUNDARY_TOKEN
|
||||
#undef TOOLS_GL2PS_BEGIN_STIPPLE_TOKEN
|
||||
#undef TOOLS_GL2PS_END_STIPPLE_TOKEN
|
||||
#undef TOOLS_GL2PS_POINT_SIZE_TOKEN
|
||||
#undef TOOLS_GL2PS_LINE_CAP_TOKEN
|
||||
#undef TOOLS_GL2PS_LINE_JOIN_TOKEN
|
||||
#undef TOOLS_GL2PS_LINE_WIDTH_TOKEN
|
||||
#undef TOOLS_GL2PS_BEGIN_BLEND_TOKEN
|
||||
#undef TOOLS_GL2PS_END_BLEND_TOKEN
|
||||
#undef TOOLS_GL2PS_SRC_BLEND_TOKEN
|
||||
#undef TOOLS_GL2PS_DST_BLEND_TOKEN
|
||||
#undef TOOLS_GL2PS_IMAGEMAP_TOKEN
|
||||
#undef TOOLS_GL2PS_DRAW_PIXELS_TOKEN
|
||||
#undef TOOLS_GL2PS_TEXT_TOKEN
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_glbuf
|
||||
#define tools_glbuf
|
||||
|
||||
//define of TOOLS_HAS_GL_VBO decided in the build systems.
|
||||
|
||||
// To have prototypes of glGenBuffers,etc...
|
||||
|
||||
#ifdef TOOLS_HAS_GL_VBO
|
||||
|
||||
#ifdef TOOLS_TOOLS_GL
|
||||
#else
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#elif defined(ANDROID)
|
||||
#elif _WIN32
|
||||
#include <GL/glext.h>
|
||||
#elif __APPLE__
|
||||
#include <OpenGL/glext.h> //Cocoa
|
||||
#else
|
||||
#include <GL/glext.h>
|
||||
#endif
|
||||
|
||||
#endif //TOOLS_TOOLS_GL
|
||||
|
||||
#endif //TOOLS_HAS_GL_VBO
|
||||
|
||||
#endif
|
||||
@@ -50,6 +50,7 @@ inline void cvt_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
|
||||
|
||||
|
||||
inline void triangle_fan_to_triangles(size_t a_npt,const float* a_fxyzs,float*& a_xyzs) {
|
||||
// a_xyzs = (a_npt-2)*3*3
|
||||
|
||||
const float* vpos = a_fxyzs;
|
||||
|
||||
@@ -86,6 +87,7 @@ inline void triangle_fan_to_triangles(size_t a_npt,const float* a_fxyzs,float*&
|
||||
}
|
||||
|
||||
inline void triangle_strip_to_triangles(size_t a_npt,const float* a_fxyzs,float*& a_xyzs) {
|
||||
// a_xyzs = (a_npt-2)*3*3
|
||||
|
||||
const float* vpos = a_fxyzs;
|
||||
|
||||
@@ -152,6 +154,7 @@ inline void triangle_fan_to_triangles(size_t a_npt,
|
||||
inline void triangle_strip_to_triangles(size_t a_npt,
|
||||
const float* a_fxyzs,const float* a_fnms,
|
||||
float*& a_xyzs,float*& a_nms) {
|
||||
// a_xyzs, a_nms = (a_npt-2)*3*3
|
||||
triangle_strip_to_triangles(a_npt,a_fxyzs,a_xyzs);
|
||||
triangle_strip_to_triangles(a_npt,a_fnms,a_nms);
|
||||
}
|
||||
@@ -268,6 +271,181 @@ inline void line_strip_to_lines_2to3(size_t a_npt,const float* a_xys,float*& a_x
|
||||
|
||||
}
|
||||
|
||||
inline void line_strip_to_lines(size_t a_npt,const float* a_xys,float*& a_xyzs) {
|
||||
// a_xyzs = (a_npt-1)*2*3
|
||||
|
||||
const float* vpos = a_xys;
|
||||
|
||||
float x1 = *vpos;vpos++;
|
||||
float y1 = *vpos;vpos++;
|
||||
float z1 = *vpos;vpos++;
|
||||
|
||||
float x2,y2,z2;
|
||||
for(size_t i=1;i<a_npt;i++) {
|
||||
x2 = *vpos;vpos++;
|
||||
y2 = *vpos;vpos++;
|
||||
z2 = *vpos;vpos++;
|
||||
|
||||
*a_xyzs = x1;a_xyzs++;
|
||||
*a_xyzs = y1;a_xyzs++;
|
||||
*a_xyzs = z1;a_xyzs++;
|
||||
|
||||
*a_xyzs = x2;a_xyzs++;
|
||||
*a_xyzs = y2;a_xyzs++;
|
||||
*a_xyzs = z2;a_xyzs++;
|
||||
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
z1 = z2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void line_loop_to_lines(size_t a_npt,const float* a_xys,float*& a_xyzs) {
|
||||
// a_xyzs = a_npt*2*3
|
||||
|
||||
const float* vpos = a_xys;
|
||||
|
||||
float x1 = *vpos;vpos++;
|
||||
float y1 = *vpos;vpos++;
|
||||
float z1 = *vpos;vpos++;
|
||||
|
||||
float x0 = x1;
|
||||
float y0 = y1;
|
||||
float z0 = z1;
|
||||
|
||||
float x2,y2,z2;
|
||||
for(size_t i=1;i<a_npt;i++) {
|
||||
x2 = *vpos;vpos++;
|
||||
y2 = *vpos;vpos++;
|
||||
z2 = *vpos;vpos++;
|
||||
|
||||
*a_xyzs = x1;a_xyzs++;
|
||||
*a_xyzs = y1;a_xyzs++;
|
||||
*a_xyzs = z1;a_xyzs++;
|
||||
|
||||
*a_xyzs = x2;a_xyzs++;
|
||||
*a_xyzs = y2;a_xyzs++;
|
||||
*a_xyzs = z2;a_xyzs++;
|
||||
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
z1 = z2;
|
||||
}
|
||||
|
||||
*a_xyzs = x1;a_xyzs++;
|
||||
*a_xyzs = y1;a_xyzs++;
|
||||
*a_xyzs = z1;a_xyzs++;
|
||||
|
||||
*a_xyzs = x0;a_xyzs++;
|
||||
*a_xyzs = y0;a_xyzs++;
|
||||
*a_xyzs = z0;a_xyzs++;
|
||||
|
||||
}
|
||||
|
||||
/// for DirectX_action :
|
||||
inline void triangle_fan_to_triangles_2to3(size_t a_npt,const float* a_xys,
|
||||
float a_r,float a_g,float a_b,float a_a,
|
||||
float*& a_xyz_rgbas) {
|
||||
|
||||
const float* vpos = a_xys;
|
||||
|
||||
float x1 = *vpos;vpos++;
|
||||
float y1 = *vpos;vpos++;
|
||||
|
||||
float x2 = *vpos;vpos++;
|
||||
float y2 = *vpos;vpos++;
|
||||
|
||||
float x3,y3;
|
||||
for(size_t i=2;i<a_npt;i++) {
|
||||
x3 = *vpos;vpos++;
|
||||
y3 = *vpos;vpos++;
|
||||
|
||||
*a_xyz_rgbas = x1;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = y1;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = 0;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = a_r;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_g;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_b;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_a;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = x2;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = y2;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = 0;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = a_r;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_g;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_b;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_a;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = x3;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = y3;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = 0;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = a_r;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_g;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_b;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_a;a_xyz_rgbas++;
|
||||
|
||||
x2 = x3;
|
||||
y2 = y3;
|
||||
}
|
||||
}
|
||||
|
||||
inline void triangle_fan_to_triangles(size_t a_npt,const float* a_xyzs,
|
||||
float a_r,float a_g,float a_b,float a_a,
|
||||
float*& a_xyz_rgbas) {
|
||||
|
||||
const float* vpos = a_xyzs;
|
||||
|
||||
float x1 = *vpos;vpos++;
|
||||
float y1 = *vpos;vpos++;
|
||||
float z1 = *vpos;vpos++;
|
||||
|
||||
float x2 = *vpos;vpos++;
|
||||
float y2 = *vpos;vpos++;
|
||||
float z2 = *vpos;vpos++;
|
||||
|
||||
float x3,y3,z3;
|
||||
for(size_t i=2;i<a_npt;i++) {
|
||||
x3 = *vpos;vpos++;
|
||||
y3 = *vpos;vpos++;
|
||||
z3 = *vpos;vpos++;
|
||||
|
||||
*a_xyz_rgbas = x1;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = y1;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = z1;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = a_r;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_g;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_b;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_a;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = x2;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = y2;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = z2;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = a_r;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_g;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_b;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_a;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = x3;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = y3;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = z3;a_xyz_rgbas++;
|
||||
|
||||
*a_xyz_rgbas = a_r;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_g;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_b;a_xyz_rgbas++;
|
||||
*a_xyz_rgbas = a_a;a_xyz_rgbas++;
|
||||
|
||||
x2 = x3;
|
||||
y2 = y3;
|
||||
z2 = z3;
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -78,8 +78,8 @@ GLUAPI void GLUAPIENTRY gluTessVertex (GLUtesselator* tess, GLUdouble *location,
|
||||
/* //////////////////////////////////////////////////////////////// */
|
||||
|
||||
/* Boolean values */
|
||||
#define GLU_FALSE 0x0
|
||||
#define GLU_TRUE 0x1
|
||||
#define TOOLS_GLU_FALSE 0x0
|
||||
#define TOOLS_GLU_TRUE 0x1
|
||||
|
||||
/* Primitives */
|
||||
#define GLU_LINE_LOOP 0x0002
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
inline int __gl_vertLeq( GLUvertex *u, GLUvertex *v )
|
||||
{
|
||||
/* Returns GLU_TRUE if u is lexicographically <= v. */
|
||||
/* Returns TOOLS_GLU_TRUE if u is lexicographically <= v. */
|
||||
|
||||
return VertLeq( u, v );
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ gluNewTess( void )
|
||||
|
||||
tess->relTolerance = GLU_TESS_DEFAULT_TOLERANCE;
|
||||
tess->windingRule = GLU_TESS_WINDING_ODD;
|
||||
tess->flagBoundary = GLU_FALSE;
|
||||
tess->boundaryOnly = GLU_FALSE;
|
||||
tess->flagBoundary = TOOLS_GLU_FALSE;
|
||||
tess->boundaryOnly = TOOLS_GLU_FALSE;
|
||||
|
||||
tess->callBegin = &static_noBegin;
|
||||
tess->callEdgeFlag = &static_noEdgeFlag;
|
||||
@@ -222,7 +222,7 @@ gluGetTessProperty( GLUtesselator *tess, GLUenum which, GLUdouble *value )
|
||||
*value= tess->windingRule;
|
||||
break;
|
||||
case GLU_TESS_BOUNDARY_ONLY:
|
||||
assert(tess->boundaryOnly == GLU_TRUE || tess->boundaryOnly == GLU_FALSE);
|
||||
assert(tess->boundaryOnly == TOOLS_GLU_TRUE || tess->boundaryOnly == TOOLS_GLU_FALSE);
|
||||
*value= tess->boundaryOnly;
|
||||
break;
|
||||
default:
|
||||
@@ -398,7 +398,7 @@ inline/*static*/ int static_EmptyCache( GLUtesselator *tess )
|
||||
if ( !static_AddVertex( tess, v->coords, v->data ) ) return 0;
|
||||
}
|
||||
tess->cacheCount = 0;
|
||||
tess->emptyCache = GLU_FALSE;
|
||||
tess->emptyCache = TOOLS_GLU_FALSE;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -407,7 +407,7 @@ inline/*static*/ int static_EmptyCache( GLUtesselator *tess )
|
||||
inline void GLUAPIENTRY
|
||||
gluTessVertex( GLUtesselator *tess, GLUdouble coords[3], void *data )
|
||||
{
|
||||
int i, tooLarge = GLU_FALSE;
|
||||
int i, tooLarge = TOOLS_GLU_FALSE;
|
||||
GLUdouble x, clamped[3];
|
||||
|
||||
RequireState( tess, T_IN_CONTOUR );
|
||||
@@ -423,11 +423,11 @@ gluTessVertex( GLUtesselator *tess, GLUdouble coords[3], void *data )
|
||||
x = coords[i];
|
||||
if( x < - GLU_TESS_MAX_COORD ) {
|
||||
x = - GLU_TESS_MAX_COORD;
|
||||
tooLarge = GLU_TRUE;
|
||||
tooLarge = TOOLS_GLU_TRUE;
|
||||
}
|
||||
if( x > GLU_TESS_MAX_COORD ) {
|
||||
x = GLU_TESS_MAX_COORD;
|
||||
tooLarge = GLU_TRUE;
|
||||
tooLarge = TOOLS_GLU_TRUE;
|
||||
}
|
||||
clamped[i] = x;
|
||||
}
|
||||
@@ -458,7 +458,7 @@ gluTessBeginPolygon( GLUtesselator *tess, void *data )
|
||||
|
||||
tess->state = T_IN_POLYGON;
|
||||
tess->cacheCount = 0;
|
||||
tess->emptyCache = GLU_FALSE;
|
||||
tess->emptyCache = TOOLS_GLU_FALSE;
|
||||
tess->mesh = NULL;
|
||||
|
||||
tess->polygonData= data;
|
||||
@@ -477,7 +477,7 @@ gluTessBeginContour( GLUtesselator *tess )
|
||||
* -- these can be generated accidentally with the obsolete
|
||||
* NextContour() interface.
|
||||
*/
|
||||
tess->emptyCache = GLU_TRUE;
|
||||
tess->emptyCache = TOOLS_GLU_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ gluTessEndPolygon( GLUtesselator *tess )
|
||||
* Otherwise we tessellate all the regions marked "inside".
|
||||
*/
|
||||
if( tess->boundaryOnly ) {
|
||||
rc = __gl_meshSetWindingNumber( mesh, 1, GLU_TRUE );
|
||||
rc = __gl_meshSetWindingNumber( mesh, 1, TOOLS_GLU_TRUE );
|
||||
} else {
|
||||
rc = __gl_meshTessellateInterior( mesh );
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ inline/*static*/ void static_MakeFace( GLUface *newFace, GLUhalfEdge *eOrig, GLU
|
||||
fNew->anEdge = eOrig;
|
||||
fNew->data = NULL;
|
||||
fNew->trail = NULL;
|
||||
fNew->marked = GLU_FALSE;
|
||||
fNew->marked = TOOLS_GLU_FALSE;
|
||||
|
||||
/* The new face is marked "inside" if the old one was. This is a
|
||||
* convenience for the common case where a face has been split in two.
|
||||
@@ -503,19 +503,19 @@ inline GLUhalfEdge *__gl_meshMakeEdge( GLUmesh *mesh )
|
||||
*/
|
||||
inline int __gl_meshSplice( GLUhalfEdge *eOrg, GLUhalfEdge *eDst )
|
||||
{
|
||||
int joiningLoops = GLU_FALSE;
|
||||
int joiningVertices = GLU_FALSE;
|
||||
int joiningLoops = TOOLS_GLU_FALSE;
|
||||
int joiningVertices = TOOLS_GLU_FALSE;
|
||||
|
||||
if( eOrg == eDst ) return 1;
|
||||
|
||||
if( eDst->Org != eOrg->Org ) {
|
||||
/* We are merging two disjoint vertices -- destroy eDst->Org */
|
||||
joiningVertices = GLU_TRUE;
|
||||
joiningVertices = TOOLS_GLU_TRUE;
|
||||
static_KillVertex( eDst->Org, eOrg->Org );
|
||||
}
|
||||
if( eDst->Lface != eOrg->Lface ) {
|
||||
/* We are connecting two disjoint loops -- destroy eDst->Lface */
|
||||
joiningLoops = GLU_TRUE;
|
||||
joiningLoops = TOOLS_GLU_TRUE;
|
||||
static_KillFace( eDst->Lface, eOrg->Lface );
|
||||
}
|
||||
|
||||
@@ -560,14 +560,14 @@ inline int __gl_meshSplice( GLUhalfEdge *eOrg, GLUhalfEdge *eDst )
|
||||
inline int __gl_meshDelete( GLUhalfEdge *eDel )
|
||||
{
|
||||
GLUhalfEdge *eDelSym = eDel->Sym;
|
||||
int joiningLoops = GLU_FALSE;
|
||||
int joiningLoops = TOOLS_GLU_FALSE;
|
||||
|
||||
/* First step: disconnect the origin vertex eDel->Org. We make all
|
||||
* changes to get a consistent mesh in this "intermediate" state.
|
||||
*/
|
||||
if( eDel->Lface != eDel->Rface ) {
|
||||
/* We are joining two loops into one -- remove the left face */
|
||||
joiningLoops = GLU_TRUE;
|
||||
joiningLoops = TOOLS_GLU_TRUE;
|
||||
static_KillFace( eDel->Lface, eDel->Rface );
|
||||
/* G.Barrand : note : Coverity says that there is a problem using eDel->Lface->anEdge in the below,
|
||||
but it appears that at the out of the upper static_KillFace() call (then here), eDel->Lface before
|
||||
@@ -687,7 +687,7 @@ inline GLUhalfEdge *__gl_meshSplitEdge( GLUhalfEdge *eOrg )
|
||||
inline GLUhalfEdge *__gl_meshConnect( GLUhalfEdge *eOrg, GLUhalfEdge *eDst )
|
||||
{
|
||||
GLUhalfEdge *eNewSym;
|
||||
int joiningLoops = GLU_FALSE;
|
||||
int joiningLoops = TOOLS_GLU_FALSE;
|
||||
GLUhalfEdge *eNew = static_MakeEdge( eOrg );
|
||||
if (eNew == NULL) return NULL;
|
||||
|
||||
@@ -695,7 +695,7 @@ inline GLUhalfEdge *__gl_meshConnect( GLUhalfEdge *eOrg, GLUhalfEdge *eDst )
|
||||
|
||||
if( eDst->Lface != eOrg->Lface ) {
|
||||
/* We are connecting two disjoint loops -- destroy eDst->Lface */
|
||||
joiningLoops = GLU_TRUE;
|
||||
joiningLoops = TOOLS_GLU_TRUE;
|
||||
static_KillFace( eDst->Lface, eOrg->Lface );
|
||||
}
|
||||
|
||||
@@ -803,8 +803,8 @@ inline GLUmesh *__gl_meshNewMesh( void )
|
||||
f->anEdge = NULL;
|
||||
f->data = NULL;
|
||||
f->trail = NULL;
|
||||
f->marked = GLU_FALSE;
|
||||
f->inside = GLU_FALSE;
|
||||
f->marked = TOOLS_GLU_FALSE;
|
||||
f->inside = TOOLS_GLU_FALSE;
|
||||
|
||||
e->next = e;
|
||||
e->Sym = eSym;
|
||||
|
||||
@@ -150,14 +150,14 @@ inline void __gl_projectPolygon( GLUtesselator *tess )
|
||||
GLUvertex *v, *vHead = &tess->mesh->vHead;
|
||||
GLUdouble norm[3];
|
||||
GLUdouble *sUnit, *tUnit;
|
||||
int i, computedNormal = GLU_FALSE;
|
||||
int i, computedNormal = TOOLS_GLU_FALSE;
|
||||
|
||||
norm[0] = tess->normal[0];
|
||||
norm[1] = tess->normal[1];
|
||||
norm[2] = tess->normal[2];
|
||||
if( norm[0] == 0 && norm[1] == 0 && norm[2] == 0 ) {
|
||||
static_ComputeNormal( tess, norm );
|
||||
computedNormal = GLU_TRUE;
|
||||
computedNormal = TOOLS_GLU_TRUE;
|
||||
}
|
||||
sUnit = tess->sUnit;
|
||||
tUnit = tess->tUnit;
|
||||
|
||||
@@ -104,7 +104,7 @@ inline PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pq->initialized = GLU_FALSE;
|
||||
pq->initialized = TOOLS_GLU_FALSE;
|
||||
pq->freeList = 0;
|
||||
pq->leq = leq;
|
||||
|
||||
@@ -184,7 +184,7 @@ inline void pqInit( PriorityQ *pq )
|
||||
for( i = pq->size; i >= 1; --i ) {
|
||||
static_FloatDown( pq, i );
|
||||
}
|
||||
pq->initialized = GLU_TRUE;
|
||||
pq->initialized = TOOLS_GLU_TRUE;
|
||||
}
|
||||
|
||||
/* really __gl_pqHeapInsert */
|
||||
@@ -376,7 +376,7 @@ inline PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) )
|
||||
|
||||
pq->size = 0;
|
||||
pq->max = INIT_SIZE();
|
||||
pq->initialized = GLU_FALSE;
|
||||
pq->initialized = TOOLS_GLU_FALSE;
|
||||
pq->leq = leq;
|
||||
return pq;
|
||||
}
|
||||
@@ -464,7 +464,7 @@ inline int pqInit( PriorityQ *pq )
|
||||
}
|
||||
}
|
||||
pq->max = pq->size;
|
||||
pq->initialized = GLU_TRUE;
|
||||
pq->initialized = TOOLS_GLU_TRUE;
|
||||
__gl_pqHeapInit( pq->heap ); /* always succeeds */
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
@@ -64,7 +64,7 @@ inline void __gl_renderMesh( GLUtesselator *tess, GLUmesh *mesh )
|
||||
tess->lonelyTriList = NULL;
|
||||
|
||||
for( f = mesh->fHead.next; f != &mesh->fHead; f = f->next ) {
|
||||
f->marked = GLU_FALSE;
|
||||
f->marked = TOOLS_GLU_FALSE;
|
||||
}
|
||||
for( f = mesh->fHead.next; f != &mesh->fHead; f = f->next ) {
|
||||
|
||||
@@ -122,10 +122,10 @@ inline/*static*/ void static_RenderMaximumFaceGroup( GLUtesselator *tess, GLUfac
|
||||
*/
|
||||
#define Marked(f) (! (f)->inside || (f)->marked)
|
||||
|
||||
#define AddToTrail(f,t) ((f)->trail = (t), (t) = (f), (f)->marked = GLU_TRUE)
|
||||
#define AddToTrail(f,t) ((f)->trail = (t), (t) = (f), (f)->marked = TOOLS_GLU_TRUE)
|
||||
|
||||
//#define FreeTrail(t) if( 1 ) { while( (t) != NULL ) { (t)->marked = GLU_FALSE; t = (t)->trail; } } else
|
||||
#define FreeTrail(t) do { while( (t) != NULL ) { (t)->marked = GLU_FALSE; t = (t)->trail; } } while(false)
|
||||
//#define FreeTrail(t) if( 1 ) { while( (t) != NULL ) { (t)->marked = TOOLS_GLU_FALSE; t = (t)->trail; } } else
|
||||
#define FreeTrail(t) do { while( (t) != NULL ) { (t)->marked = TOOLS_GLU_FALSE; t = (t)->trail; } } while(false)
|
||||
|
||||
inline/*static*/ struct FaceCount static_MaximumFan( GLUhalfEdge *eOrig )
|
||||
{
|
||||
@@ -235,7 +235,7 @@ inline/*static*/ void static_RenderLonelyTriangles( GLUtesselator *tess, GLUface
|
||||
e = f->anEdge;
|
||||
do {
|
||||
if( tess->flagBoundary ) {
|
||||
/* Set the "edge state" to GLU_TRUE just before we output the
|
||||
/* Set the "edge state" to TOOLS_GLU_TRUE just before we output the
|
||||
* first vertex of each edge on the polygon boundary.
|
||||
*/
|
||||
newState = ! e->Rface->inside;
|
||||
@@ -264,7 +264,7 @@ inline/*static*/ void static_RenderFan( GLUtesselator *tess, GLUhalfEdge *e, lon
|
||||
CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data );
|
||||
|
||||
while( ! Marked( e->Lface )) {
|
||||
e->Lface->marked = GLU_TRUE;
|
||||
e->Lface->marked = TOOLS_GLU_TRUE;
|
||||
--size;
|
||||
e = e->Onext;
|
||||
CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data );
|
||||
@@ -286,13 +286,13 @@ inline/*static*/ void static_RenderStrip( GLUtesselator *tess, GLUhalfEdge *e, l
|
||||
CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data );
|
||||
|
||||
while( ! Marked( e->Lface )) {
|
||||
e->Lface->marked = GLU_TRUE;
|
||||
e->Lface->marked = TOOLS_GLU_TRUE;
|
||||
--size;
|
||||
e = e->Dprev;
|
||||
CALL_VERTEX_OR_VERTEX_DATA( e->Org->data );
|
||||
if( Marked( e->Lface )) break;
|
||||
|
||||
e->Lface->marked = GLU_TRUE;
|
||||
e->Lface->marked = TOOLS_GLU_TRUE;
|
||||
--size;
|
||||
e = e->Onext;
|
||||
CALL_VERTEX_OR_VERTEX_DATA( e->Dst->data );
|
||||
@@ -338,8 +338,8 @@ inline int SIGN_INCONSISTENT() {
|
||||
|
||||
inline/*static*/ int static_ComputeNormal( GLUtesselator *tess, GLUdouble norm[3], int check )
|
||||
/*
|
||||
* If check==GLU_FALSE, we compute the polygon normal and place it in norm[].
|
||||
* If check==GLU_TRUE, we check that each triangle in the fan from v0 has a
|
||||
* If check==TOOLS_GLU_FALSE, we compute the polygon normal and place it in norm[].
|
||||
* If check==TOOLS_GLU_TRUE, we check that each triangle in the fan from v0 has a
|
||||
* consistent orientation with respect to norm[]. If triangles are
|
||||
* consistently oriented CCW, return 1; if CW, return -1; if all triangles
|
||||
* are degenerate return 0; otherwise (no consistent orientation) return
|
||||
@@ -412,7 +412,7 @@ inline/*static*/ int static_ComputeNormal( GLUtesselator *tess, GLUdouble norm[3
|
||||
* as a triangle fan. This handles convex polygons, as well as some
|
||||
* non-convex polygons if we get lucky.
|
||||
*
|
||||
* Returns GLU_TRUE if the polygon was successfully rendered. The rendering
|
||||
* Returns TOOLS_GLU_TRUE if the polygon was successfully rendered. The rendering
|
||||
* output is provided as callbacks (see the api).
|
||||
*/
|
||||
inline GLUboolean __gl_renderCache( GLUtesselator *tess )
|
||||
@@ -425,24 +425,24 @@ inline GLUboolean __gl_renderCache( GLUtesselator *tess )
|
||||
|
||||
if( tess->cacheCount < 3 ) {
|
||||
/* Degenerate contour -- no output */
|
||||
return GLU_TRUE;
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
|
||||
norm[0] = tess->normal[0];
|
||||
norm[1] = tess->normal[1];
|
||||
norm[2] = tess->normal[2];
|
||||
if( norm[0] == 0 && norm[1] == 0 && norm[2] == 0 ) {
|
||||
static_ComputeNormal( tess, norm, GLU_FALSE );
|
||||
static_ComputeNormal( tess, norm, TOOLS_GLU_FALSE );
|
||||
}
|
||||
|
||||
sign = static_ComputeNormal( tess, norm, GLU_TRUE );
|
||||
sign = static_ComputeNormal( tess, norm, TOOLS_GLU_TRUE );
|
||||
if( sign == SIGN_INCONSISTENT() ) {
|
||||
/* Fan triangles did not have a consistent orientation */
|
||||
return GLU_FALSE;
|
||||
return TOOLS_GLU_FALSE;
|
||||
}
|
||||
if( sign == 0 ) {
|
||||
/* All triangles were degenerate */
|
||||
return GLU_TRUE;
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
|
||||
/* Make sure we do the right thing for each winding rule */
|
||||
@@ -451,13 +451,13 @@ inline GLUboolean __gl_renderCache( GLUtesselator *tess )
|
||||
case GLU_TESS_WINDING_NONZERO:
|
||||
break;
|
||||
case GLU_TESS_WINDING_POSITIVE:
|
||||
if( sign < 0 ) return GLU_TRUE;
|
||||
if( sign < 0 ) return TOOLS_GLU_TRUE;
|
||||
break;
|
||||
case GLU_TESS_WINDING_NEGATIVE:
|
||||
if( sign > 0 ) return GLU_TRUE;
|
||||
if( sign > 0 ) return TOOLS_GLU_TRUE;
|
||||
break;
|
||||
case GLU_TESS_WINDING_ABS_GEQ_TWO:
|
||||
return GLU_TRUE;
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
|
||||
CALL_BEGIN_OR_BEGIN_DATA( tess->boundaryOnly ? GLU_LINE_LOOP
|
||||
@@ -475,7 +475,7 @@ inline GLUboolean __gl_renderCache( GLUtesselator *tess )
|
||||
}
|
||||
}
|
||||
CALL_END_OR_END_DATA();
|
||||
return GLU_TRUE;
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -146,7 +146,7 @@ inline/*static*/ int static_FixUpperEdge( ActiveRegion *reg, GLUhalfEdge *newEdg
|
||||
{
|
||||
assert( reg->fixUpperEdge );
|
||||
if ( !__gl_meshDelete( reg->eUp ) ) return 0;
|
||||
reg->fixUpperEdge = GLU_FALSE;
|
||||
reg->fixUpperEdge = TOOLS_GLU_FALSE;
|
||||
reg->eUp = newEdge;
|
||||
newEdge->activeRegion = reg;
|
||||
|
||||
@@ -203,9 +203,9 @@ inline/*static*/ ActiveRegion *static_AddRegionBelow( GLUtesselator *tess,
|
||||
/* __gl_dictListInsertBefore */
|
||||
regNew->nodeUp = dictInsertBefore( tess->dict, regAbove->nodeUp, regNew );
|
||||
if (regNew->nodeUp == NULL) longjmp(tess->env,1);
|
||||
regNew->fixUpperEdge = GLU_FALSE;
|
||||
regNew->sentinel = GLU_FALSE;
|
||||
regNew->dirty = GLU_FALSE;
|
||||
regNew->fixUpperEdge = TOOLS_GLU_FALSE;
|
||||
regNew->sentinel = TOOLS_GLU_FALSE;
|
||||
regNew->dirty = TOOLS_GLU_FALSE;
|
||||
|
||||
eNewUp->activeRegion = regNew;
|
||||
return regNew;
|
||||
@@ -226,9 +226,9 @@ inline/*static*/ GLUboolean static_IsWindingInside( GLUtesselator *tess, int n )
|
||||
return (n >= 2) || (n <= -2);
|
||||
}
|
||||
/*LINTED*/
|
||||
assert( GLU_FALSE );
|
||||
assert( TOOLS_GLU_FALSE );
|
||||
/*NOTREACHED*/
|
||||
return GLU_FALSE; /* avoid compiler complaints */
|
||||
return TOOLS_GLU_FALSE; /* avoid compiler complaints */
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ inline/*static*/ GLUhalfEdge *static_FinishLeftRegions( GLUtesselator *tess,
|
||||
regPrev = regFirst;
|
||||
ePrev = regFirst->eUp;
|
||||
while( regPrev != regLast ) {
|
||||
regPrev->fixUpperEdge = GLU_FALSE; /* placement was OK */
|
||||
regPrev->fixUpperEdge = TOOLS_GLU_FALSE; /* placement was OK */
|
||||
reg = RegionBelow( regPrev );
|
||||
e = reg->eUp;
|
||||
if( e->Org != ePrev->Org ) {
|
||||
@@ -329,7 +329,7 @@ inline/*static*/ void static_AddRightEdges( GLUtesselator *tess, ActiveRegion *r
|
||||
{
|
||||
ActiveRegion *reg, *regPrev;
|
||||
GLUhalfEdge *e, *ePrev;
|
||||
int firstTime = GLU_TRUE;
|
||||
int firstTime = TOOLS_GLU_TRUE;
|
||||
|
||||
/* Insert the new right-going edges in the dictionary */
|
||||
e = eFirst;
|
||||
@@ -365,17 +365,17 @@ inline/*static*/ void static_AddRightEdges( GLUtesselator *tess, ActiveRegion *r
|
||||
/* Check for two outgoing edges with same slope -- process these
|
||||
* before any intersection tests (see example in __gl_computeInterior).
|
||||
*/
|
||||
regPrev->dirty = GLU_TRUE;
|
||||
regPrev->dirty = TOOLS_GLU_TRUE;
|
||||
if( ! firstTime && static_CheckForRightSplice( tess, regPrev )) {
|
||||
AddWinding( e, ePrev );
|
||||
static_DeleteRegion( tess, regPrev );
|
||||
if ( !__gl_meshDelete( ePrev ) ) longjmp(tess->env,1);
|
||||
}
|
||||
firstTime = GLU_FALSE;
|
||||
firstTime = TOOLS_GLU_FALSE;
|
||||
regPrev = reg;
|
||||
ePrev = e;
|
||||
}
|
||||
regPrev->dirty = GLU_TRUE;
|
||||
regPrev->dirty = TOOLS_GLU_TRUE;
|
||||
assert( regPrev->windingNumber - e->winding == reg->windingNumber );
|
||||
|
||||
if( cleanUp ) {
|
||||
@@ -406,7 +406,7 @@ inline/*static*/ void static_CallCombine( GLUtesselator *tess, GLUvertex *isect,
|
||||
* generated intersection points.
|
||||
*/
|
||||
CALL_ERROR_OR_ERROR_DATA( GLU_TESS_NEED_COMBINE_CALLBACK );
|
||||
tess->fatalError = GLU_TRUE;
|
||||
tess->fatalError = TOOLS_GLU_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -423,7 +423,7 @@ inline/*static*/ void static_SpliceMergeVertices( GLUtesselator *tess, GLUhalfEd
|
||||
|
||||
data[0] = e1->Org->data;
|
||||
data[1] = e2->Org->data;
|
||||
static_CallCombine( tess, e1->Org, data, weights, GLU_FALSE );
|
||||
static_CallCombine( tess, e1->Org, data, weights, TOOLS_GLU_FALSE );
|
||||
if ( !__gl_meshSplice( e1, e2 ) ) longjmp(tess->env,1);
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ inline/*static*/ void static_GetIntersectData( GLUtesselator *tess, GLUvertex *i
|
||||
static_VertexWeights( isect, orgUp, dstUp, &weights[0] );
|
||||
static_VertexWeights( isect, orgLo, dstLo, &weights[2] );
|
||||
|
||||
static_CallCombine( tess, isect, data, weights, GLU_TRUE );
|
||||
static_CallCombine( tess, isect, data, weights, TOOLS_GLU_TRUE );
|
||||
}
|
||||
|
||||
inline/*static*/ int static_CheckForRightSplice( GLUtesselator *tess, ActiveRegion *regUp )
|
||||
@@ -504,14 +504,14 @@ inline/*static*/ int static_CheckForRightSplice( GLUtesselator *tess, ActiveRegi
|
||||
GLUhalfEdge *eLo = regLo->eUp;
|
||||
|
||||
if( VertLeq( eUp->Org, eLo->Org )) {
|
||||
if( EdgeSign( eLo->Dst, eUp->Org, eLo->Org ) > 0 ) return GLU_FALSE;
|
||||
if( EdgeSign( eLo->Dst, eUp->Org, eLo->Org ) > 0 ) return TOOLS_GLU_FALSE;
|
||||
|
||||
/* eUp->Org appears to be below eLo */
|
||||
if( ! VertEq( eUp->Org, eLo->Org )) {
|
||||
/* Splice eUp->Org into eLo */
|
||||
if ( __gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1);
|
||||
if ( !__gl_meshSplice( eUp, eLo->Oprev ) ) longjmp(tess->env,1);
|
||||
regUp->dirty = regLo->dirty = GLU_TRUE;
|
||||
regUp->dirty = regLo->dirty = TOOLS_GLU_TRUE;
|
||||
|
||||
} else if( eUp->Org != eLo->Org ) {
|
||||
/* merge the two vertices, discarding eUp->Org */
|
||||
@@ -519,14 +519,14 @@ inline/*static*/ int static_CheckForRightSplice( GLUtesselator *tess, ActiveRegi
|
||||
static_SpliceMergeVertices( tess, eLo->Oprev, eUp );
|
||||
}
|
||||
} else {
|
||||
if( EdgeSign( eUp->Dst, eLo->Org, eUp->Org ) < 0 ) return GLU_FALSE;
|
||||
if( EdgeSign( eUp->Dst, eLo->Org, eUp->Org ) < 0 ) return TOOLS_GLU_FALSE;
|
||||
|
||||
/* eLo->Org appears to be above eUp, so splice eLo->Org into eUp */
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = GLU_TRUE;
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = TOOLS_GLU_TRUE;
|
||||
if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1);
|
||||
if ( !__gl_meshSplice( eLo->Oprev, eUp ) ) longjmp(tess->env,1);
|
||||
}
|
||||
return GLU_TRUE;
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
|
||||
inline/*static*/ int static_CheckForLeftSplice( GLUtesselator *tess, ActiveRegion *regUp )
|
||||
@@ -557,25 +557,25 @@ inline/*static*/ int static_CheckForLeftSplice( GLUtesselator *tess, ActiveRegio
|
||||
assert( ! VertEq( eUp->Dst, eLo->Dst ));
|
||||
|
||||
if( VertLeq( eUp->Dst, eLo->Dst )) {
|
||||
if( EdgeSign( eUp->Dst, eLo->Dst, eUp->Org ) < 0 ) return GLU_FALSE;
|
||||
if( EdgeSign( eUp->Dst, eLo->Dst, eUp->Org ) < 0 ) return TOOLS_GLU_FALSE;
|
||||
|
||||
/* eLo->Dst is above eUp, so splice eLo->Dst into eUp */
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = GLU_TRUE;
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = TOOLS_GLU_TRUE;
|
||||
e = __gl_meshSplitEdge( eUp );
|
||||
if (e == NULL) longjmp(tess->env,1);
|
||||
if ( !__gl_meshSplice( eLo->Sym, e ) ) longjmp(tess->env,1);
|
||||
e->Lface->inside = regUp->inside;
|
||||
} else {
|
||||
if( EdgeSign( eLo->Dst, eUp->Dst, eLo->Org ) > 0 ) return GLU_FALSE;
|
||||
if( EdgeSign( eLo->Dst, eUp->Dst, eLo->Org ) > 0 ) return TOOLS_GLU_FALSE;
|
||||
|
||||
/* eUp->Dst is below eLo, so splice eUp->Dst into eLo */
|
||||
regUp->dirty = regLo->dirty = GLU_TRUE;
|
||||
regUp->dirty = regLo->dirty = TOOLS_GLU_TRUE;
|
||||
e = __gl_meshSplitEdge( eLo );
|
||||
if (e == NULL) longjmp(tess->env,1);
|
||||
if ( !__gl_meshSplice( eUp->Lnext, eLo->Sym ) ) longjmp(tess->env,1);
|
||||
e->Rface->inside = regUp->inside;
|
||||
}
|
||||
return GLU_TRUE;
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -585,7 +585,7 @@ inline/*static*/ int static_CheckForIntersect( GLUtesselator *tess, ActiveRegion
|
||||
* they intersect. If so, create the intersection and add it
|
||||
* to the data structures.
|
||||
*
|
||||
* Returns GLU_TRUE if adding the new intersection resulted in a recursive
|
||||
* Returns TOOLS_GLU_TRUE if adding the new intersection resulted in a recursive
|
||||
* call to AddRightEdges(); in this case all "dirty" regions have been
|
||||
* checked for intersections, and possibly regUp has been deleted.
|
||||
*/
|
||||
@@ -607,16 +607,16 @@ inline/*static*/ int static_CheckForIntersect( GLUtesselator *tess, ActiveRegion
|
||||
assert( orgUp != tess->event && orgLo != tess->event );
|
||||
assert( ! regUp->fixUpperEdge && ! regLo->fixUpperEdge );
|
||||
|
||||
if( orgUp == orgLo ) return GLU_FALSE; /* right endpoints are the same */
|
||||
if( orgUp == orgLo ) return TOOLS_GLU_FALSE; /* right endpoints are the same */
|
||||
|
||||
tMinUp = GLU_MIN( orgUp->t, dstUp->t );
|
||||
tMaxLo = GLU_MAX( orgLo->t, dstLo->t );
|
||||
if( tMinUp > tMaxLo ) return GLU_FALSE; /* t ranges do not overlap */
|
||||
if( tMinUp > tMaxLo ) return TOOLS_GLU_FALSE; /* t ranges do not overlap */
|
||||
|
||||
if( VertLeq( orgUp, orgLo )) {
|
||||
if( EdgeSign( dstLo, orgUp, orgLo ) > 0 ) return GLU_FALSE;
|
||||
if( EdgeSign( dstLo, orgUp, orgLo ) > 0 ) return TOOLS_GLU_FALSE;
|
||||
} else {
|
||||
if( EdgeSign( dstUp, orgLo, orgUp ) < 0 ) return GLU_FALSE;
|
||||
if( EdgeSign( dstUp, orgLo, orgUp ) < 0 ) return TOOLS_GLU_FALSE;
|
||||
}
|
||||
|
||||
/* At this point the edges intersect, at least marginally */
|
||||
@@ -654,7 +654,7 @@ inline/*static*/ int static_CheckForIntersect( GLUtesselator *tess, ActiveRegion
|
||||
if( VertEq( &isect, orgUp ) || VertEq( &isect, orgLo )) {
|
||||
/* Easy case -- intersection at one of the right endpoints */
|
||||
(void) static_CheckForRightSplice( tess, regUp );
|
||||
return GLU_FALSE;
|
||||
return TOOLS_GLU_FALSE;
|
||||
}
|
||||
|
||||
if( (! VertEq( dstUp, tess->event )
|
||||
@@ -674,8 +674,8 @@ inline/*static*/ int static_CheckForIntersect( GLUtesselator *tess, ActiveRegion
|
||||
if (regUp == NULL) longjmp(tess->env,1);
|
||||
eUp = RegionBelow(regUp)->eUp;
|
||||
static_FinishLeftRegions( tess, RegionBelow(regUp), regLo );
|
||||
static_AddRightEdges( tess, regUp, eUp->Oprev, eUp, eUp, GLU_TRUE );
|
||||
return GLU_TRUE;
|
||||
static_AddRightEdges( tess, regUp, eUp->Oprev, eUp, eUp, TOOLS_GLU_TRUE );
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
if( dstUp == tess->event ) {
|
||||
/* Splice dstUp into eLo, and process the new region(s) */
|
||||
@@ -686,27 +686,27 @@ inline/*static*/ int static_CheckForIntersect( GLUtesselator *tess, ActiveRegion
|
||||
e = RegionBelow(regUp)->eUp->Rprev;
|
||||
regLo->eUp = eLo->Oprev;
|
||||
eLo = static_FinishLeftRegions( tess, regLo, NULL );
|
||||
static_AddRightEdges( tess, regUp, eLo->Onext, eUp->Rprev, e, GLU_TRUE );
|
||||
return GLU_TRUE;
|
||||
static_AddRightEdges( tess, regUp, eLo->Onext, eUp->Rprev, e, TOOLS_GLU_TRUE );
|
||||
return TOOLS_GLU_TRUE;
|
||||
}
|
||||
/* Special case: called from ConnectRightVertex. If either
|
||||
* edge passes on the wrong side of tess->event, split it
|
||||
* (and wait for ConnectRightVertex to splice it appropriately).
|
||||
*/
|
||||
if( EdgeSign( dstUp, tess->event, &isect ) >= 0 ) {
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = GLU_TRUE;
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = TOOLS_GLU_TRUE;
|
||||
if (__gl_meshSplitEdge( eUp->Sym ) == NULL) longjmp(tess->env,1);
|
||||
eUp->Org->s = tess->event->s;
|
||||
eUp->Org->t = tess->event->t;
|
||||
}
|
||||
if( EdgeSign( dstLo, tess->event, &isect ) <= 0 ) {
|
||||
regUp->dirty = regLo->dirty = GLU_TRUE;
|
||||
regUp->dirty = regLo->dirty = TOOLS_GLU_TRUE;
|
||||
if (__gl_meshSplitEdge( eLo->Sym ) == NULL) longjmp(tess->env,1);
|
||||
eLo->Org->s = tess->event->s;
|
||||
eLo->Org->t = tess->event->t;
|
||||
}
|
||||
/* leave the rest for ConnectRightVertex */
|
||||
return GLU_FALSE;
|
||||
return TOOLS_GLU_FALSE;
|
||||
}
|
||||
|
||||
/* General case -- split both edges, splice into new vertex.
|
||||
@@ -729,8 +729,8 @@ inline/*static*/ int static_CheckForIntersect( GLUtesselator *tess, ActiveRegion
|
||||
longjmp(tess->env,1);
|
||||
}
|
||||
static_GetIntersectData( tess, eUp->Org, orgUp, dstUp, orgLo, dstLo );
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = regLo->dirty = GLU_TRUE;
|
||||
return GLU_FALSE;
|
||||
RegionAbove(regUp)->dirty = regUp->dirty = regLo->dirty = TOOLS_GLU_TRUE;
|
||||
return TOOLS_GLU_FALSE;
|
||||
}
|
||||
|
||||
inline/*static*/ void static_WalkDirtyRegions( GLUtesselator *tess, ActiveRegion *regUp )
|
||||
@@ -760,7 +760,7 @@ inline/*static*/ void static_WalkDirtyRegions( GLUtesselator *tess, ActiveRegion
|
||||
return;
|
||||
}
|
||||
}
|
||||
regUp->dirty = GLU_FALSE;
|
||||
regUp->dirty = TOOLS_GLU_FALSE;
|
||||
eUp = regUp->eUp;
|
||||
eLo = regLo->eUp;
|
||||
|
||||
@@ -859,7 +859,7 @@ inline/*static*/ void static_ConnectRightVertex( GLUtesselator *tess, ActiveRegi
|
||||
ActiveRegion *regLo = RegionBelow(regUp);
|
||||
GLUhalfEdge *eUp = regUp->eUp;
|
||||
GLUhalfEdge *eLo = regLo->eUp;
|
||||
int degenerate = GLU_FALSE;
|
||||
int degenerate = TOOLS_GLU_FALSE;
|
||||
|
||||
if( eUp->Dst != eLo->Dst ) {
|
||||
(void) static_CheckForIntersect( tess, regUp );
|
||||
@@ -874,15 +874,15 @@ inline/*static*/ void static_ConnectRightVertex( GLUtesselator *tess, ActiveRegi
|
||||
if (regUp == NULL) longjmp(tess->env,1);
|
||||
eTopLeft = RegionBelow( regUp )->eUp;
|
||||
static_FinishLeftRegions( tess, RegionBelow(regUp), regLo );
|
||||
degenerate = GLU_TRUE;
|
||||
degenerate = TOOLS_GLU_TRUE;
|
||||
}
|
||||
if( VertEq( eLo->Org, tess->event )) {
|
||||
if ( !__gl_meshSplice( eBottomLeft, eLo->Oprev ) ) longjmp(tess->env,1);
|
||||
eBottomLeft = static_FinishLeftRegions( tess, regLo, NULL );
|
||||
degenerate = GLU_TRUE;
|
||||
degenerate = TOOLS_GLU_TRUE;
|
||||
}
|
||||
if( degenerate ) {
|
||||
static_AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, GLU_TRUE );
|
||||
static_AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, TOOLS_GLU_TRUE );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -900,8 +900,8 @@ inline/*static*/ void static_ConnectRightVertex( GLUtesselator *tess, ActiveRegi
|
||||
/* Prevent cleanup, otherwise eNew might disappear before we've even
|
||||
* had a chance to mark it as a temporary edge.
|
||||
*/
|
||||
static_AddRightEdges( tess, regUp, eNew, eNew->Onext, eNew->Onext, GLU_FALSE );
|
||||
eNew->Sym->activeRegion->fixUpperEdge = GLU_TRUE;
|
||||
static_AddRightEdges( tess, regUp, eNew, eNew->Onext, eNew->Onext, TOOLS_GLU_FALSE );
|
||||
eNew->Sym->activeRegion->fixUpperEdge = TOOLS_GLU_TRUE;
|
||||
static_WalkDirtyRegions( tess, regUp );
|
||||
}
|
||||
|
||||
@@ -912,7 +912,7 @@ inline/*static*/ void static_ConnectRightVertex( GLUtesselator *tess, ActiveRegi
|
||||
* TOLERANCE_NONZERO will be useful. They were debugged before the
|
||||
* code to merge identical vertices in the main loop was added.
|
||||
*/
|
||||
//#define TOLERANCE_NONZERO GLU_FALSE
|
||||
//#define TOLERANCE_NONZERO TOOLS_GLU_FALSE
|
||||
|
||||
inline/*static*/ void static_ConnectLeftDegenerate( GLUtesselator *tess,
|
||||
ActiveRegion *regUp, GLUvertex *vEvent )
|
||||
@@ -930,7 +930,7 @@ inline/*static*/ void static_ConnectLeftDegenerate( GLUtesselator *tess,
|
||||
/* e->Org is an unprocessed vertex - just combine them, and wait
|
||||
* for e->Org to be pulled from the queue
|
||||
*/
|
||||
assert( /*TOLERANCE_NONZERO*/ GLU_FALSE );
|
||||
assert( /*TOLERANCE_NONZERO*/ TOOLS_GLU_FALSE );
|
||||
static_SpliceMergeVertices( tess, e, vEvent->anEdge );
|
||||
return;
|
||||
}
|
||||
@@ -941,7 +941,7 @@ inline/*static*/ void static_ConnectLeftDegenerate( GLUtesselator *tess,
|
||||
if( regUp->fixUpperEdge ) {
|
||||
/* This edge was fixable -- delete unused portion of original edge */
|
||||
if ( !__gl_meshDelete( e->Onext ) ) longjmp(tess->env,1);
|
||||
regUp->fixUpperEdge = GLU_FALSE;
|
||||
regUp->fixUpperEdge = TOOLS_GLU_FALSE;
|
||||
}
|
||||
if ( !__gl_meshSplice( vEvent->anEdge, e ) ) longjmp(tess->env,1);
|
||||
static_SweepEvent( tess, vEvent ); /* recurse */
|
||||
@@ -951,7 +951,7 @@ inline/*static*/ void static_ConnectLeftDegenerate( GLUtesselator *tess,
|
||||
/* vEvent coincides with e->Dst, which has already been processed.
|
||||
* Splice in the additional right-going edges.
|
||||
*/
|
||||
assert( /*TOLERANCE_NONZERO*/ GLU_FALSE );
|
||||
assert( /*TOLERANCE_NONZERO*/ TOOLS_GLU_FALSE );
|
||||
regUp = static_TopRightRegion( regUp );
|
||||
reg = RegionBelow( regUp );
|
||||
eTopRight = reg->eUp->Sym;
|
||||
@@ -970,7 +970,7 @@ inline/*static*/ void static_ConnectLeftDegenerate( GLUtesselator *tess,
|
||||
/* e->Dst had no left-going edges -- indicate this to AddRightEdges() */
|
||||
eTopLeft = NULL;
|
||||
}
|
||||
static_AddRightEdges( tess, regUp, eTopRight->Onext, eLast, eTopLeft, GLU_TRUE );
|
||||
static_AddRightEdges( tess, regUp, eTopRight->Onext, eLast, eTopLeft, TOOLS_GLU_TRUE );
|
||||
}
|
||||
|
||||
|
||||
@@ -1036,7 +1036,7 @@ inline/*static*/ void static_ConnectLeftVertex( GLUtesselator *tess, GLUvertex *
|
||||
/* The new vertex is in a region which does not belong to the polygon.
|
||||
* We don''t need to connect this vertex to the rest of the mesh.
|
||||
*/
|
||||
static_AddRightEdges( tess, regUp, vEvent->anEdge, vEvent->anEdge, NULL, GLU_TRUE );
|
||||
static_AddRightEdges( tess, regUp, vEvent->anEdge, vEvent->anEdge, NULL, TOOLS_GLU_TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1089,7 +1089,7 @@ inline/*static*/ void static_SweepEvent( GLUtesselator *tess, GLUvertex *vEvent
|
||||
/* No right-going edges -- add a temporary "fixable" edge */
|
||||
static_ConnectRightVertex( tess, regUp, eBottomLeft );
|
||||
} else {
|
||||
static_AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, GLU_TRUE );
|
||||
static_AddRightEdges( tess, regUp, eBottomLeft->Onext, eTopLeft, eTopLeft, TOOLS_GLU_TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1126,10 +1126,10 @@ inline/*static*/ void static_AddSentinel( GLUtesselator *tess, GLUdouble t )
|
||||
|
||||
reg->eUp = e;
|
||||
reg->windingNumber = 0;
|
||||
reg->inside = GLU_FALSE;
|
||||
reg->fixUpperEdge = GLU_FALSE;
|
||||
reg->sentinel = GLU_TRUE;
|
||||
reg->dirty = GLU_FALSE;
|
||||
reg->inside = TOOLS_GLU_FALSE;
|
||||
reg->fixUpperEdge = TOOLS_GLU_FALSE;
|
||||
reg->sentinel = TOOLS_GLU_TRUE;
|
||||
reg->dirty = TOOLS_GLU_FALSE;
|
||||
reg->nodeUp = dictInsert( tess->dict, reg ); /* __gl_dictListInsertBefore */
|
||||
if (reg->nodeUp == NULL) longjmp(tess->env,1);
|
||||
}
|
||||
@@ -1295,7 +1295,7 @@ inline int __gl_computeInterior( GLUtesselator *tess )
|
||||
{
|
||||
GLUvertex *v, *vNext;
|
||||
|
||||
tess->fatalError = GLU_FALSE;
|
||||
tess->fatalError = TOOLS_GLU_FALSE;
|
||||
|
||||
/* Each vertex defines an event for our sweep line. Start by inserting
|
||||
* all the vertices in a priority queue. Events are processed in
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* polygon have a winding number of "value", and regions outside
|
||||
* have a winding number of 0.
|
||||
*
|
||||
* If keepOnlyBoundary is GLU_TRUE, it also deletes all edges which do not
|
||||
* If keepOnlyBoundary is TOOLS_GLU_TRUE, it also deletes all edges which do not
|
||||
* separate an interior region from an exterior one.
|
||||
*/
|
||||
|
||||
@@ -173,7 +173,7 @@ inline void __gl_meshDiscardExterior( GLUmesh *mesh )
|
||||
* polygon have a winding number of "value", and regions outside
|
||||
* have a winding number of 0.
|
||||
*
|
||||
* If keepOnlyBoundary is GLU_TRUE, it also deletes all edges which do not
|
||||
* If keepOnlyBoundary is TOOLS_GLU_TRUE, it also deletes all edges which do not
|
||||
* separate an interior region from an exterior one.
|
||||
*/
|
||||
inline int __gl_meshSetWindingNumber( GLUmesh *mesh, int value,
|
||||
|
||||
@@ -63,8 +63,8 @@
|
||||
#undef GLU_MIN
|
||||
#undef GLU_MAX
|
||||
#undef GLU_ABS
|
||||
#undef GLU_FALSE
|
||||
#undef GLU_TRUE
|
||||
#undef TOOLS_GLU_FALSE
|
||||
#undef TOOLS_GLU_TRUE
|
||||
#undef GLU_LINE_LOOP
|
||||
#undef GLU_TRIANGLES
|
||||
#undef GLU_TRIANGLE_STRIP
|
||||
|
||||
@@ -32,7 +32,7 @@ inline bool hatcher::check_polyline(vec3f* listPoints,unsigned int aNumber){
|
||||
|
||||
if ((int)aNumber-firstOffset <3) {
|
||||
#ifdef TOOLS_HATCHER_DEBUG
|
||||
::printf("hatcher::check_polyline : ERROR the polygon you give has not enough points!\n\n");
|
||||
::printf("hatcher::check_polyline : ERROR the polygone you give have not enought points!\n\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ inline bool hatcher::compute_polyline (vec3f* tabPoints,unsigned int aNumber) {
|
||||
return true;
|
||||
} else {
|
||||
#ifdef TOOLS_HATCHER_DEBUG
|
||||
::printf("hatcher::drawStripPolyline : WARNING there is a case which was not done in the algorithm...possibly some drawing problems.\n\n");
|
||||
::printf("hatcher::drawStripPolyline : WARNING there is a case witch was not done in the algotithm...possibly some drawing problems.\n\n");
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -606,10 +606,10 @@ inline bool hatcher::compute_single_polyline (vec3f* tabPoints,unsigned int aNum
|
||||
fNormal[2]*AB[0]-fNormal[0]*AB[2],
|
||||
fNormal[0]*AB[1]-fNormal[1]*AB[0]);
|
||||
|
||||
float normAB =(float)sqrt(std::pow(AB[0],2)+
|
||||
float normAB =(float)std::sqrt(std::pow(AB[0],2)+
|
||||
std::pow(AB[1],2)+
|
||||
std::pow(AB[2],2));
|
||||
float normABPerpVector =(float)sqrt(std::pow(ABPerpVector[0],2)+
|
||||
float normABPerpVector =(float)std::sqrt(std::pow(ABPerpVector[0],2)+
|
||||
std::pow(ABPerpVector[1],2)+
|
||||
std::pow(ABPerpVector[2],2));
|
||||
|
||||
@@ -643,7 +643,7 @@ inline bool hatcher::compute_single_polyline (vec3f* tabPoints,unsigned int aNum
|
||||
|
||||
// normalize vector to match the shift size
|
||||
float param = 1.0f;
|
||||
param = (float)sqrt((std::pow(fShift,2))/(
|
||||
param = (float)std::sqrt((std::pow(fShift,2))/(
|
||||
std::pow(dirShiftVector[0],2)+
|
||||
std::pow(dirShiftVector[1],2)+
|
||||
std::pow(dirShiftVector[2],2)));
|
||||
|
||||
@@ -106,6 +106,81 @@ inline bool write_array(hid_t a_loc,const std::string& a_name,
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool write_vlen(hid_t a_loc,const std::string& a_name,
|
||||
hid_t a_file_type,hid_t a_mem_type,
|
||||
unsigned int a_chunked,unsigned int a_compress,
|
||||
unsigned int a_size,const T a_array[]) {
|
||||
hid_t cpt = -1;
|
||||
if(a_compress || a_chunked) {
|
||||
cpt = ::H5Pcreate(H5P_DATASET_CREATE);
|
||||
if(cpt<0) return false;
|
||||
if(a_chunked) {
|
||||
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
hsize_t cdims[1];
|
||||
cdims[0] = a_chunked;
|
||||
if(H5Pset_chunk(cpt,1,cdims)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(a_compress) {
|
||||
if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cpt = H5P_DEFAULT;
|
||||
}
|
||||
|
||||
hid_t dataset = -1;
|
||||
|
||||
{hsize_t dims[1];
|
||||
dims[0] = 1;
|
||||
hid_t file_space = -1;
|
||||
if(a_chunked) {
|
||||
hsize_t mx_dims[1];
|
||||
mx_dims[0] = H5S_UNLIMITED; //extendable.
|
||||
file_space = ::H5Screate_simple(1,dims,mx_dims);
|
||||
} else {
|
||||
file_space = ::H5Screate_simple(1,dims,NULL);
|
||||
}
|
||||
if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);return false;}
|
||||
|
||||
hid_t file_type = ::H5Tvlen_create(a_file_type);
|
||||
|
||||
dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,file_space,cpt);
|
||||
if(cpt>=0) ::H5Pclose(cpt);
|
||||
::H5Sclose(file_space);
|
||||
::H5Tclose(file_type);
|
||||
if(dataset<0) return false;}
|
||||
|
||||
hid_t mem_type = ::H5Tvlen_create(a_mem_type);
|
||||
|
||||
hvl_t wdata[1];
|
||||
wdata[0].len = a_size;
|
||||
wdata[0].p = (void*)a_array;
|
||||
|
||||
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) {
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
return false;
|
||||
}
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
|
||||
hid_t a_file_type,hid_t a_mem_type,
|
||||
@@ -286,6 +361,66 @@ inline bool write_append_array_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool write_append_vlen_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid_t a_mem_type,
|
||||
unsigned int a_number,const T a_array[]) {
|
||||
hsize_t old_size = 0;
|
||||
|
||||
{hid_t dataspace = H5Dget_space(a_dataset);
|
||||
if(dataspace<0) return false;
|
||||
hsize_t dims[1];
|
||||
if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
|
||||
::H5Sclose(dataspace);
|
||||
return false;
|
||||
}
|
||||
old_size = dims[0];
|
||||
::H5Sclose(dataspace);}
|
||||
|
||||
{hsize_t exts[1];
|
||||
exts[0] = old_size+1;
|
||||
// if(H5Dextend(dataset,exts)<0) {
|
||||
if(H5Dset_extent(a_dataset,exts)<0) return false;}
|
||||
|
||||
hid_t file_space = H5Dget_space(a_dataset);
|
||||
if(file_space<0) return false;
|
||||
|
||||
{hsize_t offset[1];
|
||||
offset[0] = old_size;
|
||||
hsize_t count[1];
|
||||
count[0] = 1;
|
||||
if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
|
||||
::H5Sclose(file_space);
|
||||
return false;
|
||||
}}
|
||||
|
||||
hsize_t dims[1];
|
||||
dims[0] = 1;
|
||||
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
|
||||
if(mem_space<0) {
|
||||
::H5Sclose(file_space);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t mem_type = ::H5Tvlen_create(a_mem_type);
|
||||
|
||||
hvl_t wdata[1];
|
||||
wdata[0].len = a_number;
|
||||
wdata[0].p = (void*)a_array;
|
||||
|
||||
if(H5Dwrite(a_dataset,mem_type,mem_space,file_space,H5P_DEFAULT,wdata)<0) {
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
return false;
|
||||
}
|
||||
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool write_append_array(hid_t a_loc,const std::string& a_name,hid_t a_file_type,hid_t a_mem_type,
|
||||
unsigned int a_number,const T a_array[]) {
|
||||
@@ -443,6 +578,106 @@ inline bool read_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,un
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
template <class T>
|
||||
inline bool read_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,unsigned int& a_size,T*& a_array) {
|
||||
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
|
||||
if(dataset<0) {
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false; // data set not found.
|
||||
}
|
||||
|
||||
hid_t file_space = H5Dget_space(dataset);
|
||||
if(file_space<0) {
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
{int dimn = H5Sget_simple_extent_ndims(file_space);
|
||||
if(dimn<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
if(dimn!=1) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
//printf("debug : read dimn %d\n",dimn);
|
||||
}
|
||||
|
||||
hsize_t dims[1];
|
||||
{if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}}
|
||||
|
||||
unsigned int _size = (unsigned int)dims[0];
|
||||
if(_size!=1) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
|
||||
if(mem_space<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t mem_type = ::H5Tvlen_create(a_mem_type);
|
||||
|
||||
hvl_t rdata[1];
|
||||
if(H5Dread(dataset,mem_type,mem_space,file_space,H5P_DEFAULT,rdata)<0) {
|
||||
//::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata); ???
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hsize_t len = rdata[0].len;
|
||||
if(!len) {
|
||||
//a_array = new T[1];
|
||||
a_array = 0; //it is ok.
|
||||
} else {
|
||||
a_array = new T[len];
|
||||
T* _data = (T*)rdata[0].p;
|
||||
T* pos = a_array;
|
||||
for(hsize_t index=0;index<len;index++,pos++,_data++) *pos = *_data;
|
||||
}
|
||||
a_size = len;
|
||||
|
||||
::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata);
|
||||
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
template <class T>
|
||||
inline bool read_sub_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,
|
||||
unsigned int a_offset,unsigned int a_number,
|
||||
@@ -501,6 +736,14 @@ inline bool read_sub_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_typ
|
||||
// abcdef
|
||||
// 012345
|
||||
int remain = sz-a_offset;
|
||||
if(remain<=0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return a_number?false:true;
|
||||
}
|
||||
|
||||
int number = (int(a_number)<=remain) ? int(a_number) : remain;
|
||||
if(number<=0) {
|
||||
::H5Sclose(file_space);
|
||||
@@ -551,6 +794,130 @@ inline bool read_sub_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_typ
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,
|
||||
unsigned int a_offset,
|
||||
unsigned int& a_size,T*& a_array) {
|
||||
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
|
||||
if(dataset<0) {
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false; // data set not found.
|
||||
}
|
||||
|
||||
hid_t file_space = H5Dget_space(dataset);
|
||||
if(file_space<0) {
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
{int dimn = H5Sget_simple_extent_ndims(file_space);
|
||||
if(dimn<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
if(dimn!=1) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
//printf("debug : read dimn %d\n",dimn);
|
||||
}
|
||||
|
||||
hsize_t dims[1];
|
||||
{if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}}
|
||||
|
||||
unsigned int sz = (unsigned int)dims[0];
|
||||
if(!sz) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return true; //It is ok.
|
||||
}
|
||||
|
||||
// abcdef
|
||||
// 012345
|
||||
int remain = sz-a_offset;
|
||||
if(remain<=0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
{hsize_t offset[1];
|
||||
offset[0] = a_offset;
|
||||
hsize_t count[1];
|
||||
count[0] = 1;
|
||||
if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}}
|
||||
|
||||
dims[0] = 1;
|
||||
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
|
||||
if(mem_space<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t mem_type = ::H5Tvlen_create(a_mem_type);
|
||||
|
||||
hvl_t rdata[1];
|
||||
if(H5Dread(dataset,mem_type,mem_space,file_space,H5P_DEFAULT,rdata)<0) {
|
||||
//::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata); ???
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hsize_t len = rdata[0].len;
|
||||
if(!len) {
|
||||
//a_array = new T[1];
|
||||
a_array = 0; //it is ok.
|
||||
} else {
|
||||
a_array = new T[len];
|
||||
T* _data = (T*)rdata[0].p;
|
||||
T* pos = a_array;
|
||||
for(hsize_t index=0;index<len;index++,pos++,_data++) *pos = *_data;
|
||||
}
|
||||
a_size = len;
|
||||
|
||||
::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata);
|
||||
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
inline bool read_scalar(hid_t a_loc,const std::string& a_name,TYPE& aValue) {
|
||||
return read_scalar<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),aValue);
|
||||
@@ -576,7 +943,7 @@ inline bool read_std_vec_vec(hid_t a_loc,const std::string& a_name,hid_t a_mem_t
|
||||
a_vec_vec.resize((size_t)sz);
|
||||
std::string scount;
|
||||
for(size_t count=0;count<(size_t)sz;count++) {
|
||||
tools::num2s(count,scount);
|
||||
tools::num2s(tools::uint64(count),scount);
|
||||
if(!read_std_vec<TYPE>(a_loc,a_name+"_elem_"+scount,a_mem_type,a_vec_vec[count])) {a_vec_vec.clear();return false;}
|
||||
}
|
||||
return true;
|
||||
@@ -784,6 +1151,14 @@ inline bool write_array(hid_t a_loc,const std::string& a_name,
|
||||
a_chunked,a_compress,a_size,a_array);
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
inline bool write_vlen(hid_t a_loc,const std::string& a_name,
|
||||
unsigned int a_size,const TYPE a_array[],
|
||||
unsigned int a_chunked = 0,unsigned int a_compress = 0) {
|
||||
return hdf5::write_vlen<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),
|
||||
a_chunked,a_compress,a_size,a_array);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool write_std_vec(hid_t a_loc,const std::string& a_name,
|
||||
hid_t a_file_type,hid_t a_mem_type,
|
||||
@@ -805,7 +1180,7 @@ template <class TYPE>
|
||||
inline bool write_std_vec_vec(hid_t a_loc,const std::string& a_name,const std::vector< std::vector<TYPE> >& a_vec_vec,
|
||||
unsigned int /*a_chunked*/ = 0,unsigned int /*a_compress*/ = 0) {
|
||||
if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_vec_vec.size())) return false;
|
||||
size_t count = 0;
|
||||
unsigned int count = 0; //uint for num2s.
|
||||
std::string scount;
|
||||
tools_typename_vforcit(std::vector<TYPE>,a_vec_vec,it) {
|
||||
tools::num2s(count,scount);
|
||||
@@ -819,7 +1194,7 @@ inline bool write_std_vec_vec(hid_t a_loc,const std::string& a_name,const std::v
|
||||
//inline bool write_std_map(hid_t a_loc,const std::string& a_name,const std::map<TKEY,TVALUE>& a_map,
|
||||
// unsigned int a_chunked = 0,unsigned int a_compress = 0) {
|
||||
// if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_map.size())) return false;
|
||||
// size_t count = 0;
|
||||
// unsigned int count = 0; //uint for num2s.
|
||||
// std::string scount;
|
||||
// inlib_typename_mforcit(TKEY,TVALUE,a_map,it) {
|
||||
// tools::num2s(count,scount);
|
||||
@@ -844,6 +1219,11 @@ inline bool write_append_array_dataset(hid_t a_dataset,unsigned int a_number,con
|
||||
return hdf5::write_append_array_dataset<TYPE>(a_dataset,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
inline bool write_append_vlen_dataset(hid_t a_dataset,unsigned int a_number,const TYPE a_array[]) {
|
||||
return hdf5::write_append_vlen_dataset<TYPE>(a_dataset,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
inline bool write_append_array(hid_t a_loc,const std::string& a_name,unsigned int a_number,const TYPE a_array[]) {
|
||||
return hdf5::write_append_array<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
|
||||
@@ -854,6 +1234,11 @@ inline bool read_array(hid_t a_loc,const std::string& a_name,unsigned int& a_siz
|
||||
return read_array<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_size,a_array);
|
||||
}
|
||||
|
||||
//template <class TYPE>
|
||||
//inline bool read_vlen(hid_t a_loc,const std::string& a_name,unsigned int& a_size,TYPE*& a_array) {
|
||||
// return read_vlen<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_size,a_array);
|
||||
//}
|
||||
|
||||
template <class TYPE>
|
||||
inline bool read_std_vec(hid_t a_loc,const std::string& a_name,std::vector<TYPE>& a_vec) {
|
||||
return read_std_vec<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_vec);
|
||||
@@ -870,6 +1255,12 @@ inline bool read_sub_array(hid_t a_loc,const std::string& a_name,unsigned int a_
|
||||
return read_sub_array<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_offset,a_number,a_size,a_array);
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,unsigned int a_offset,
|
||||
unsigned int& a_size,TYPE*& a_array) {
|
||||
return read_sub_vlen<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_offset,a_size,a_array);
|
||||
}
|
||||
|
||||
inline bool read_bool(hid_t a_loc,const std::string& a_name,bool& aValue) {
|
||||
unsigned char value = 0;
|
||||
if(!read_scalar<unsigned char>(a_loc,a_name,H5T_NATIVE_UCHAR,value)) {
|
||||
@@ -901,13 +1292,13 @@ inline bool write_scalar_atb(hid_t aDS,const std::string& a_name,const TYPE& aDa
|
||||
hid_t scalar = ::H5Screate(H5S_SCALAR);
|
||||
if(scalar<0) return false;
|
||||
|
||||
hid_t aid = tools_H5Acreate(aDS,a_name.c_str(),H5T_STD_I32LE,scalar,H5P_DEFAULT);
|
||||
hid_t aid = tools_H5Acreate(aDS,a_name.c_str(),to_T_file_type(TYPE()),scalar,H5P_DEFAULT);
|
||||
if(aid<0) {
|
||||
::H5Sclose(scalar);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(H5Awrite(aid,H5T_NATIVE_INT,&aData)<0) {
|
||||
if(H5Awrite(aid,to_T_mem_type(TYPE()),&aData)<0) {
|
||||
::H5Sclose(scalar);
|
||||
::H5Aclose(aid);
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_hdf5_group_exists
|
||||
#define tools_hdf5_group_exists
|
||||
|
||||
#include "hdf5_h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace tools {
|
||||
namespace hdf5 {
|
||||
|
||||
class group_exists_struct {
|
||||
public:
|
||||
group_exists_struct(const std::string& a_what):m_what(a_what),m_found(false){}
|
||||
virtual ~group_exists_struct() {}
|
||||
protected:
|
||||
group_exists_struct(const group_exists_struct& a_from):m_what(a_from.m_what),m_found(a_from.m_found){}
|
||||
group_exists_struct& operator=(const group_exists_struct&){return *this;}
|
||||
public:
|
||||
std::string m_what;
|
||||
bool m_found;
|
||||
};
|
||||
|
||||
inline herr_t group_exists_visit(hid_t a_id,const char* a_name,void* a_tag){ //a_id = parent of a_name object.
|
||||
group_exists_struct* visitor = (group_exists_struct*)a_tag;
|
||||
H5G_stat_t statbuf;
|
||||
::H5Gget_objinfo(a_id,a_name,0,&statbuf);
|
||||
switch(statbuf.type) {
|
||||
case H5G_GROUP:{
|
||||
if(a_name==visitor->m_what) {visitor->m_found=true;return 0;} //found
|
||||
//::H5Giterate(a_id,a_name,NULL,group_exists_visit,visitor);
|
||||
}break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline bool group_exists(hid_t a_file_id,const std::string& a_name) {
|
||||
group_exists_struct visitor(a_name);
|
||||
::H5Giterate(a_file_id,".",NULL,group_exists_visit,&visitor);
|
||||
return visitor.m_found;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -24,7 +24,7 @@ namespace hdf5 {
|
||||
inline bool write_std_map_ss(hid_t a_loc,const std::string& a_name,const std::map<std::string,std::string>& a_map,
|
||||
unsigned int /*a_chunked*/ = 0,unsigned int /*a_compress*/ = 0) {
|
||||
if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_map.size())) return false;
|
||||
size_t count = 0;
|
||||
unsigned int count = 0; //uint for num2s.
|
||||
std::string scount;
|
||||
tools_mforcit(std::string,std::string,a_map,it) {
|
||||
tools::num2s(count,scount);
|
||||
@@ -205,9 +205,11 @@ inline bool read_hdata(hid_t a_loc,histo_data_t& a_hdata) {
|
||||
}
|
||||
|
||||
template <class HISTO>
|
||||
inline bool read_histo(std::ostream& a_out,hid_t a_loc,const std::string& a_name,HISTO*& a_histo) {
|
||||
inline bool read_histo(std::ostream& a_out,hid_t a_loc,const std::string& a_name,HISTO*& a_histo,bool a_verb_class = true) {
|
||||
a_histo = 0;
|
||||
|
||||
//if(::H5Gget_objinfo(a_loc,a_name.c_str(),0,NULL)<0) {return false;}
|
||||
|
||||
hid_t histo = tools_H5Gopen(a_loc,a_name.c_str());
|
||||
if(histo<0) {
|
||||
a_out << "tools::hdf5::read_histo : can't open group." << std::endl;
|
||||
@@ -222,7 +224,10 @@ inline bool read_histo(std::ostream& a_out,hid_t a_loc,const std::string& a_name
|
||||
}
|
||||
|
||||
if(sclass!=HISTO::s_class()) {
|
||||
a_out << "tools::hdf5::read_histo : unknown class : " << sclass << std::endl;
|
||||
if(a_verb_class) {
|
||||
a_out << "tools::hdf5::read_histo :"
|
||||
<< " read class " << tools::sout(sclass) << " not " << tools::sout(HISTO::s_class()) << std::endl;
|
||||
}
|
||||
::H5Gclose(histo);
|
||||
return false;
|
||||
}
|
||||
@@ -249,7 +254,7 @@ inline bool read_histo(std::ostream& a_out,hid_t a_loc,const std::string& a_name
|
||||
}
|
||||
|
||||
template <class PROFILE>
|
||||
inline bool read_profile(std::ostream& a_out,hid_t a_loc,const std::string& a_name,PROFILE*& a_histo) {
|
||||
inline bool read_profile(std::ostream& a_out,hid_t a_loc,const std::string& a_name,PROFILE*& a_histo,bool a_verb_class = true) {
|
||||
a_histo = 0;
|
||||
|
||||
hid_t histo = tools_H5Gopen(a_loc,a_name.c_str());
|
||||
@@ -266,7 +271,10 @@ inline bool read_profile(std::ostream& a_out,hid_t a_loc,const std::string& a_na
|
||||
}
|
||||
|
||||
if(sclass!=PROFILE::s_class()) {
|
||||
a_out << "tools::hdf5::read_profile : unknown class : " << sclass << std::endl;
|
||||
if(a_verb_class) {
|
||||
a_out << "tools::hdf5::read_profile :"
|
||||
<< " read class " << tools::sout(sclass) << " not " << tools::sout(PROFILE::s_class()) << std::endl;
|
||||
}
|
||||
::H5Gclose(histo);
|
||||
return false;
|
||||
}
|
||||
@@ -298,6 +306,36 @@ inline bool read_profile(std::ostream& a_out,hid_t a_loc,const std::string& a_na
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read_class_version(std::ostream& a_out,hid_t a_loc,const std::string& a_name,
|
||||
std::string& a_class,int& a_version,bool a_verbose = true) {
|
||||
hid_t id = tools_H5Gopen(a_loc,a_name.c_str());
|
||||
if(id<0) {
|
||||
if(a_verbose) a_out << "tools::hdf5::read_class_version : can't open group." << std::endl;
|
||||
a_class.clear();
|
||||
a_version = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!read_atb(id,"class",a_class)) {
|
||||
if(a_verbose) a_out << "tools::hdf5::read_class_version : can't read_atb() class." << std::endl;
|
||||
::H5Gclose(id);
|
||||
a_class.clear();
|
||||
a_version = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!read_atb(id,"version",a_version)) {
|
||||
if(a_verbose) a_out << "tools::hdf5::read_class_version : read_atb version failed." << std::endl;
|
||||
::H5Gclose(id);
|
||||
a_class.clear();
|
||||
a_version = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
::H5Gclose(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
||||
@@ -139,12 +139,15 @@ public:
|
||||
m_basket = new T[m_basket_size];
|
||||
if(m_write) {
|
||||
} else { //read.
|
||||
size_t n = tools::mn<size_t>((size_t)m_branch.entries(),m_basket_size);
|
||||
if(!m_branch.read_page<T>(n,m_basket)) {
|
||||
m_store.out() << "tools::hdf5::ntuple::column_ref:column_ref : read_page() failed." << std::endl;
|
||||
m_basket_pos = 0;
|
||||
m_basket_end = 0;
|
||||
return;
|
||||
tools::uint64 _entries = m_branch.entries();
|
||||
size_t n = tools::mn<size_t>((size_t)_entries,m_basket_size);
|
||||
if(_entries) {
|
||||
if(!m_branch.read_page<T>(n,m_basket)) {
|
||||
m_store.out() << "tools::hdf5::ntuple::column_ref:column_ref : read_page() failed." << std::endl;
|
||||
m_basket_pos = 0;
|
||||
m_basket_end = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_basket_pos = 0;
|
||||
m_basket_end = n;
|
||||
@@ -262,7 +265,93 @@ public:
|
||||
TOOLS_CLASS_STRING_VALUE(vector_ushort,vector<tools::ushort>)
|
||||
TOOLS_CLASS_STRING_VALUE(vector_uint32,vector<tools::uint32>)
|
||||
TOOLS_CLASS_STRING_VALUE(vector_uint64,vector<tools::uint64>)
|
||||
|
||||
|
||||
//
|
||||
#define TOOLS_HDF5_NTUPLE_VLEN
|
||||
//
|
||||
#define TOOLS_HDF5_NTUPLE_STRING
|
||||
|
||||
#ifdef TOOLS_HDF5_NTUPLE_VLEN
|
||||
template <class T>
|
||||
class std_vector_column_ref : public virtual icol {
|
||||
#ifdef TOOLS_MEM
|
||||
static const std::string& s_class() {
|
||||
static const std::string s_v("tools::hdf5::ntuple::std_vector_column_ref<"+tools::stype(T())+">");
|
||||
return s_v;
|
||||
}
|
||||
#endif
|
||||
public:
|
||||
static tools::cid id_class() {return tools::_cid_std_vector<T>()+10000;}
|
||||
virtual void* cast(tools::cid a_class) const {
|
||||
if(void* p = tools::cmp_cast<std_vector_column_ref>(this,a_class)) {return p;}
|
||||
else return 0;
|
||||
}
|
||||
virtual tools::cid id_cls() const {return id_class();}
|
||||
public: //icol
|
||||
virtual bool add() { //write.
|
||||
if(!m_write) return false;
|
||||
const T* _data = tools::vec_data(m_ref);
|
||||
return m_branch.write_vlen<T>(m_ref.size(),_data);
|
||||
}
|
||||
virtual bool fetch_entry() { //read.
|
||||
if(m_write) return false;
|
||||
size_t n;
|
||||
T* _data;
|
||||
if(!m_branch.read_vlen<T>(n,_data)) {
|
||||
m_store.out() << "tools::hdf5::ntuple::std_vector_column_ref:fetch_entry : read_page() failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_ref.resize(n);
|
||||
T* dpos = _data;
|
||||
T* pos = tools::vec_data(m_ref);
|
||||
for(size_t index=0;index<n;index++,pos++,dpos++) *pos = *dpos;
|
||||
delete [] _data;
|
||||
return true;
|
||||
}
|
||||
virtual void reset() {m_branch.reset_pos();}
|
||||
virtual const std::string& name() const {return m_name;}
|
||||
virtual bool set_basket_size(size_t) {return true;}
|
||||
public:
|
||||
std_vector_column_ref(store& a_store,pages& a_pages,bool a_write,const std::string& a_name,
|
||||
size_t /*a_basket_size*/,
|
||||
std::vector<T>& a_ref)
|
||||
:m_store(a_store)
|
||||
,m_branch(a_pages)
|
||||
,m_write(a_write)
|
||||
,m_name(a_name)
|
||||
,m_ref(a_ref)
|
||||
{
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
virtual ~std_vector_column_ref(){
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
protected:
|
||||
std_vector_column_ref(const std_vector_column_ref& a_from)
|
||||
:icol(a_from)
|
||||
,m_store(a_from.m_store)
|
||||
,m_branch(a_from.m_branch)
|
||||
,m_write(a_from.m_write)
|
||||
,m_name(a_from.m_name)
|
||||
,m_ref(a_from.m_ref)
|
||||
{}
|
||||
std_vector_column_ref& operator=(const std_vector_column_ref& a_from){
|
||||
if(&a_from==this) return *this;
|
||||
m_name = a_from.m_name;
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
store& m_store;
|
||||
pages& m_branch;
|
||||
bool m_write;
|
||||
std::string m_name;
|
||||
std::vector<T>& m_ref;
|
||||
};
|
||||
#else //!TOOLS_HDF5_NTUPLE_VLEN
|
||||
template <class T>
|
||||
class std_vector_column_ref : public column<unsigned int> {
|
||||
typedef column<unsigned int> parent;
|
||||
@@ -288,7 +377,7 @@ public:
|
||||
if(!m_write) return false;
|
||||
if(m_ref.size()) {
|
||||
const T* _data = tools::vec_data(m_ref);
|
||||
if(!m_data_pages.write_page<T>(m_ref.size(),(void*)_data)) return false;
|
||||
if(!m_data_pages.write_page<T>(m_ref.size(),_data)) return false;
|
||||
}
|
||||
if(!parent::fill((unsigned int)m_ref.size())) return false;
|
||||
if(!parent::add()) return false;
|
||||
@@ -351,7 +440,8 @@ public:
|
||||
std::vector<T>& m_ref;
|
||||
pages m_data_pages;
|
||||
};
|
||||
|
||||
#endif //TOOLS_HDF5_NTUPLE_VLEN
|
||||
|
||||
template <class T>
|
||||
class std_vector_column : public std_vector_column_ref<T> {
|
||||
typedef std_vector_column_ref<T> parent;
|
||||
@@ -392,6 +482,78 @@ public:
|
||||
std::vector<T> m_tmp;
|
||||
};
|
||||
|
||||
#ifdef TOOLS_HDF5_NTUPLE_STRING
|
||||
class column_string_ref : public virtual icol {
|
||||
#ifdef TOOLS_MEM
|
||||
TOOLS_SCLASS(tools::hdf5::ntuple::column_string_ref)
|
||||
#endif
|
||||
public:
|
||||
static tools::cid id_class() {
|
||||
static const std::string s_v;
|
||||
return tools::_cid(s_v)+10000;
|
||||
}
|
||||
virtual void* cast(tools::cid a_class) const {
|
||||
if(void* p = tools::cmp_cast<column_string_ref>(this,a_class)) {return p;}
|
||||
else return 0;
|
||||
}
|
||||
virtual tools::cid id_cls() const {return id_class();}
|
||||
public: //icol
|
||||
virtual bool add() { //write.
|
||||
if(!m_write) return false;
|
||||
return m_branch.write_string(m_ref);
|
||||
}
|
||||
virtual bool fetch_entry() { //read.
|
||||
if(m_write) return false;
|
||||
if(!m_branch.read_string(m_ref)) {
|
||||
m_store.out() << "tools::hdf5::ntuple::column_string_ref:fetch_entry : read_page() failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual void reset() {m_branch.reset_pos();}
|
||||
virtual const std::string& name() const {return m_name;}
|
||||
virtual bool set_basket_size(size_t) {return true;}
|
||||
public:
|
||||
column_string_ref(store& a_store,pages& a_pages,bool a_write,const std::string& a_name,
|
||||
size_t /*a_basket_size*/,
|
||||
std::string& a_ref)
|
||||
:m_store(a_store)
|
||||
,m_branch(a_pages)
|
||||
,m_write(a_write)
|
||||
,m_name(a_name)
|
||||
,m_ref(a_ref)
|
||||
{
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
virtual ~column_string_ref(){
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
protected:
|
||||
column_string_ref(const column_string_ref& a_from)
|
||||
:icol(a_from)
|
||||
,m_store(a_from.m_store)
|
||||
,m_branch(a_from.m_branch)
|
||||
,m_write(a_from.m_write)
|
||||
,m_name(a_from.m_name)
|
||||
,m_ref(a_from.m_ref)
|
||||
{}
|
||||
column_string_ref& operator=(const column_string_ref& a_from){
|
||||
if(&a_from==this) return *this;
|
||||
m_name = a_from.m_name;
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
store& m_store;
|
||||
pages& m_branch;
|
||||
bool m_write;
|
||||
std::string m_name;
|
||||
std::string& m_ref;
|
||||
};
|
||||
#else //!TOOLS_HDF5_NTUPLE_STRING
|
||||
class column_string_ref : public column<unsigned int> {
|
||||
typedef column<unsigned int> parent;
|
||||
#ifdef TOOLS_MEM
|
||||
@@ -416,7 +578,7 @@ public:
|
||||
if(!m_write) return false;
|
||||
if(m_ref.size()) {
|
||||
const char* _data = m_ref.c_str();
|
||||
if(!m_data_pages.write_page<char>(m_ref.size(),(void*)_data)) return false;
|
||||
if(!m_data_pages.write_page<char>(m_ref.size(),_data)) return false;
|
||||
}
|
||||
if(!parent::fill((unsigned int)m_ref.size())) return false;
|
||||
if(!parent::add()) return false;
|
||||
@@ -479,6 +641,7 @@ public:
|
||||
std::string& m_ref;
|
||||
pages m_data_pages;
|
||||
};
|
||||
#endif //TOOLS_HDF5_NTUPLE_STRING
|
||||
|
||||
class column_string : public column_string_ref {
|
||||
typedef column_string_ref parent;
|
||||
@@ -813,15 +976,17 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string& title() const {return m_title;}
|
||||
|
||||
const std::vector<icol*>& columns() const {return m_cols;}
|
||||
std::vector<icol*>& columns() {return m_cols;}
|
||||
|
||||
template <class T>
|
||||
column_ref<T>* create_column_ref(const std::string& a_name,size_t a_basket_size,T& a_user_var) {
|
||||
column_ref<T>* create_column_ref(const std::string& a_name,size_t a_basket_size,T& a_ref) {
|
||||
if(tools::find_named<icol>(m_cols,a_name)) return 0;
|
||||
pages* _pages = create_pages(a_name,tools::stype(T()));
|
||||
if(!_pages) return 0;
|
||||
column_ref<T>* col = new column_ref<T>(*this,*_pages,true,a_name,a_basket_size,a_user_var);
|
||||
column_ref<T>* col = new column_ref<T>(*this,*_pages,true,a_name,a_basket_size,a_ref);
|
||||
if(!col) return 0;
|
||||
m_cols.push_back(col);
|
||||
return col;
|
||||
@@ -849,12 +1014,12 @@ public:
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std_vector_column_ref<T>* create_std_column_ref(const std::string& a_name,size_t a_basket_size,std::vector<T>& a_user_vec) {
|
||||
std_vector_column_ref<T>* create_std_column_ref(const std::string& a_name,size_t a_basket_size,std::vector<T>& a_ref) {
|
||||
//NOTE : to optimize, we do not handle a default std::vector value logic.
|
||||
if(tools::find_named<icol>(m_cols,a_name)) return 0;
|
||||
pages* _pages = create_pages(a_name,"vector<"+tools::stype(T())+">");
|
||||
if(!_pages) return 0;
|
||||
std_vector_column_ref<T>* col = new std_vector_column_ref<T>(*this,*_pages,true,a_name,a_basket_size,a_user_vec);
|
||||
std_vector_column_ref<T>* col = new std_vector_column_ref<T>(*this,*_pages,true,a_name,a_basket_size,a_ref);
|
||||
if(!col) return 0;
|
||||
m_cols.push_back(col);
|
||||
return col;
|
||||
|
||||
@@ -102,9 +102,9 @@ public:
|
||||
void reset_pos() {m_pos = 0;}
|
||||
|
||||
template <class TYPE>
|
||||
bool write_page(size_t a_size,void* a_array) {
|
||||
bool write_page(size_t a_size,const TYPE* a_array) {
|
||||
if(!m_pos) {
|
||||
if(!write_array<TYPE>(m_group,s_pages(),a_size,(TYPE*)a_array,a_size,m_compress)) {
|
||||
if(!write_array<TYPE>(m_group,s_pages(),a_size,a_array,a_size?a_size:32,m_compress)) {
|
||||
m_out << "pages::write_page : write_array<TYPE>() failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -114,8 +114,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!write_append_array_dataset<TYPE>(m_dataset,a_size,(TYPE*)a_array)) {
|
||||
m_out << "pages::write_page : write_append_array<TYPE>() failed. Pos " << m_pos << std::endl;
|
||||
if(!write_append_array_dataset<TYPE>(m_dataset,a_size,a_array)) {
|
||||
m_out << "pages::write_page : write_append_array_dataset<TYPE>() failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
bool read_page(size_t a_size,void* a_array) {
|
||||
bool read_page(size_t a_size,TYPE* a_array) {
|
||||
//it is assumed that a_array can contain a_size*sizeof(TYPE) bytes.
|
||||
unsigned int _size = a_size;
|
||||
unsigned int n = 0;
|
||||
@@ -151,6 +151,91 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
bool write_vlen(size_t a_size,const TYPE* a_array) {
|
||||
if(!m_pos) {
|
||||
if(!hdf5::write_vlen<TYPE>(m_group,s_pages(),a_size,a_array,a_size?a_size:32,m_compress)) {
|
||||
m_out << "pages::write_vlen : write_vlen<TYPE>() failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_dataset = tools_H5Dopen(m_group,s_pages().c_str());
|
||||
if(m_dataset<0) {
|
||||
m_out << "pages::write_vlen : H5Dopen failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!write_append_vlen_dataset<TYPE>(m_dataset,a_size,a_array)) {
|
||||
m_out << "pages::write_vlen : write_append_vlen_dataset<TYPE>() failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_pos++;
|
||||
m_entries++;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
bool read_vlen(size_t& a_size,TYPE*& a_array) {
|
||||
//it is assumed that a_array can contain a_size*sizeof(TYPE) bytes.
|
||||
unsigned int sz;
|
||||
if(!read_sub_vlen<TYPE>(m_group,s_pages(),(unsigned int)m_pos,sz,a_array)) {
|
||||
m_out << "pages::read_vlen : read_sub_vlen<TYPE>() failed." << std::endl;
|
||||
a_size = 0;
|
||||
a_array = 0;
|
||||
return false;
|
||||
}
|
||||
a_size = sz;
|
||||
m_pos++;
|
||||
m_entries++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_string(const std::string& a_string) {
|
||||
if(!m_pos) {
|
||||
if(!hdf5::write_string_dataset(m_group,s_pages(),a_string,128,m_compress)) { //32=>enforce extendable.
|
||||
m_out << "pages::write_string : hdf5::write_string() failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_dataset = tools_H5Dopen(m_group,s_pages().c_str());
|
||||
if(m_dataset<0) {
|
||||
m_out << "pages::write_string : H5Dopen failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!write_append_string_dataset(m_dataset,a_string)) {
|
||||
m_out << "pages::write_string : write_append_string_dataset() failed. Pos " << m_pos << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_pos++;
|
||||
m_entries++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_string(std::string& a_string) {
|
||||
if(!read_sub_string(m_group,s_pages(),(unsigned int)m_pos,a_string)) {
|
||||
m_out << "pages::read_string : read_sub_string() failed." << std::endl;
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
m_pos++;
|
||||
m_entries++;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
bool write_string(const std::string& a_string) {return write_vlen<char>(a_string.size(),a_string.c_str());}
|
||||
|
||||
bool read_string(std::string& a_string) {
|
||||
size_t sz;char* _data;
|
||||
if(!read_vlen<char>(sz,_data)) {a_string.clear();return false;}
|
||||
a_string.resize(sz);
|
||||
for(size_t index=0;index<sz;index++) a_string[index] = _data[index];
|
||||
delete [] _data;
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
bool write_strings(size_t a_number,void* a_array) {
|
||||
size_t sz = m_size*a_number;
|
||||
@@ -191,7 +276,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_strings(size_t a_size,void* a_array) {
|
||||
bool read_strings(size_t a_size,char* a_array) {
|
||||
unsigned int _size = a_size*m_size;
|
||||
unsigned int n = 0;
|
||||
char* array = 0;
|
||||
|
||||
@@ -37,13 +37,19 @@ public:
|
||||
m_group = -1;
|
||||
return;
|
||||
}
|
||||
if(!write_atb(m_group,"type","object")) {
|
||||
m_out << "tools::hdf5::store::store : write_atb(type) failed." << std::endl;
|
||||
::H5Gclose(m_group);
|
||||
m_group = -1;
|
||||
return;
|
||||
}
|
||||
if(!write_atb(m_group,"class",s_class())) {
|
||||
m_out << "tools::hdf5::store::store : write_atb(class) failed." << std::endl;
|
||||
::H5Gclose(m_group);
|
||||
m_group = -1;
|
||||
return;
|
||||
}
|
||||
int v = 1;
|
||||
int v = 2; //1->2 add "type" atb.
|
||||
if(!write_scalar_atb<int>(m_group,"version",v)) {
|
||||
m_out << "tools::hdf5::store::store : write_scalar_atb(version) failed." << std::endl;
|
||||
::H5Gclose(m_group);
|
||||
@@ -99,29 +105,35 @@ public:
|
||||
if(!entries(_entries)) {
|
||||
m_out << "tools::hdf5::store::~store : not same entries on all columns. Write 0." << std::endl;
|
||||
}
|
||||
if(!write_scalar<tools::uint64>(m_group,s_entries(),_entries)) {
|
||||
m_out << "tools::hdf5::store::~store : write_scalar(entries) failed." << std::endl;
|
||||
if(m_group<0) { //constructor may have failed.
|
||||
} else {
|
||||
if(!write_scalar<tools::uint64>(m_group,s_entries(),_entries)) {
|
||||
m_out << "tools::hdf5::store::~store : write_scalar(entries) failed." << std::endl;
|
||||
}
|
||||
if(!write_scalar<unsigned int>(m_group,s_columns(),m_pagess.size())) {
|
||||
m_out << "tools::hdf5::store::~store : write_scalar(columns) failed." << std::endl;
|
||||
}
|
||||
{std::vector<std::string> names;
|
||||
tools_vforcit(pages*,m_pagess,it) names.push_back((*it)->name());
|
||||
//{m_out << "debug : write : names :" << std::endl;
|
||||
// tools_vforcit(std::string,names,it) m_out << *it << std::endl;}
|
||||
if(!write_array_string(m_group,s_names(),names)) {
|
||||
m_out << "tools::hdf5::store::~store : write_array_string(names) failed." << std::endl;
|
||||
}}
|
||||
{std::vector<std::string> TFORMs;
|
||||
tools_vforcit(pages*,m_pagess,it) TFORMs.push_back((*it)->form());
|
||||
//{m_out << "debug : write : TFORMs :" << std::endl;
|
||||
// tools_vforcit(std::string,TFORMs,it) m_out << *it << std::endl;}
|
||||
if(!write_array_string(m_group,s_forms(),TFORMs)) {
|
||||
m_out << "tools::hdf5::store::~store : write_array_string(tforms) failed." << std::endl;
|
||||
}}
|
||||
}
|
||||
if(!write_scalar<unsigned int>(m_group,s_columns(),m_pagess.size())) {
|
||||
m_out << "tools::hdf5::store::~store : write_scalar(columns) failed." << std::endl;
|
||||
}
|
||||
{std::vector<std::string> names;
|
||||
tools_vforcit(pages*,m_pagess,it) names.push_back((*it)->name());
|
||||
//{m_out << "debug : write : names :" << std::endl;
|
||||
// tools_vforcit(std::string,names,it) m_out << *it << std::endl;}
|
||||
if(!write_array_string(m_group,s_names(),names)) {
|
||||
m_out << "tools::hdf5::store::~store : write_array_string(names) failed." << std::endl;
|
||||
}}
|
||||
{std::vector<std::string> TFORMs;
|
||||
tools_vforcit(pages*,m_pagess,it) TFORMs.push_back((*it)->form());
|
||||
//{m_out << "debug : write : TFORMs :" << std::endl;
|
||||
// tools_vforcit(std::string,TFORMs,it) m_out << *it << std::endl;}
|
||||
if(!write_array_string(m_group,s_forms(),TFORMs)) {
|
||||
m_out << "tools::hdf5::store::~store : write_array_string(tforms) failed." << std::endl;
|
||||
}}
|
||||
}
|
||||
tools::safe_clear(m_pagess);
|
||||
::H5Gclose(m_group);
|
||||
if(m_group<0) { //constructor may have failed.
|
||||
} else {
|
||||
::H5Gclose(m_group);
|
||||
}
|
||||
#ifdef TOOLS_MEM
|
||||
tools::mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
|
||||
@@ -41,6 +41,20 @@ inline hid_t string_datatype(size_t aSize){
|
||||
return datatype;
|
||||
}
|
||||
|
||||
inline hid_t str_datatype() {
|
||||
hid_t datatype = ::H5Tcopy(H5T_C_S1);
|
||||
if(datatype<0) return failure();
|
||||
if(::H5Tset_size(datatype,H5T_VARIABLE)<0) {
|
||||
::H5Tclose(datatype);
|
||||
return failure();
|
||||
}
|
||||
if(::H5Tset_strpad(datatype,H5T_STR_NULLTERM)<0) {
|
||||
::H5Tclose(datatype);
|
||||
return failure();
|
||||
}
|
||||
return datatype;
|
||||
}
|
||||
|
||||
inline hid_t basic_mem_type(hid_t a_file_type){
|
||||
H5T_class_t mclass = H5Tget_class(a_file_type);
|
||||
size_t msize = H5Tget_size(a_file_type);
|
||||
@@ -98,8 +112,8 @@ inline hid_t compound_mem_type(hid_t a_file_type){
|
||||
size_t sz = H5Tget_size(a_file_type);
|
||||
//printf("debug : compound_mem_type : sz %lu\n",sz);
|
||||
|
||||
hid_t memtype = ::H5Tcreate(H5T_COMPOUND,sz);
|
||||
if(memtype<0) return failure();
|
||||
hid_t mem_type = ::H5Tcreate(H5T_COMPOUND,sz);
|
||||
if(mem_type<0) return failure();
|
||||
|
||||
//FIXME : WARNING : is order the booked order ?
|
||||
|
||||
@@ -116,21 +130,21 @@ inline hid_t compound_mem_type(hid_t a_file_type){
|
||||
if( (mclass==H5T_INTEGER) ||
|
||||
(mclass==H5T_STRING) ||
|
||||
(mclass==H5T_FLOAT) ) {
|
||||
hid_t mmemtype = basic_mem_type(mtype);
|
||||
if(mmemtype<0) {
|
||||
hid_t mmem_type = basic_mem_type(mtype);
|
||||
if(mmem_type<0) {
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
if(H5Tinsert(memtype,mname,moffset,mmemtype)<0) {
|
||||
::H5Tclose(mmemtype);
|
||||
if(H5Tinsert(mem_type,mname,moffset,mmem_type)<0) {
|
||||
::H5Tclose(mmem_type);
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
::H5Tclose(mmemtype);
|
||||
::H5Tclose(mmem_type);
|
||||
|
||||
} else if(mclass==H5T_ARRAY) {
|
||||
int dimn = ::H5Tget_array_ndims(mtype); //Should be 1;
|
||||
@@ -141,7 +155,7 @@ inline hid_t compound_mem_type(hid_t a_file_type){
|
||||
delete [] perms;
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
hid_t base_type = H5Tget_super(mtype);
|
||||
@@ -150,61 +164,61 @@ inline hid_t compound_mem_type(hid_t a_file_type){
|
||||
delete [] perms;
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
hid_t mmemtype = basic_mem_type(base_type);
|
||||
if(mmemtype<0) {
|
||||
hid_t mmem_type = basic_mem_type(base_type);
|
||||
if(mmem_type<0) {
|
||||
delete [] dims;
|
||||
delete [] perms;
|
||||
::H5Tclose(base_type);
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
::H5Tclose(base_type);
|
||||
hid_t array_type = tools_H5Tarray_create(mmemtype,dimn,dims,perms);
|
||||
hid_t array_type = tools_H5Tarray_create(mmem_type,dimn,dims,perms);
|
||||
delete [] dims;
|
||||
delete [] perms;
|
||||
if(array_type<0) {
|
||||
::H5Tclose(mmemtype);
|
||||
::H5Tclose(mmem_type);
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
::H5Tclose(mmemtype);
|
||||
::H5Tclose(mmem_type);
|
||||
|
||||
if(H5Tinsert(memtype,mname,moffset,array_type)<0) {
|
||||
if(H5Tinsert(mem_type,mname,moffset,array_type)<0) {
|
||||
::H5Tclose(array_type);
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
::H5Tclose(array_type);
|
||||
|
||||
} else if(mclass==H5T_COMPOUND) {
|
||||
hid_t mmemtype = compound_mem_type(mtype);
|
||||
if(memtype<0) {
|
||||
hid_t mmem_type = compound_mem_type(mtype);
|
||||
if(mem_type<0) {
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
if(H5Tinsert(memtype,mname,moffset,mmemtype)<0) {
|
||||
::H5Tclose(mmemtype);
|
||||
if(H5Tinsert(mem_type,mname,moffset,mmem_type)<0) {
|
||||
::H5Tclose(mmem_type);
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}
|
||||
::H5Tclose(mmemtype);
|
||||
::H5Tclose(mmem_type);
|
||||
} else {
|
||||
::H5Tclose(mtype);
|
||||
if(mname) ::free(mname);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
return failure();
|
||||
}}
|
||||
::H5Tclose(mtype);
|
||||
@@ -212,7 +226,7 @@ inline hid_t compound_mem_type(hid_t a_file_type){
|
||||
if(mname) ::free(mname);
|
||||
}
|
||||
|
||||
return memtype;
|
||||
return mem_type;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -223,28 +237,29 @@ inline hid_t compound_mem_type(hid_t a_file_type){
|
||||
namespace tools {
|
||||
namespace hdf5 {
|
||||
|
||||
inline bool read_atb(hid_t aID,const std::string& a_name,std::string& aData,unsigned int aSize = 100){
|
||||
inline bool read_atb(hid_t a_id,const std::string& a_name,std::string& a_data,unsigned int aSize = 100){
|
||||
// From H5LT.c/H5LTget_attribute_string.
|
||||
if(!H5LT_find_attribute(aID,a_name.c_str())) {aData.clear();return false;}
|
||||
if(!H5LT_find_attribute(a_id,a_name.c_str())) {a_data.clear();return false;}
|
||||
char* b = new char[aSize];
|
||||
if(H5LT_get_attribute_disk(aID,a_name.c_str(),b)<0) {
|
||||
if(H5LT_get_attribute_disk(a_id,a_name.c_str(),b)<0) {
|
||||
delete [] b;
|
||||
a_data.clear();
|
||||
return false;
|
||||
}
|
||||
aData = std::string(b);
|
||||
a_data = std::string(b);
|
||||
delete [] b;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read_atb(hid_t aID,const std::string& a_name,unsigned int& aData){
|
||||
if(!H5LT_find_attribute(aID,a_name.c_str())) {aData=0;return false;}
|
||||
if(H5LT_get_attribute_mem(aID,a_name.c_str(),H5T_NATIVE_UINT,&aData)<0) return false;
|
||||
inline bool read_atb(hid_t a_id,const std::string& a_name,unsigned int& a_data){
|
||||
if(!H5LT_find_attribute(a_id,a_name.c_str())) {a_data=0;return false;}
|
||||
if(H5LT_get_attribute_mem(a_id,a_name.c_str(),H5T_NATIVE_UINT,&a_data)<0) {a_data=0;return false;}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read_atb(hid_t aID,const std::string& a_name,int& aData){
|
||||
if(!H5LT_find_attribute(aID,a_name.c_str())) {aData=0;return false;}
|
||||
if(H5LT_get_attribute_mem(aID,a_name.c_str(),H5T_NATIVE_INT,&aData)<0) return false;
|
||||
inline bool read_atb(hid_t a_id,const std::string& a_name,int& a_data){
|
||||
if(!H5LT_find_attribute(a_id,a_name.c_str())) {a_data=0;return false;}
|
||||
if(H5LT_get_attribute_mem(a_id,a_name.c_str(),H5T_NATIVE_INT,&a_data)<0) {a_data=0;return false;}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -302,14 +317,14 @@ inline bool dataset_vec_size(hid_t a_loc,const std::string& a_name,hsize_t& a_si
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write_atb(hid_t aDS,const std::string& a_name,const std::string& aData){
|
||||
inline bool write_atb(hid_t a_id,const std::string& a_name,const std::string& a_data){
|
||||
// From H5LT.c/H5LTset_attribute_string.
|
||||
int has_attr = H5LT_find_attribute(aDS,a_name.c_str());
|
||||
int has_attr = H5LT_find_attribute(a_id,a_name.c_str());
|
||||
if(has_attr==1) {
|
||||
if(H5Adelete(aDS,a_name.c_str())<0) return false;
|
||||
if(H5Adelete(a_id,a_name.c_str())<0) return false;
|
||||
}
|
||||
|
||||
hid_t datatype = string_datatype(aData.size()+1);
|
||||
hid_t datatype = string_datatype(a_data.size()+1);
|
||||
if(datatype<0) return false;
|
||||
|
||||
hid_t scalar = ::H5Screate(H5S_SCALAR);
|
||||
@@ -318,14 +333,14 @@ inline bool write_atb(hid_t aDS,const std::string& a_name,const std::string& aDa
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t aid = tools_H5Acreate(aDS,a_name.c_str(),datatype,scalar,H5P_DEFAULT);
|
||||
hid_t aid = tools_H5Acreate(a_id,a_name.c_str(),datatype,scalar,H5P_DEFAULT);
|
||||
if(aid<0) {
|
||||
::H5Sclose(scalar);
|
||||
::H5Tclose(datatype);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(H5Awrite(aid,datatype,aData.c_str())<0) {
|
||||
if(H5Awrite(aid,datatype,a_data.c_str())<0) {
|
||||
::H5Aclose(aid);
|
||||
::H5Sclose(scalar);
|
||||
::H5Tclose(datatype);
|
||||
@@ -339,7 +354,7 @@ inline bool write_atb(hid_t aDS,const std::string& a_name,const std::string& aDa
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write_bool(hid_t a_loc,const std::string& a_name,bool aData) {
|
||||
inline bool write_bool(hid_t a_loc,const std::string& a_name,bool a_data) {
|
||||
hid_t scalar = ::H5Screate(H5S_SCALAR);
|
||||
if(scalar<0) return false;
|
||||
|
||||
@@ -361,7 +376,7 @@ inline bool write_bool(hid_t a_loc,const std::string& a_name,bool aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char data = aData?1:0;
|
||||
unsigned char data = a_data?1:0;
|
||||
if(::H5Dwrite(dataset,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,&data)<0) {
|
||||
::H5Pclose(compact);
|
||||
::H5Sclose(scalar);
|
||||
@@ -375,7 +390,7 @@ inline bool write_bool(hid_t a_loc,const std::string& a_name,bool aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write_string(hid_t a_loc,const std::string& a_name,const std::string& aString) {
|
||||
inline bool write_string(hid_t a_loc,const std::string& a_name,const std::string& a_string) {
|
||||
hid_t scalar = ::H5Screate(H5S_SCALAR);
|
||||
if(scalar<0) return false;
|
||||
|
||||
@@ -392,34 +407,180 @@ inline bool write_string(hid_t a_loc,const std::string& a_name,const std::string
|
||||
}
|
||||
|
||||
// From H5LTmakge_dataset_string.
|
||||
hid_t filetype = string_datatype(aString.size()+1);
|
||||
if(filetype<0) {
|
||||
hid_t file_type = string_datatype(a_string.size()+1);
|
||||
if(file_type<0) {
|
||||
::H5Pclose(compact);
|
||||
::H5Sclose(scalar);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),filetype,scalar,compact);
|
||||
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,scalar,compact);
|
||||
if(dataset<0) {
|
||||
::H5Pclose(compact);
|
||||
::H5Sclose(scalar);
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t memtype = filetype;
|
||||
if(H5Dwrite(dataset,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,aString.c_str())<0) {
|
||||
hid_t mem_type = file_type;
|
||||
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_string.c_str())<0) {
|
||||
::H5Pclose(compact);
|
||||
::H5Sclose(scalar);
|
||||
::H5Dclose(dataset);
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
return false;
|
||||
}
|
||||
|
||||
::H5Pclose(compact);
|
||||
::H5Sclose(scalar);
|
||||
::H5Dclose(dataset);
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write_string_dataset(hid_t a_loc,const std::string& a_name,
|
||||
unsigned int a_chunked,unsigned int a_compress,
|
||||
const std::string& a_string) {
|
||||
hid_t cpt = -1;
|
||||
if(a_compress || a_chunked) {
|
||||
cpt = ::H5Pcreate(H5P_DATASET_CREATE);
|
||||
if(cpt<0) return false;
|
||||
if(a_chunked) {
|
||||
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
hsize_t cdims[1];
|
||||
cdims[0] = a_chunked;
|
||||
if(H5Pset_chunk(cpt,1,cdims)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(a_compress) {
|
||||
if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
|
||||
::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cpt = H5P_DEFAULT;
|
||||
}
|
||||
|
||||
hid_t file_type = str_datatype(); //first input => H5T_VARIABLE.
|
||||
if(file_type<0) {
|
||||
if(cpt>=0) ::H5Pclose(cpt);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t file_space = -1;
|
||||
{hsize_t dims[1];
|
||||
dims[0] = 1;
|
||||
if(a_chunked) {
|
||||
hsize_t mx_dims[1];
|
||||
mx_dims[0] = H5S_UNLIMITED; //extendable.
|
||||
file_space = ::H5Screate_simple(1,dims,mx_dims);
|
||||
} else {
|
||||
file_space = ::H5Screate_simple(1,dims,NULL);
|
||||
}
|
||||
if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);::H5Tclose(file_type);return false;}}
|
||||
|
||||
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,file_space,cpt);
|
||||
if(cpt>=0) ::H5Pclose(cpt);
|
||||
::H5Sclose(file_space);
|
||||
if(dataset<0) {
|
||||
::H5Tclose(file_type);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t mem_type = file_type;
|
||||
|
||||
const char* wdata[1];
|
||||
wdata[0] = a_string.c_str();
|
||||
|
||||
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) {
|
||||
::H5Dclose(dataset);
|
||||
::H5Tclose(file_type);
|
||||
return false;
|
||||
}
|
||||
|
||||
::H5Tclose(file_type);
|
||||
::H5Dclose(dataset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write_string_dataset(hid_t a_loc,const std::string& a_name,
|
||||
const std::string& a_string,
|
||||
unsigned int a_chunked = 0,unsigned int a_compress = 0) {
|
||||
return hdf5::write_string_dataset(a_loc,a_name,a_chunked,a_compress,a_string);
|
||||
}
|
||||
|
||||
inline bool write_append_string_dataset(hid_t a_dataset,const std::string& a_string) {
|
||||
hsize_t old_size = 0;
|
||||
|
||||
{hid_t dataspace = H5Dget_space(a_dataset);
|
||||
if(dataspace<0) return false;
|
||||
hsize_t dims[1];
|
||||
if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
|
||||
::H5Sclose(dataspace);
|
||||
return false;
|
||||
}
|
||||
old_size = dims[0];
|
||||
::H5Sclose(dataspace);}
|
||||
|
||||
{hsize_t exts[1];
|
||||
exts[0] = old_size+1;
|
||||
// if(H5Dextend(dataset,exts)<0) {
|
||||
if(H5Dset_extent(a_dataset,exts)<0) return false;}
|
||||
|
||||
hid_t file_space = H5Dget_space(a_dataset);
|
||||
if(file_space<0) return false;
|
||||
|
||||
{hsize_t offset[1];
|
||||
offset[0] = old_size;
|
||||
hsize_t count[1];
|
||||
count[0] = 1;
|
||||
if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
|
||||
::H5Sclose(file_space);
|
||||
return false;
|
||||
}}
|
||||
|
||||
hsize_t dims[1];
|
||||
dims[0] = 1;
|
||||
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
|
||||
if(mem_space<0) {
|
||||
::H5Sclose(file_space);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t mem_type = str_datatype();
|
||||
if(mem_type<0) {
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* wdata[1];
|
||||
wdata[0] = a_string.c_str();
|
||||
|
||||
if(H5Dwrite(a_dataset,mem_type,mem_space,file_space,H5P_DEFAULT,wdata)<0) {
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
return false;
|
||||
}
|
||||
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -442,26 +603,26 @@ inline bool write_array_string(hid_t a_loc,const std::string& a_name,const std::
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t filetype = string_datatype(sz);
|
||||
if(filetype<0) {
|
||||
hid_t file_type = string_datatype(sz);
|
||||
if(file_type<0) {
|
||||
delete [] buffer;
|
||||
::H5Sclose(scalar);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),filetype,scalar,H5P_DEFAULT);
|
||||
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,scalar,H5P_DEFAULT);
|
||||
if(dataset<0) {
|
||||
delete [] buffer;
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
::H5Sclose(scalar);
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t memtype = filetype;
|
||||
if(H5Dwrite(dataset,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,buffer)<0) {
|
||||
hid_t mem_type = file_type;
|
||||
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,buffer)<0) {
|
||||
delete [] buffer;
|
||||
::H5Dclose(dataset);
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
::H5Sclose(scalar);
|
||||
return false;
|
||||
}
|
||||
@@ -469,12 +630,12 @@ inline bool write_array_string(hid_t a_loc,const std::string& a_name,const std::
|
||||
delete [] buffer;
|
||||
|
||||
::H5Dclose(dataset);
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
::H5Sclose(scalar);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type,char* aData) {
|
||||
inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type,char* a_data) {
|
||||
unsigned int chunked = 0;
|
||||
unsigned int compress = 0;
|
||||
|
||||
@@ -532,7 +693,7 @@ inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type
|
||||
return false;
|
||||
}
|
||||
|
||||
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,aData)<0) {
|
||||
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_data)<0) {
|
||||
::H5Dclose(dataset);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(simple);
|
||||
@@ -548,148 +709,286 @@ inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read_string(hid_t a_loc,const std::string& a_name,std::string& aString) {
|
||||
inline bool read_string(hid_t a_loc,const std::string& a_name,std::string& a_string) {
|
||||
// From H5LTread_dataset_string.
|
||||
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
|
||||
if(dataset<0) {
|
||||
aString.clear();
|
||||
a_string.clear();
|
||||
return false; // data set not found.
|
||||
}
|
||||
|
||||
hid_t filetype = H5Dget_type(dataset);
|
||||
if(filetype<0) {
|
||||
hid_t file_type = H5Dget_type(dataset);
|
||||
if(file_type<0) {
|
||||
::H5Dclose(dataset);
|
||||
aString.clear();
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
H5T_class_t t_class = H5Tget_class(filetype);
|
||||
H5T_class_t t_class = H5Tget_class(file_type);
|
||||
if(t_class!=H5T_STRING) {
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
::H5Dclose(dataset);
|
||||
aString.clear();
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t sz = H5Tget_size(filetype);
|
||||
::H5Tclose(filetype);
|
||||
size_t sz = H5Tget_size(file_type);
|
||||
::H5Tclose(file_type);
|
||||
if(!sz) {
|
||||
::H5Dclose(dataset);
|
||||
aString.clear();
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
// We could have use filetype since, for string,
|
||||
// We could have use file_type since, for string,
|
||||
// file type is the same than memory type.
|
||||
hid_t memtype = string_datatype(sz);
|
||||
if(memtype<0) {
|
||||
hid_t mem_type = string_datatype(sz);
|
||||
if(mem_type<0) {
|
||||
::H5Dclose(dataset);
|
||||
aString.clear();
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
char* buff = new char[sz];
|
||||
herr_t stat = H5Dread(dataset,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,buff);
|
||||
::H5Tclose(memtype);
|
||||
herr_t stat = H5Dread(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,buff);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
if(stat<0) {
|
||||
delete [] buff;
|
||||
aString.clear();
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t len = sz-1;
|
||||
aString.resize(len,0);
|
||||
for(size_t index=0;index<len;index++) aString[index] = buff[index];
|
||||
a_string.resize(len,0);
|
||||
for(size_t index=0;index<len;index++) a_string[index] = buff[index];
|
||||
|
||||
delete [] buff;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,char*& aData) {
|
||||
inline bool read_sub_string(hid_t a_loc,const std::string& a_name,unsigned int a_offset,std::string& a_string) {
|
||||
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
|
||||
if(dataset<0) {
|
||||
a_string.clear();
|
||||
return false; // data set not found.
|
||||
}
|
||||
|
||||
hid_t file_space = H5Dget_space(dataset);
|
||||
if(file_space<0) {
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
{int dimn = H5Sget_simple_extent_ndims(file_space);
|
||||
if(dimn<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
if(dimn!=1) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}}
|
||||
|
||||
hsize_t dims[1];
|
||||
{if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}}
|
||||
|
||||
{unsigned int sz = (unsigned int)dims[0];
|
||||
if(!sz) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false; //Is it ok ?
|
||||
}
|
||||
|
||||
// abcdef
|
||||
// 012345
|
||||
int remain = sz-a_offset;
|
||||
if(remain<=0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}}
|
||||
|
||||
{hsize_t offset[1];
|
||||
offset[0] = a_offset;
|
||||
hsize_t count[1];
|
||||
count[0] = 1;
|
||||
if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}}
|
||||
|
||||
dims[0] = 1;
|
||||
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
|
||||
if(mem_space<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t file_type = H5Dget_type(dataset);
|
||||
if(file_type<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
H5T_class_t t_class = H5Tget_class(file_type);
|
||||
if(t_class!=H5T_STRING) {
|
||||
::H5Tclose(file_type);
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
//size_t sz = H5Tget_size(file_type); //it gives the largest string size in the dataset.
|
||||
//if(!sz) {
|
||||
// ::H5Tclose(file_type);
|
||||
// ::H5Sclose(file_space);
|
||||
// ::H5Dclose(dataset);
|
||||
// a_string.clear();
|
||||
// return false;
|
||||
//}
|
||||
|
||||
::H5Tclose(file_type);
|
||||
|
||||
hid_t mem_type = str_datatype();
|
||||
if(mem_type<0) {
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
char* rdata[1];
|
||||
herr_t stat = H5Dread(dataset,mem_type,mem_space,file_space,H5P_DEFAULT,rdata);
|
||||
if(stat<0) {
|
||||
::H5Dvlen_reclaim(mem_type,mem_space, H5P_DEFAULT,rdata);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
a_string.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
char* buff = rdata[0];
|
||||
|
||||
size_t len = ::strlen(buff);
|
||||
a_string.resize(len,0);
|
||||
for(size_t index=0;index<len;index++) a_string[index] = buff[index];
|
||||
|
||||
::H5Dvlen_reclaim(mem_type,mem_space, H5P_DEFAULT,rdata);
|
||||
|
||||
::H5Tclose(mem_type);
|
||||
::H5Sclose(mem_space);
|
||||
::H5Sclose(file_space);
|
||||
::H5Dclose(dataset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,char*& a_data) {
|
||||
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
|
||||
if(dataset<0) {
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t filetype = H5Dget_type(dataset);
|
||||
if(filetype<0) {
|
||||
hid_t file_type = H5Dget_type(dataset);
|
||||
if(file_type<0) {
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
H5T_class_t t_class = H5Tget_class(filetype);
|
||||
H5T_class_t t_class = H5Tget_class(file_type);
|
||||
if(t_class!=H5T_COMPOUND) {
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t sz = H5Tget_size(filetype);
|
||||
size_t sz = H5Tget_size(file_type);
|
||||
if(!sz) {
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t memtype = compound_mem_type(filetype);
|
||||
if(memtype<0) {
|
||||
::H5Tclose(filetype);
|
||||
hid_t mem_type = compound_mem_type(file_type);
|
||||
if(mem_type<0) {
|
||||
::H5Tclose(file_type);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
|
||||
hid_t dataspace = H5Dget_space(dataset);
|
||||
if(dataspace<0) {
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
hid_t scalar = ::H5Screate(H5S_SCALAR);
|
||||
if(scalar<0) {
|
||||
::H5Sclose(dataspace);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
char* buffer = new char[sz];
|
||||
if(H5Dread(dataset,memtype,scalar,dataspace,H5P_DEFAULT,buffer)<0) {
|
||||
if(H5Dread(dataset,mem_type,scalar,dataspace,H5P_DEFAULT,buffer)<0) {
|
||||
delete [] buffer;
|
||||
::H5Sclose(scalar);
|
||||
::H5Sclose(dataspace);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
a_size = 0;
|
||||
aData = 0;
|
||||
a_data = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
::H5Sclose(scalar);
|
||||
::H5Sclose(dataspace);
|
||||
::H5Tclose(memtype);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
|
||||
a_size = sz;
|
||||
aData = buffer;
|
||||
a_data = buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -698,37 +997,37 @@ inline bool read_array_string(hid_t a_loc,const std::string& a_name,std::vector<
|
||||
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
|
||||
if(dataset<0) return false;
|
||||
|
||||
hid_t filetype = H5Dget_type(dataset);
|
||||
if(filetype<0) {
|
||||
hid_t file_type = H5Dget_type(dataset);
|
||||
if(file_type<0) {
|
||||
::H5Dclose(dataset);
|
||||
return false;
|
||||
}
|
||||
|
||||
H5T_class_t t_class = H5Tget_class(filetype);
|
||||
H5T_class_t t_class = H5Tget_class(file_type);
|
||||
if(t_class!=H5T_STRING) {
|
||||
::H5Tclose(filetype);
|
||||
::H5Tclose(file_type);
|
||||
::H5Dclose(dataset);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t sz = H5Tget_size(filetype);
|
||||
::H5Tclose(filetype);
|
||||
size_t sz = H5Tget_size(file_type);
|
||||
::H5Tclose(file_type);
|
||||
if(!sz) {
|
||||
::H5Dclose(dataset);
|
||||
return false;
|
||||
}
|
||||
|
||||
// We could have use filetype since, for string,
|
||||
// We could have use file_type since, for string,
|
||||
// file type is the same than memory type.
|
||||
hid_t memtype = string_datatype(sz);
|
||||
if(memtype<0) {
|
||||
hid_t mem_type = string_datatype(sz);
|
||||
if(mem_type<0) {
|
||||
::H5Dclose(dataset);
|
||||
return false;
|
||||
}
|
||||
|
||||
char* buffer = new char[sz];
|
||||
herr_t stat = H5Dread(dataset,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,buffer);
|
||||
::H5Tclose(memtype);
|
||||
herr_t stat = H5Dread(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,buffer);
|
||||
::H5Tclose(mem_type);
|
||||
::H5Dclose(dataset);
|
||||
if(stat<0) {
|
||||
delete [] buffer;
|
||||
|
||||
@@ -31,8 +31,7 @@ public:
|
||||
int& a_number,int* a_mx_point,
|
||||
float* aX,float* aY,float& a_width){
|
||||
// PAW special characters.
|
||||
extract(H_SPECIAL,
|
||||
H_UPPER,a_char,a_scale,a_number,a_mx_point,aX,aY,a_width);
|
||||
extract(H_SPECIAL,H_UPPER,a_char,a_scale,a_number,a_mx_point,aX,aY,a_width);
|
||||
}
|
||||
|
||||
static void latin_char_points(char a_char,float a_scale, //input
|
||||
|
||||
@@ -28,83 +28,83 @@ public:
|
||||
bn_t bins() const {return m_number_of_bins;}
|
||||
const std::vector<TC>& edges() const {return m_edges;}
|
||||
|
||||
TC bin_width(int aBin) const {
|
||||
if(aBin==UNDERFLOW_BIN) {
|
||||
TC bin_width(int a_bin) const {
|
||||
if(a_bin==UNDERFLOW_BIN) {
|
||||
return 0; //FIXME return DBL_MAX;
|
||||
} else if(aBin==OVERFLOW_BIN) {
|
||||
} else if(a_bin==OVERFLOW_BIN) {
|
||||
return 0; //FIXME return DBL_MAX;
|
||||
} else if((aBin<0) ||(aBin>=(int)m_number_of_bins)) {
|
||||
} else if((a_bin<0) ||(a_bin>=(int)m_number_of_bins)) {
|
||||
return 0;
|
||||
} else {
|
||||
if(m_fixed) {
|
||||
return m_bin_width;
|
||||
} else {
|
||||
return (m_edges[aBin+1]-m_edges[aBin]);
|
||||
return (m_edges[a_bin+1]-m_edges[a_bin]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TC bin_lower_edge(int aBin) const {
|
||||
if(aBin==UNDERFLOW_BIN) {
|
||||
TC bin_lower_edge(int a_bin) const {
|
||||
if(a_bin==UNDERFLOW_BIN) {
|
||||
return 0; //FIXME return -DBL_MAX;
|
||||
} else if(aBin==OVERFLOW_BIN) {
|
||||
} else if(a_bin==OVERFLOW_BIN) {
|
||||
return 0; //FIXME return bin_upper_edge(m_number_of_bins-1);
|
||||
} else if((aBin<0) ||(aBin>=(int)m_number_of_bins)) {
|
||||
} else if((a_bin<0) ||(a_bin>=(int)m_number_of_bins)) {
|
||||
return 0;
|
||||
} else {
|
||||
if(m_fixed) {
|
||||
return (m_minimum_value + aBin * m_bin_width);
|
||||
return (m_minimum_value + a_bin * m_bin_width);
|
||||
} else {
|
||||
return m_edges[aBin];
|
||||
return m_edges[a_bin];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TC bin_upper_edge(int aBin) const {
|
||||
if(aBin==UNDERFLOW_BIN) {
|
||||
TC bin_upper_edge(int a_bin) const {
|
||||
if(a_bin==UNDERFLOW_BIN) {
|
||||
return 0; //FIXME bin_lower_edge(0)
|
||||
} else if(aBin==OVERFLOW_BIN) {
|
||||
} else if(a_bin==OVERFLOW_BIN) {
|
||||
return 0; //FIXME return DBL_MAX;
|
||||
} else if((aBin<0) ||(aBin>=(int)m_number_of_bins)) {
|
||||
} else if((a_bin<0) ||(a_bin>=(int)m_number_of_bins)) {
|
||||
return 0;
|
||||
} else {
|
||||
if(m_fixed) {
|
||||
return (m_minimum_value + (aBin + 1) * m_bin_width);
|
||||
return (m_minimum_value + (a_bin + 1) * m_bin_width);
|
||||
} else {
|
||||
return m_edges[aBin+1];
|
||||
return m_edges[a_bin+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TC bin_center(int aBin) const {
|
||||
if(aBin==UNDERFLOW_BIN) {
|
||||
TC bin_center(int a_bin) const {
|
||||
if(a_bin==UNDERFLOW_BIN) {
|
||||
return 0; //FIXME : -INF
|
||||
} else if(aBin==OVERFLOW_BIN) {
|
||||
} else if(a_bin==OVERFLOW_BIN) {
|
||||
return 0; //FIXME : +INF
|
||||
} else if(aBin<0) {
|
||||
} else if(a_bin<0) {
|
||||
return 0; //FIXME : -INF
|
||||
} else if(aBin>=(int)m_number_of_bins) {
|
||||
} else if(a_bin>=(int)m_number_of_bins) {
|
||||
return 0; //FIXME : +INF
|
||||
} else {
|
||||
if(m_fixed) {
|
||||
return (m_minimum_value + (aBin + 0.5) * m_bin_width);
|
||||
return (m_minimum_value + (a_bin + 0.5) * m_bin_width);
|
||||
} else {
|
||||
return (m_edges[aBin] + m_edges[aBin+1])/2.;
|
||||
return (m_edges[a_bin] + m_edges[a_bin+1])/2.;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int coord_to_index(TC aValue) const {
|
||||
if( aValue < m_minimum_value) {
|
||||
int coord_to_index(TC a_value) const {
|
||||
if( a_value < m_minimum_value) {
|
||||
return UNDERFLOW_BIN;
|
||||
} else if( aValue >= m_maximum_value) {
|
||||
} else if( a_value >= m_maximum_value) {
|
||||
return OVERFLOW_BIN;
|
||||
} else {
|
||||
if(m_fixed) {
|
||||
return (int)((aValue - m_minimum_value)/m_bin_width);
|
||||
return (int)((a_value - m_minimum_value)/m_bin_width);
|
||||
} else {
|
||||
for(bn_t index=0;index<m_number_of_bins;index++) {
|
||||
if((m_edges[index]<=aValue)&&(aValue<m_edges[index+1])) {
|
||||
if((m_edges[index]<=a_value)&&(a_value<m_edges[index+1])) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
@@ -114,20 +114,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool coord_to_absolute_index(TC aValue,bn_t& a_index) const {
|
||||
if( aValue < m_minimum_value) {
|
||||
bool coord_to_absolute_index(TC a_value,bn_t& a_index) const {
|
||||
if( a_value < m_minimum_value) {
|
||||
a_index = 0;
|
||||
return true;
|
||||
} else if( aValue >= m_maximum_value) {
|
||||
} else if( a_value >= m_maximum_value) {
|
||||
a_index = m_number_of_bins+1;
|
||||
return true;
|
||||
} else {
|
||||
if(m_fixed) {
|
||||
a_index = (bn_t)((aValue - m_minimum_value)/m_bin_width)+1;
|
||||
a_index = (bn_t)((a_value - m_minimum_value)/m_bin_width)+1;
|
||||
return true;
|
||||
} else {
|
||||
for(bn_t index=0;index<m_number_of_bins;index++) {
|
||||
if((m_edges[index]<=aValue)&&(aValue<m_edges[index+1])) {
|
||||
if((m_edges[index]<=a_value)&&(a_value<m_edges[index+1])) {
|
||||
a_index = index+1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -207,6 +207,25 @@ public: //histo_data
|
||||
TW get_in_range_Sw() const {return parent::m_in_range_Sw;} //for CERN-ROOT file writing.
|
||||
TW get_in_range_Sw2() const {return parent::m_in_range_Sw2;} //for CERN-ROOT file writing.
|
||||
|
||||
void get_Sw_Sw2(TW& a_sw,TW& a_sw2) const {
|
||||
a_sw = 0;
|
||||
a_sw2 = 0;
|
||||
for(TO ibin=0;ibin<parent::m_bin_number;ibin++) {
|
||||
if(!histo::is_out(parent::m_axes,ibin)) {
|
||||
a_sw += parent::m_bin_Sw[ibin];
|
||||
a_sw2 += parent::m_bin_Sw2[ibin];
|
||||
}
|
||||
}
|
||||
}
|
||||
void get_all_Sw_Sw2(TW& a_sw,TW& a_sw2) const {
|
||||
a_sw = 0;
|
||||
a_sw2 = 0;
|
||||
for(TO ibin=0;ibin<parent::m_bin_number;ibin++) {
|
||||
a_sw += parent::m_bin_Sw[ibin];
|
||||
a_sw2 += parent::m_bin_Sw2[ibin];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
TW get_all_Sw() const {
|
||||
TW sw = 0;
|
||||
@@ -377,7 +396,7 @@ public:
|
||||
const std::vector<TC>& in_range_planes_xyw() const {return parent::m_in_range_plane_Sxyw;}
|
||||
|
||||
public:
|
||||
const axis_t& get_axis(int aIndex) const {return parent::m_axes[aIndex];}
|
||||
const axis_t& get_axis(int a_index) const {return parent::m_axes[a_index];}
|
||||
offset_t get_bins() const {return parent::m_bin_number;}
|
||||
const std::string& get_title() const {return parent::m_title;}
|
||||
dim_t get_dimension() const {return parent::m_dimension;}
|
||||
|
||||
@@ -104,8 +104,8 @@ public:
|
||||
double upper_edge() const {
|
||||
return (m_histo ? m_histo->axis().upper_edge() : m_upper_x);
|
||||
}
|
||||
double value(unsigned int aIndex) const {return (m_histo ?0:m_xs[aIndex]);}
|
||||
double weight(unsigned int aIndex) const {return (m_histo ?0:m_ws[aIndex]);}
|
||||
double value(unsigned int a_index) const {return (m_histo ?0:m_xs[a_index]);}
|
||||
double weight(unsigned int a_index) const {return (m_histo ?0:m_ws[a_index]);}
|
||||
double mean() const {
|
||||
return (m_histo ? m_histo->mean() : (m_Sw?m_Sxw/m_Sw:0));
|
||||
}
|
||||
@@ -123,9 +123,9 @@ public:
|
||||
return _rms;
|
||||
}
|
||||
|
||||
bool convert(unsigned int aBins,double aLowerEdge,double aUpperEdge){
|
||||
bool convert(unsigned int a_bins,double a_lower_edge,double a_upper_edge){
|
||||
if(m_histo) return true;
|
||||
m_histo = new histo::h1d(base_cloud::title(),aBins,aLowerEdge,aUpperEdge);
|
||||
m_histo = new histo::h1d(base_cloud::title(),a_bins,a_lower_edge,a_upper_edge);
|
||||
if(!m_histo) return false;
|
||||
bool status = fill_histogram(*m_histo);
|
||||
clear();
|
||||
|
||||
@@ -35,9 +35,9 @@ public:
|
||||
double lower_edge_y() const { return m_histo ? m_histo->axis_y().lower_edge() : m_lower_y;}
|
||||
double upper_edge_x() const { return m_histo ? m_histo->axis_x().upper_edge() : m_upper_x;}
|
||||
double upper_edge_y() const { return m_histo ? m_histo->axis_y().upper_edge() : m_upper_y;}
|
||||
double value_x(unsigned int aIndex) const { return m_histo ? 0 : m_xs[aIndex];}
|
||||
double value_y(unsigned int aIndex) const { return m_histo ? 0 : m_ys[aIndex];}
|
||||
double weight(unsigned int aIndex) const { return m_histo ? 0 : m_ws[aIndex];}
|
||||
double value_x(unsigned int a_index) const { return m_histo ? 0 : m_xs[a_index];}
|
||||
double value_y(unsigned int a_index) const { return m_histo ? 0 : m_ys[a_index];}
|
||||
double weight(unsigned int a_index) const { return m_histo ? 0 : m_ws[a_index];}
|
||||
double mean_x() const {return m_histo ? m_histo->mean_x() : (m_Sw?m_Sxw/m_Sw:0);}
|
||||
double mean_y() const {return m_histo ? m_histo->mean_y() : (m_Sw?m_Syw/m_Sw:0);}
|
||||
double rms_x() const;
|
||||
@@ -211,13 +211,13 @@ void c2d::clear(){
|
||||
|
||||
inline
|
||||
bool c2d::convert(
|
||||
unsigned int aBinsX,double aLowerEdgeX,double aUpperEdgeX
|
||||
,unsigned int aBinsY,double aLowerEdgeY,double aUpperEdgeY
|
||||
unsigned int a_bins_x,double a_lower_edge_x,double a_upper_edge_x
|
||||
,unsigned int a_bins_y,double a_lower_edge_y,double a_upper_edge_y
|
||||
) {
|
||||
if(m_histo) return true; // Done.
|
||||
m_histo = new histo::h2d(base_cloud::title(),
|
||||
aBinsX,aLowerEdgeX,aUpperEdgeX,
|
||||
aBinsY,aLowerEdgeY,aUpperEdgeY);
|
||||
a_bins_x,a_lower_edge_x,a_upper_edge_x,
|
||||
a_bins_y,a_lower_edge_y,a_upper_edge_y);
|
||||
if(!m_histo) return false;
|
||||
bool status = fill_histogram(*m_histo);
|
||||
clear();
|
||||
|
||||
@@ -261,15 +261,15 @@ void c3d::clear(){
|
||||
|
||||
inline
|
||||
bool c3d::convert(
|
||||
unsigned int aBinsX,double aLowerEdgeX,double aUpperEdgeX
|
||||
,unsigned int aBinsY,double aLowerEdgeY,double aUpperEdgeY
|
||||
,unsigned int aBinsZ,double aLowerEdgeZ,double aUpperEdgeZ
|
||||
unsigned int a_bins_x,double a_lower_edge_x,double a_upper_edge_x
|
||||
,unsigned int a_bins_y,double a_lower_edge_y,double a_upper_edge_y
|
||||
,unsigned int a_bins_z,double a_lower_edge_z,double a_upper_edge_z
|
||||
) {
|
||||
if(m_histo) return true; // Done.
|
||||
m_histo = new histo::h3d(base_cloud::title(),
|
||||
aBinsX,aLowerEdgeX,aUpperEdgeX,
|
||||
aBinsY,aLowerEdgeY,aUpperEdgeY,
|
||||
aBinsZ,aLowerEdgeZ,aUpperEdgeZ);
|
||||
a_bins_x,a_lower_edge_x,a_upper_edge_x,
|
||||
a_bins_y,a_lower_edge_y,a_upper_edge_y,
|
||||
a_bins_z,a_lower_edge_z,a_upper_edge_z);
|
||||
if(!m_histo) return false;
|
||||
bool status = fill_histogram(*m_histo);
|
||||
clear();
|
||||
@@ -450,20 +450,20 @@ double c3d::upper_edge_z() const {
|
||||
return m_histo ? m_histo->axis_z().upper_edge() : m_upper_z;
|
||||
}
|
||||
inline
|
||||
double c3d::value_x(unsigned int aIndex) const {
|
||||
return m_histo ? 0 : m_xs[aIndex];
|
||||
double c3d::value_x(unsigned int a_index) const {
|
||||
return m_histo ? 0 : m_xs[a_index];
|
||||
}
|
||||
inline
|
||||
double c3d::value_y(unsigned int aIndex) const {
|
||||
return m_histo ? 0 : m_ys[aIndex];
|
||||
double c3d::value_y(unsigned int a_index) const {
|
||||
return m_histo ? 0 : m_ys[a_index];
|
||||
}
|
||||
inline
|
||||
double c3d::value_z(unsigned int aIndex) const {
|
||||
return m_histo ? 0 : m_zs[aIndex];
|
||||
double c3d::value_z(unsigned int a_index) const {
|
||||
return m_histo ? 0 : m_zs[a_index];
|
||||
}
|
||||
inline
|
||||
double c3d::weight(unsigned int aIndex) const {
|
||||
return m_histo ? 0 : m_ws[aIndex];
|
||||
double c3d::weight(unsigned int a_index) const {
|
||||
return m_histo ? 0 : m_ws[a_index];
|
||||
}
|
||||
inline
|
||||
double c3d::mean_x() const {
|
||||
|
||||
@@ -170,6 +170,75 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_bin_content(bn_t a_ibin,TN a_entries,TW a_Sw,TW a_Sw2,TC a_Sxw,TC a_Sx2w,TC a_Svw,TC a_Sv2w) {
|
||||
if(parent::m_dimension!=1) return false;
|
||||
if(a_ibin>(parent::m_axes[0].m_number_of_bins+1)) return false;
|
||||
|
||||
bool inRange = true;
|
||||
if(a_ibin==0) inRange = false;
|
||||
else if(a_ibin==(parent::m_axes[0].m_number_of_bins+1)) inRange = false;
|
||||
|
||||
TO offset = a_ibin;
|
||||
|
||||
parent::m_all_entries -= parent::m_bin_entries[offset];
|
||||
if(inRange) {
|
||||
parent::m_in_range_entries -= parent::m_bin_entries[offset];
|
||||
parent::m_in_range_Sw -= parent::m_bin_Sw[offset];
|
||||
parent::m_in_range_Sw2 -= parent::m_bin_Sw2[offset];
|
||||
parent::m_in_range_Sxw[0] -= parent::m_bin_Sxw[offset][0];
|
||||
parent::m_in_range_Sx2w[0] -= parent::m_bin_Sx2w[offset][0];
|
||||
}
|
||||
|
||||
parent::m_bin_entries[offset] = a_entries;
|
||||
parent::m_bin_Sw[offset] = a_Sw;
|
||||
parent::m_bin_Sw2[offset] = a_Sw2;
|
||||
|
||||
parent::m_bin_Sxw[offset][0] = a_Sxw;
|
||||
parent::m_bin_Sx2w[offset][0] = a_Sx2w;
|
||||
|
||||
parent::m_all_entries += a_entries;
|
||||
if(inRange) {
|
||||
parent::m_in_range_entries += a_entries;
|
||||
parent::m_in_range_Sw += a_Sw;
|
||||
parent::m_in_range_Sw2 += a_Sw2;
|
||||
|
||||
parent::m_in_range_Sxw[0] += a_Sxw;
|
||||
parent::m_in_range_Sx2w[0] += a_Sx2w;
|
||||
}
|
||||
|
||||
// Profile part :
|
||||
m_bin_Svw[offset] = a_Svw;
|
||||
m_bin_Sv2w[offset] = a_Sv2w;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_bin_content(bn_t a_ibin,TN& a_entries,TW& a_Sw,TW& a_Sw2,TC& a_Sxw,TC& a_Sx2w,TC& a_Svw,TC& a_Sv2w) {
|
||||
if(parent::m_dimension!=1) {
|
||||
a_entries = 0;a_Sw = 0;a_Sw2 = 0;a_Sxw = 0;a_Sx2w = 0;
|
||||
return false;
|
||||
}
|
||||
if(a_ibin>(parent::m_axes[0].m_number_of_bins+1)) {
|
||||
a_entries = 0;a_Sw = 0;a_Sw2 = 0;a_Sxw = 0;a_Sx2w = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
TO offset = a_ibin;
|
||||
|
||||
a_entries = parent::m_bin_entries[offset];
|
||||
a_Sw = parent::m_bin_Sw[offset];
|
||||
a_Sw2 = parent::m_bin_Sw2[offset];
|
||||
|
||||
a_Sxw = parent::m_bin_Sxw[offset][0];
|
||||
a_Sx2w = parent::m_bin_Sx2w[offset][0];
|
||||
|
||||
// Profile part :
|
||||
a_Svw = m_bin_Svw[offset];
|
||||
a_Sv2w = m_bin_Sv2w[offset];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TV bin_rms_value(int aI) const {
|
||||
TO offset;
|
||||
if(!parent::_find_offset(aI,offset)) return 0;
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_image
|
||||
#define tools_image
|
||||
|
||||
#include <vector>
|
||||
#include <cstring> //memcpy
|
||||
#include <cstdio> //fopen
|
||||
|
||||
#include "forit"
|
||||
|
||||
namespace tools {
|
||||
namespace image {
|
||||
|
||||
// give a set of cols*rows same size rgb-image and build
|
||||
// a big image :
|
||||
inline unsigned char* concatenate(unsigned char** a_buffers,
|
||||
unsigned int a_w,unsigned int a_h,
|
||||
unsigned int a_bpp,
|
||||
unsigned int a_cols,unsigned int a_rows,
|
||||
unsigned int a_bw,unsigned int a_bh,
|
||||
unsigned char a_bc,
|
||||
unsigned int& a_rw,unsigned int& a_rh){
|
||||
|
||||
// assume a_buffers has a_cols*a_rows entries.
|
||||
// a_buffers[0] is bottom-left
|
||||
// a_row=0 is bottom.
|
||||
|
||||
unsigned int wbw = a_w + 2*a_bw;
|
||||
unsigned int hbh = a_h + 2*a_bh;
|
||||
|
||||
a_rw = wbw * a_cols;
|
||||
a_rh = hbh * a_rows;
|
||||
|
||||
//printf("debug : %d %d\n",a_rw,a_rh);
|
||||
|
||||
// on big concatenated image the below may fail :
|
||||
unsigned char* rb = new unsigned char[a_rh*a_rw*a_bpp];
|
||||
if(!rb) {a_rw = 0;a_rh = 0;return 0;}
|
||||
|
||||
unsigned int wbw3 = wbw*a_bpp;
|
||||
unsigned int aw3 = a_w*a_bpp;
|
||||
|
||||
//copy tiles :
|
||||
unsigned int index = 0;
|
||||
for(unsigned int j=0;j<a_rows;j++) {
|
||||
for(unsigned int i=0;i<a_cols;i++) {
|
||||
unsigned char* tile = a_buffers[index];
|
||||
|
||||
for(unsigned int r=0;r<hbh;r++) {
|
||||
unsigned char* pos = rb + (j*hbh+r)*a_rw*a_bpp + i*wbw*a_bpp;
|
||||
::memset(pos,a_bc,wbw3);
|
||||
}
|
||||
|
||||
for(unsigned int r=0;r<a_h;r++) {
|
||||
unsigned char* pos = rb + (j*hbh+r+a_bh)*a_rw*a_bpp + (i*wbw+a_bw)*a_bpp;
|
||||
unsigned char* ptile = tile+r*aw3;
|
||||
for(unsigned int c=0;c<aw3;c++,pos++,ptile++) *pos = *ptile;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return rb;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace tools {
|
||||
namespace image {
|
||||
|
||||
typedef unsigned char* (*file_reader)(std::ostream&,const std::string&,unsigned int&,unsigned int&,unsigned int&);
|
||||
|
||||
inline unsigned char* concatenate(std::ostream& a_out,
|
||||
const std::vector<std::string>& a_files,
|
||||
unsigned int a_cols,unsigned int a_rows,
|
||||
unsigned int a_bw,unsigned int a_bh,
|
||||
unsigned char a_bc,
|
||||
file_reader a_file_reader,
|
||||
unsigned int& a_w,unsigned int& a_h,
|
||||
unsigned int& a_bpp) {
|
||||
// a_files[0] is cols=0, rows=0
|
||||
// a_files[1] is cols=1, rows=0
|
||||
// a_files[2] is cols=2, rows=0
|
||||
// ...
|
||||
// and row=0 is bottom of big image.
|
||||
|
||||
unsigned int number = a_cols*a_rows;
|
||||
if(number!=a_files.size()) {
|
||||
a_out << "tools::image::concatenate :"
|
||||
<< " bad number of files. " << number << " expected."
|
||||
<< std::endl;
|
||||
a_bpp = a_w = a_h = 0;
|
||||
return 0;
|
||||
}
|
||||
if(a_files.empty()) {
|
||||
a_out << "tools::image::concatenate :"
|
||||
<< " list of files is empty."
|
||||
<< std::endl;
|
||||
a_bpp = a_w = a_h = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int w1 = 0;
|
||||
unsigned int h1 = 0;
|
||||
unsigned int bpp1 = 0;
|
||||
|
||||
typedef unsigned char* buffer_t;
|
||||
buffer_t* bs = new buffer_t[number];
|
||||
{for(unsigned int i=0;i<number;i++) {bs[i] = 0;}}
|
||||
|
||||
bool read_failed = false;
|
||||
unsigned int index = 0;
|
||||
for(unsigned int j=0;j<a_rows;j++) {
|
||||
for(unsigned int i=0;i<a_cols;i++) {
|
||||
const std::string& file = a_files[index];
|
||||
unsigned int w,h,bpp;
|
||||
unsigned char* b = a_file_reader(a_out,file,w,h,bpp);
|
||||
if(!b) {
|
||||
a_out << "tools::image::concatenate :"
|
||||
<< " can't read " << file << " expected."
|
||||
<< std::endl;
|
||||
read_failed = true;
|
||||
break;
|
||||
}
|
||||
if(!index) {
|
||||
w1 = w;
|
||||
h1 = h;
|
||||
bpp1 = bpp;
|
||||
} else {
|
||||
if(w!=w1) {
|
||||
a_out << "tools::image::concatenate :"
|
||||
<< " file " << file
|
||||
<< " does not have same width image as the first file one."
|
||||
<< " (" << w << "," << w1 << ")."
|
||||
<< std::endl;
|
||||
delete [] b;
|
||||
read_failed = true;
|
||||
break;
|
||||
}
|
||||
if(h!=h1) {
|
||||
a_out << "tools::image::concatenate :"
|
||||
<< " file " << file
|
||||
<< " does not have same height image as the first file one."
|
||||
<< " (" << h << "," << h1 << ")."
|
||||
<< std::endl;
|
||||
delete [] b;
|
||||
read_failed = true;
|
||||
break;
|
||||
}
|
||||
if(bpp!=bpp1) {
|
||||
a_out << "tools::image::concatenate :"
|
||||
<< " file " << file
|
||||
<< " does not have same bytes per pixel as the first file one."
|
||||
<< " (" << h << "," << h1 << ")."
|
||||
<< std::endl;
|
||||
delete [] b;
|
||||
read_failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bs[index] = b;
|
||||
|
||||
index++;
|
||||
}
|
||||
if(read_failed) break;
|
||||
}
|
||||
|
||||
if(read_failed) {
|
||||
{for(unsigned int i=0;i<number;i++) {delete [] bs[i];}}
|
||||
a_bpp = a_w = a_h = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int wa,ha;
|
||||
unsigned char* ba = image::concatenate(bs,w1,h1,bpp1,a_cols,a_rows,a_bw,a_bh,a_bc,wa,ha);
|
||||
if(!ba) {
|
||||
a_out << "tools::image::concatenate :"
|
||||
<< " failed to concatenate all buffers."
|
||||
<< std::endl;
|
||||
{for(unsigned int i=0;i<number;i++) {delete [] bs[i];}}
|
||||
a_bpp = a_w = a_h = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
{for(unsigned int i=0;i<number;i++) {delete [] bs[i];}}
|
||||
|
||||
a_w = wa;
|
||||
a_h = ha;
|
||||
a_bpp = bpp1;
|
||||
return ba;
|
||||
}
|
||||
|
||||
typedef unsigned char* (*reader)(FILE*,unsigned int&,unsigned int&);
|
||||
typedef bool(*writer)(FILE*,unsigned char*,unsigned int,unsigned int);
|
||||
|
||||
inline bool convert(std::ostream& a_out,
|
||||
const std::string& a_sin,
|
||||
reader a_reader,
|
||||
const std::string& a_sout,
|
||||
writer a_writer){
|
||||
|
||||
FILE* fin = ::fopen(a_sin.c_str(),"rb");
|
||||
if(!fin) {
|
||||
a_out << "tools::image::convert :"
|
||||
<< " can't open " << a_sin
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int w,h;
|
||||
unsigned char* b = a_reader(fin,w,h);
|
||||
if(!b) {
|
||||
a_out << "tools::image::convert :"
|
||||
<< " can't read " << a_sin
|
||||
<< std::endl;
|
||||
::fclose(fin);
|
||||
return false;
|
||||
}
|
||||
::fclose(fin);
|
||||
|
||||
FILE* fout = ::fopen(a_sout.c_str(),"wb");
|
||||
if(!fout) {
|
||||
a_out << "tools::image::convert :"
|
||||
<< " can't open " << a_sout
|
||||
<< std::endl;
|
||||
delete [] b;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!a_writer(fout,b,w,h)) {
|
||||
a_out << "tools::image::convert :"
|
||||
<< " can't write " << a_sout
|
||||
<< std::endl;
|
||||
::fclose(fout);
|
||||
delete [] b;
|
||||
return false;
|
||||
}
|
||||
::fclose(fout);
|
||||
delete [] b;
|
||||
return true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include "image_reader"
|
||||
|
||||
#include "sout"
|
||||
|
||||
#include "S_STRING"
|
||||
#ifdef TOOLS_MEM
|
||||
#include "mem"
|
||||
#endif
|
||||
|
||||
namespace tools {
|
||||
namespace image {
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
TOOLS_SCLASS(tools::image::iterator)
|
||||
public:
|
||||
virtual ~iterator(){}
|
||||
public:
|
||||
virtual unsigned int entries() const = 0;
|
||||
virtual bool next() = 0;
|
||||
virtual bool rewind() = 0;
|
||||
public:
|
||||
virtual unsigned int index() const = 0;
|
||||
virtual unsigned char* read_image(unsigned int& a_w,unsigned int& a_h,
|
||||
unsigned int& a_bpp) = 0;
|
||||
};
|
||||
|
||||
class iterator_reader : public virtual iterator {
|
||||
public:
|
||||
TOOLS_SCLASS(tools::image::iterator_reader)
|
||||
public:
|
||||
//still virtual :
|
||||
//virtual unsigned int entries() const = 0;
|
||||
//virtual bool next() = 0;
|
||||
//virtual bool rewind() = 0;
|
||||
//virtual unsigned int index() const = 0;
|
||||
virtual unsigned char* read_image(unsigned int& a_w,unsigned int& a_h,
|
||||
unsigned int& a_bpp) {
|
||||
|
||||
std::string file;
|
||||
if(begin_file(file)) {
|
||||
tools_vforcit(image::ireader*,m_readers,it) {
|
||||
if((*it)->is(file)) {
|
||||
unsigned char* buffer = _open(*(*it),file,a_w,a_h,a_bpp);
|
||||
end_file(file);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
end_file(file);
|
||||
}
|
||||
a_w = 0;a_h = 0;a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
public:
|
||||
virtual bool begin_file(std::string&) = 0;
|
||||
virtual bool end_file(const std::string&) = 0;
|
||||
public:
|
||||
iterator_reader(std::ostream& a_out,unsigned int a_limit)
|
||||
:m_out(a_out)
|
||||
,m_limit(a_limit)
|
||||
{
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
virtual ~iterator_reader(){
|
||||
_clean();
|
||||
#ifdef TOOLS_MEM
|
||||
mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
iterator_reader(const iterator_reader& a_from)
|
||||
:iterator(a_from)
|
||||
,m_out(a_from.m_out)
|
||||
,m_limit(a_from.m_limit)
|
||||
{
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
_copy(a_from.m_readers);
|
||||
}
|
||||
iterator_reader& operator=(const iterator_reader& a_from){
|
||||
if(&a_from==this) return *this;
|
||||
m_limit = a_from.m_limit;
|
||||
_copy(a_from.m_readers);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
void add_reader(ireader* a_reader) {
|
||||
m_readers.push_back(a_reader); //take ownership.
|
||||
}
|
||||
protected:
|
||||
unsigned char* _open(const image::ireader& a_reader,
|
||||
const std::string& a_path,
|
||||
unsigned int& a_w,unsigned int& a_h,
|
||||
unsigned int& a_bpp){
|
||||
// permit to put in common code for jpeg and png.
|
||||
|
||||
unsigned char* buffer = 0;
|
||||
|
||||
if(m_limit) {
|
||||
if(!a_reader.infos(m_out,a_path,a_w,a_h,a_bpp)) {
|
||||
m_out << "tools::image::iterator_reader::_open :"
|
||||
<< " for file " << sout(a_path)
|
||||
<< " ireader::infos failed."
|
||||
<< std::endl;
|
||||
a_w = 0;a_h = 0;a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
if((a_w*a_h*a_bpp)>m_limit) {
|
||||
|
||||
//unsigned int sw;
|
||||
//unsigned int sh;
|
||||
//float aspect = float(w)/float(h);
|
||||
//if(aspect>=1) {
|
||||
// sh = 2;
|
||||
// sw = aspect*sh;
|
||||
//} else {
|
||||
// sw = 2;
|
||||
// sh = sw/aspect;
|
||||
//}
|
||||
|
||||
unsigned int sw = 2;
|
||||
unsigned int sh = 2;
|
||||
while(true) {
|
||||
if(((2*sw)*(2*sh)*a_bpp)>m_limit) break;
|
||||
sw *=2;
|
||||
sh *=2;
|
||||
}
|
||||
|
||||
unsigned int sx = (a_w-sw)/2;
|
||||
unsigned int sy = (a_h-sh)/2;
|
||||
|
||||
buffer = a_reader.read_part
|
||||
(m_out,a_path,sx,sy,sw,sh,a_w,a_h,a_bpp);
|
||||
} else {
|
||||
buffer = a_reader.read(m_out,a_path,a_w,a_h,a_bpp);
|
||||
}
|
||||
} else {
|
||||
buffer = a_reader.read(m_out,a_path,a_w,a_h,a_bpp);
|
||||
}
|
||||
|
||||
if(!buffer) {
|
||||
m_out << "tools::image::iterator_reader::_open :"
|
||||
<< " for file " << sout(a_path)
|
||||
<< " read failed."
|
||||
<< std::endl;
|
||||
a_w = 0;a_h = 0;a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void _clean() {
|
||||
std::vector<ireader*>::iterator it;
|
||||
for(it=m_readers.begin();it!=m_readers.end();) {
|
||||
ireader* obj = *it;
|
||||
it = m_readers.erase(it);
|
||||
delete obj;
|
||||
}
|
||||
}
|
||||
void _copy(const std::vector<ireader*>& a_from) {
|
||||
_clean();
|
||||
tools_vforcit(ireader*,a_from,it) m_readers.push_back((*it)->copy());
|
||||
}
|
||||
protected:
|
||||
std::ostream& m_out;
|
||||
unsigned int m_limit;
|
||||
std::vector<ireader*> m_readers;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_image_reader
|
||||
#define tools_image_reader
|
||||
|
||||
#include "forit"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tools {
|
||||
namespace image {
|
||||
|
||||
class ireader {
|
||||
public:
|
||||
virtual ~ireader() {}
|
||||
public:
|
||||
virtual ireader* copy() const = 0;
|
||||
virtual bool is(const std::string&) const = 0;
|
||||
virtual bool infos(std::ostream& a_out,const std::string& a_file,
|
||||
unsigned int& a_width,unsigned int& a_height,
|
||||
unsigned int& a_bpp) const = 0;
|
||||
virtual unsigned char* read(std::ostream& a_out,const std::string& a_file,
|
||||
unsigned int& a_width,unsigned int& a_height,
|
||||
unsigned int& a_bpp) const = 0;
|
||||
virtual unsigned char* read_part(std::ostream& a_out,
|
||||
const std::string& a_file,
|
||||
unsigned int a_sx,unsigned int a_sy,
|
||||
unsigned int a_sw,unsigned int a_sh,
|
||||
unsigned int& a_rw,unsigned int& a_rh,
|
||||
unsigned int& a_rbpp) const = 0;
|
||||
};
|
||||
|
||||
class readers {
|
||||
public:
|
||||
typedef std::pair<std::string,ireader*> named_reader;
|
||||
public:
|
||||
readers(){}
|
||||
virtual ~readers(){_clear();}
|
||||
public:
|
||||
readers(const readers& a_from) {
|
||||
_copy(a_from.m_readers);
|
||||
}
|
||||
readers& operator=(const readers& a_from){
|
||||
if(&a_from==this) return *this;
|
||||
_copy(a_from.m_readers);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
void add_reader(const std::string& a_name,ireader* a_reader) {
|
||||
m_readers.push_back(named_reader(a_name,a_reader)); //take ownership of a_reader.
|
||||
}
|
||||
const std::vector<named_reader>& named_readers() const {return m_readers;}
|
||||
protected:
|
||||
void _clear(){
|
||||
tools_vforit(named_reader,m_readers,it) delete (*it).second;
|
||||
m_readers.clear();
|
||||
}
|
||||
void _copy(const std::vector<named_reader>& a_from) {
|
||||
_clear();
|
||||
tools_vforcit(named_reader,a_from,it) {
|
||||
m_readers.push_back(named_reader((*it).first,(*it).second->copy()));
|
||||
}
|
||||
}
|
||||
protected:
|
||||
std::vector<named_reader> m_readers; //have a vector (and not a map) since the order is important.
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,702 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_jpeg
|
||||
#define tools_jpeg
|
||||
|
||||
#include <cstdio> //FILE,size_t
|
||||
|
||||
//#define TOOLS_JPEG_OUT_ERR
|
||||
|
||||
extern "C" { //Needed on Windows.
|
||||
#ifdef TOOLS_USE_NATIVE_JPEG
|
||||
#include <jpeglib.h>
|
||||
#else
|
||||
#include <ourex_jpeglib.h> //enforce ourex jpeg
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <csetjmp>
|
||||
#include <cstring> //memcpy
|
||||
#include <tools/mnmx>
|
||||
|
||||
namespace tools {
|
||||
namespace jpeg {
|
||||
|
||||
inline bool write_file(FILE* a_file,int a_quality,unsigned char* a_buffer,unsigned int a_width,unsigned int a_height,unsigned int a_bpp) {
|
||||
|
||||
struct jpeg_compress_struct cinfo;
|
||||
|
||||
struct jpeg_error_mgr jerr;
|
||||
cinfo.err = ::jpeg_std_error(&jerr);
|
||||
|
||||
::jpeg_create_compress(&cinfo);
|
||||
|
||||
::jpeg_stdio_dest(&cinfo,a_file);
|
||||
|
||||
cinfo.image_width = a_width;
|
||||
cinfo.image_height = a_height;
|
||||
cinfo.input_components = a_bpp; // # of color components per pixel.
|
||||
cinfo.in_color_space = JCS_RGB; // colorspace of input image.
|
||||
|
||||
::jpeg_set_defaults(&cinfo);
|
||||
::jpeg_set_quality(&cinfo,a_quality,TRUE);
|
||||
|
||||
::jpeg_start_compress(&cinfo,TRUE);
|
||||
|
||||
int row_stride = a_width * cinfo.input_components;
|
||||
|
||||
while (cinfo.next_scanline < cinfo.image_height) {
|
||||
JSAMPROW row_pointer =
|
||||
a_buffer+(cinfo.image_height-1-cinfo.next_scanline) * row_stride;
|
||||
::jpeg_write_scanlines(&cinfo, &row_pointer, 1);
|
||||
}
|
||||
|
||||
::jpeg_finish_compress(&cinfo);
|
||||
::jpeg_destroy_compress(&cinfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write_file_100(FILE* a_file,unsigned char* a_buffer,unsigned int a_width,unsigned int a_height,unsigned int a_bpp) {
|
||||
return tools::jpeg::write_file(a_file,100,a_buffer,a_width,a_height,a_bpp);
|
||||
}
|
||||
|
||||
struct error_mgr {
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmp_buffer;
|
||||
};
|
||||
|
||||
typedef struct error_mgr* error_ptr;
|
||||
|
||||
extern "C" {
|
||||
inline void exlib_jpeg_error_exit(j_common_ptr cinfo){
|
||||
error_ptr myerr = (error_ptr) cinfo->err;
|
||||
//(*cinfo->err->output_message) (cinfo);
|
||||
//printf("debug : error_exit\n");
|
||||
//NSLog(@"debug : jpeg::error_exit");
|
||||
::longjmp(myerr->setjmp_buffer, 1);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool infos_file(FILE* a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
//NOTE : G.Barrand : not sure that in case of error, we cleanup properly !
|
||||
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct error_mgr jerr;
|
||||
|
||||
cinfo.err = ::jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = exlib_jpeg_error_exit;
|
||||
if(::setjmp(jerr.setjmp_buffer)) {
|
||||
//printf("debug : out of setjmp\n");
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
::jpeg_create_decompress(&cinfo);
|
||||
::jpeg_stdio_src(&cinfo,a_file);
|
||||
::jpeg_read_header(&cinfo, TRUE);
|
||||
|
||||
::jpeg_start_decompress(&cinfo);
|
||||
|
||||
a_width = cinfo.output_width;
|
||||
a_height = cinfo.output_height;
|
||||
a_bpp = cinfo.output_components;
|
||||
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline unsigned char* read_file(FILE* a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
// the returned buffer must be delete with "delete []".
|
||||
|
||||
//NOTE : G.Barrand : not sure that in case of error, we cleanup properly !
|
||||
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct error_mgr jerr;
|
||||
|
||||
cinfo.err = ::jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = exlib_jpeg_error_exit;
|
||||
if(::setjmp(jerr.setjmp_buffer)) {
|
||||
#ifdef TOOLS_JPEG_OUT_ERR
|
||||
::printf("tools::jpeg::read_file : out of setjmp\n");
|
||||
#endif
|
||||
//NOTE : how to be sure to delete the below new if having been done ?
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
::jpeg_create_decompress(&cinfo);
|
||||
::jpeg_stdio_src(&cinfo,a_file);
|
||||
::jpeg_read_header(&cinfo, TRUE);
|
||||
|
||||
::jpeg_start_decompress(&cinfo);
|
||||
|
||||
int row_stride = cinfo.output_width * cinfo.output_components;
|
||||
|
||||
if((!cinfo.output_width)||
|
||||
(!cinfo.output_height)||
|
||||
(cinfo.output_components<=0)) {
|
||||
#ifdef TOOLS_JPEG_OUT_ERR
|
||||
::printf("tools::jpeg::read_file : bad size, w %u h %u cpnts %d\n",
|
||||
cinfo.output_width,cinfo.output_height,cinfo.output_components);
|
||||
#endif
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
a_width = cinfo.output_width;
|
||||
a_height = cinfo.output_height;
|
||||
a_bpp = cinfo.output_components;
|
||||
|
||||
unsigned char* image_buffer = new unsigned char[row_stride * cinfo.output_height];
|
||||
if(!image_buffer) {
|
||||
#ifdef TOOLS_JPEG_OUT_ERR
|
||||
::printf("tools::jpeg::read_file : alloc of %d bytes failed\n",
|
||||
row_stride * cinfo.output_height);
|
||||
#endif
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//FIXME : iPad : the below crashes on LHCb_artist_16384_4096_80.jpg.
|
||||
|
||||
{JSAMPROW buffer[1];
|
||||
unsigned char* pos = image_buffer + row_stride * cinfo.output_height;
|
||||
while (cinfo.output_scanline<cinfo.output_height) {
|
||||
pos -= row_stride;
|
||||
buffer[0] = pos;
|
||||
if(::jpeg_read_scanlines(&cinfo, buffer, 1)!=1) {
|
||||
#ifdef TOOLS_JPEG_OUT_ERR
|
||||
::printf("tools::jpeg::read_file : jpeg_read_scanlines failed\n");
|
||||
#endif
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
delete [] image_buffer;
|
||||
return 0;
|
||||
}
|
||||
}}
|
||||
|
||||
if(cinfo.output_scanline<cinfo.output_height)
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
else
|
||||
::jpeg_finish_decompress(&cinfo);
|
||||
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
return image_buffer;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <tools/sout>
|
||||
|
||||
namespace tools {
|
||||
namespace jpeg {
|
||||
|
||||
inline bool is(const std::string& a_file){
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) return false; //if file does not exist, then it is not a jpeg !
|
||||
unsigned char head[4];
|
||||
size_t nitem = ::fread(head,1,4,file);
|
||||
::fclose(file);
|
||||
if(nitem!=4) return false;
|
||||
if(head[0]!=255) return false;
|
||||
if(head[1]!=216) return false;
|
||||
if(head[2]!=255) return false;
|
||||
//if(head[3]!=224) return false; //LRI.jpg is 225 !
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool infos(std::ostream& a_out,const std::string& a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
if(!is(a_file)) {
|
||||
a_out << "tools::jpeg::infos :"
|
||||
<< " file " << a_file << " is not jpeg."
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) {
|
||||
a_out << "tools::jpeg::infos :"
|
||||
<< " can't open " << a_file
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int w,h,bpp;
|
||||
bool status = infos_file(file,w,h,bpp);
|
||||
|
||||
::fclose(file);
|
||||
|
||||
if(!status) {
|
||||
a_out << "tools::jpeg::infos :"
|
||||
<< " problem reading " << a_file
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
a_width = w;
|
||||
a_height = h;
|
||||
a_bpp = bpp;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline unsigned char* read(std::ostream& a_out,const std::string& a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
if(!is(a_file)) {
|
||||
a_out << "tools::jpeg::read :"
|
||||
<< " file " << a_file << " is not jpeg."
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) {
|
||||
a_out << "tools::jpeg::read :"
|
||||
<< " can't open " << a_file
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int w,h,bpp;
|
||||
unsigned char* buffer = read_file(file,w,h,bpp);
|
||||
|
||||
::fclose(file);
|
||||
|
||||
if(!buffer) {
|
||||
a_out << "tools::jpeg::read :"
|
||||
<< " problem reading " << a_file
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
a_width = w;
|
||||
a_height = h;
|
||||
a_bpp = bpp;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline unsigned char* read_part(std::ostream& a_out,
|
||||
const std::string& a_file,
|
||||
unsigned int a_sx,unsigned int a_sy,
|
||||
unsigned int a_sw,unsigned int a_sh,
|
||||
unsigned int& a_rw,unsigned int& a_rh,
|
||||
unsigned int& a_rbpp) {
|
||||
if(!is(a_file)) {
|
||||
a_out << "tools::jpeg::read_part :"
|
||||
<< " file " << a_file << " is not jpeg."
|
||||
<< std::endl;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) {
|
||||
a_out << "tools::jpeg::read_part :"
|
||||
<< " can't open " << a_file
|
||||
<< std::endl;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct error_mgr jerr;
|
||||
|
||||
cinfo.err = ::jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = exlib_jpeg_error_exit;
|
||||
if(::setjmp(jerr.setjmp_buffer)) {
|
||||
//printf("debug : out of setjmp\n");
|
||||
::fclose(file);
|
||||
//NOTE : how to be sure to delete the below news if having been done ?
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
::jpeg_create_decompress(&cinfo);
|
||||
::jpeg_stdio_src(&cinfo,file);
|
||||
::jpeg_read_header(&cinfo,TRUE);
|
||||
|
||||
::jpeg_start_decompress(&cinfo);
|
||||
|
||||
int row_stride = cinfo.output_width * cinfo.output_components;
|
||||
|
||||
unsigned int w = cinfo.output_width;
|
||||
unsigned int h = cinfo.output_height;
|
||||
|
||||
if((a_sx>=w)||(a_sy>=h)){
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
::fclose(file);
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 012345
|
||||
a_rw = tools::mn<unsigned int>(w-a_sx,a_sw);
|
||||
a_rh = tools::mn<unsigned int>(h-a_sy,a_sh);
|
||||
a_rbpp = cinfo.output_components;
|
||||
|
||||
if(!a_rw||!a_rh||!a_rbpp){
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
::fclose(file);
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char* image_buffer = new unsigned char[a_rw*a_rh*a_rbpp];
|
||||
if(!image_buffer) {
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
::fclose(file);
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char* line = new unsigned char[row_stride];
|
||||
if(!line) {
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
::fclose(file);
|
||||
delete [] image_buffer;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//FIXME : iPad : the below crashes on LHCb_artist_16384_4096_80.jpg.
|
||||
|
||||
unsigned int hbeg = a_sy;
|
||||
unsigned int hend = a_sy+a_rh;
|
||||
|
||||
{JSAMPROW buffer[1];
|
||||
buffer[0] = line;
|
||||
unsigned char* pos = image_buffer+a_rh*a_rw*a_rbpp;
|
||||
while(cinfo.output_scanline<cinfo.output_height) {
|
||||
if(jpeg_read_scanlines(&cinfo, buffer, 1)!=1) {
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
::fclose(file);
|
||||
delete [] line;
|
||||
delete [] image_buffer;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
if((hbeg<=cinfo.output_scanline)&&(cinfo.output_scanline<hend)){
|
||||
pos -= a_rw*a_rbpp;
|
||||
::memcpy(pos,line+a_sx*a_rbpp,a_rw*a_rbpp);
|
||||
}
|
||||
}}
|
||||
|
||||
if(cinfo.output_scanline<cinfo.output_height)
|
||||
::jpeg_abort_decompress(&cinfo);
|
||||
else
|
||||
::jpeg_finish_decompress(&cinfo);
|
||||
|
||||
::jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
::fclose(file);
|
||||
|
||||
delete [] line;
|
||||
|
||||
return image_buffer;
|
||||
}
|
||||
|
||||
inline bool write(std::ostream& a_out,
|
||||
const std::string& a_file,
|
||||
unsigned char* a_buffer,
|
||||
unsigned int a_width,
|
||||
unsigned int a_height,
|
||||
unsigned int a_bpp,
|
||||
int a_quality) {
|
||||
FILE* file = ::fopen(a_file.c_str(),"wb");
|
||||
if(!file) {
|
||||
a_out << "tools::jpeg::write :"
|
||||
<< " can't open file " << tools::sout(a_file) << "."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if(!write_file(file,a_quality,a_buffer,a_width,a_height,a_bpp)) {
|
||||
::fclose(file);
|
||||
a_out << "tools::jpeg::write :"
|
||||
<< " can't write file " << tools::sout(a_file) << "."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
::fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <tools/xpm>
|
||||
|
||||
namespace tools {
|
||||
namespace jpeg {
|
||||
|
||||
inline bool to_xpm(std::ostream& a_out,const std::string& a_file,const std::string& a_name,bool a_verbose = false) {
|
||||
return tools::xpm::to_xpm(a_out,a_file,a_name,read,a_verbose);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <tools/image>
|
||||
#include <vector>
|
||||
|
||||
namespace tools {
|
||||
namespace jpeg {
|
||||
|
||||
inline bool concatenate(std::ostream& a_out,
|
||||
const std::vector<std::string>& a_files,
|
||||
unsigned int a_cols,unsigned int a_rows,
|
||||
unsigned int a_bw,unsigned int a_bh,
|
||||
unsigned char a_bc,
|
||||
const std::string& a_file,int a_quality) {
|
||||
unsigned int wa,ha,bppa;
|
||||
unsigned char* ba =
|
||||
tools::image::concatenate
|
||||
(a_out,a_files,a_cols,a_rows,a_bw,a_bh,a_bc,read,wa,ha,bppa);
|
||||
if(!ba) {
|
||||
a_out << "tools::jpeg::concatenate :"
|
||||
<< " failed to concatenate all buffers."
|
||||
<< std::endl;
|
||||
delete [] ba;
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* file = ::fopen(a_file.c_str(),"wb");
|
||||
if(!file) {
|
||||
a_out << "tools::jpeg::concatenate :"
|
||||
<< " can't open " << file << " for writing."
|
||||
<< std::endl;
|
||||
delete [] ba;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!write_file(file,a_quality,ba,wa,ha,bppa)) {
|
||||
a_out << "tools::jpeg::concatenate :"
|
||||
<< " can't write " << a_file << "."
|
||||
<< std::endl;
|
||||
delete [] ba;
|
||||
::fclose(file);
|
||||
return false;
|
||||
}
|
||||
|
||||
delete [] ba;
|
||||
::fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
class reader : public virtual tools::image::ireader {
|
||||
public:
|
||||
virtual tools::image::ireader* copy() const {return new reader(*this);}
|
||||
virtual bool is(const std::string& a_file) const {
|
||||
return tools::jpeg::is(a_file);
|
||||
}
|
||||
virtual bool infos(std::ostream& a_out,const std::string& a_file,
|
||||
unsigned int& a_width,unsigned int& a_height,
|
||||
unsigned int& a_bpp) const {
|
||||
return tools::jpeg::infos(a_out,a_file,a_width,a_height,a_bpp);
|
||||
}
|
||||
virtual unsigned char* read(std::ostream& a_out,const std::string& a_file,
|
||||
unsigned int& a_width,unsigned int& a_height,
|
||||
unsigned int& a_bpp) const {
|
||||
return tools::jpeg::read(a_out,a_file,a_width,a_height,a_bpp);
|
||||
}
|
||||
virtual unsigned char* read_part(std::ostream& a_out,
|
||||
const std::string& a_file,
|
||||
unsigned int a_sx,unsigned int a_sy,
|
||||
unsigned int a_sw,unsigned int a_sh,
|
||||
unsigned int& a_rw,unsigned int& a_rh,
|
||||
unsigned int& a_rbpp) const {
|
||||
return tools::jpeg::read_part(a_out,a_file,
|
||||
a_sx,a_sy,
|
||||
a_sw,a_sh,
|
||||
a_rw,a_rh,
|
||||
a_rbpp);
|
||||
}
|
||||
public:
|
||||
reader(){}
|
||||
virtual ~reader(){}
|
||||
public:
|
||||
reader(const reader&):ireader(){}
|
||||
reader& operator=(const reader&){return *this;}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
//#include <tools/img>
|
||||
//
|
||||
//namespace tools {
|
||||
//namespace jpeg {
|
||||
//
|
||||
//class jpeg_data : public tools::img_byte {
|
||||
//public:
|
||||
// jpeg_data(std::ostream& a_out)
|
||||
// :tools::img_byte(3)
|
||||
// ,m_out(a_out)
|
||||
// ,m_FILE(0)
|
||||
// ,m_row_stride(0)
|
||||
// ,m_pos(0)
|
||||
// {}
|
||||
// virtual ~jpeg_data(){
|
||||
// if(m_FILE) ::fclose(m_FILE);
|
||||
// }
|
||||
//protected: //don't copy
|
||||
// jpeg_data(const jpeg_data& a_from)
|
||||
// :tools::img_byte(a_from)
|
||||
// ,m_out(a_from.m_out)
|
||||
// {}
|
||||
// jpeg_data& operator=(const jpeg_data& a_from){
|
||||
// tools::img_byte::operator=(a_from);
|
||||
// return *this;
|
||||
// }
|
||||
//public:
|
||||
// bool open(const std::string& a_file) {
|
||||
// if(m_FILE) return false;
|
||||
//
|
||||
// if(!tools::jpeg::is(a_file)) {
|
||||
// m_out << "tools::jpeg::jpeg_data::open :"
|
||||
// << " file " << a_file << " is not jpeg."
|
||||
// << std::endl;
|
||||
// return false;
|
||||
// }
|
||||
// m_FILE = ::fopen(a_file.c_str(),"rb");
|
||||
// if(!m_FILE) {
|
||||
// m_out << "tools::jpeg::jpeg_data::open :"
|
||||
// << " can't open " << a_file
|
||||
// << std::endl;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// m_cinfo.err = ::jpeg_std_error(&m_jerr.pub);
|
||||
// m_jerr.pub.error_exit = exlib_jpeg_exlib_jpeg_exlib_jpeg_error_exit;
|
||||
// if(::setjmp(m_jerr.setjmp_buffer)) {
|
||||
// m_out << "tools::jpeg::jpeg_data::open :"
|
||||
// << " setjmp failed." << a_file
|
||||
// << std::endl;
|
||||
// ::fclose(m_FILE);
|
||||
// m_FILE = 0;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// ::jpeg_create_decompress(&m_cinfo);
|
||||
// ::jpeg_stdio_src(&m_cinfo,m_FILE);
|
||||
// ::jpeg_read_header(&m_cinfo,TRUE);
|
||||
//
|
||||
// ::jpeg_start_decompress(&m_cinfo);
|
||||
//
|
||||
// if(m_cinfo.output_components!=3) {
|
||||
// m_out << "tools::jpeg::jpeg_data::open :"
|
||||
// << " file " << a_file << " dont't have three components."
|
||||
// << std::endl;
|
||||
// ::fclose(m_FILE);
|
||||
// m_FILE = 0;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// m_row_stride = m_cinfo.output_width * m_cinfo.output_components;
|
||||
//
|
||||
// unsigned char* buffer =
|
||||
// new unsigned char[m_row_stride * m_cinfo.output_height];
|
||||
// if(!buffer) {
|
||||
// m_out << "tools::jpeg::jpeg_data::open :"
|
||||
// << " can't alloc " << m_row_stride * m_cinfo.output_height
|
||||
// << std::endl;
|
||||
// ::fclose(m_FILE);
|
||||
// m_FILE = 0;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// tools::img_byte::set(m_cinfo.output_width,m_cinfo.output_height,
|
||||
// buffer,true);
|
||||
// m_pos = buffer + m_row_stride * m_cinfo.output_height;
|
||||
// return true;
|
||||
// }
|
||||
// bool read_row() {
|
||||
// if(!m_FILE) return false;
|
||||
// //::printf("debug : read_row %d\n",m_cinfo.output_scanline);
|
||||
// if(m_cinfo.output_scanline<m_cinfo.output_height) {
|
||||
// m_pos -= m_row_stride;
|
||||
// m_jbuffer[0] = m_pos;
|
||||
// if(::jpeg_read_scanlines(&m_cinfo,m_jbuffer,1)!=1) {
|
||||
// tools::img_byte::clear();
|
||||
// ::fclose(m_FILE);
|
||||
// m_FILE = 0;
|
||||
// return false;
|
||||
// }
|
||||
// m_h = m_cinfo.output_scanline; //in case we have to stop before end.
|
||||
// return true; //continue reading.
|
||||
// } else { //done.
|
||||
// ::jpeg_finish_decompress(&m_cinfo);
|
||||
// ::jpeg_destroy_decompress(&m_cinfo);
|
||||
// ::fclose(m_FILE);
|
||||
// m_FILE = 0;
|
||||
// return false; //stop reading.
|
||||
// }
|
||||
// }
|
||||
//protected:
|
||||
// std::ostream& m_out;
|
||||
// FILE* m_FILE;
|
||||
// struct jpeg_decompress_struct m_cinfo;
|
||||
// struct tools::jpeg::error_mgr m_jerr;
|
||||
// int m_row_stride;
|
||||
// JSAMPROW m_jbuffer[1];
|
||||
// unsigned char* m_pos;
|
||||
//};
|
||||
//
|
||||
//}}
|
||||
|
||||
#endif
|
||||
@@ -132,6 +132,18 @@ public:\
|
||||
}}\
|
||||
}\
|
||||
public:\
|
||||
template <class ARRAY>\
|
||||
bool mul_array(ARRAY& a_array,T a_tmp[]) const {\
|
||||
/* a_array = this *= a_array */\
|
||||
unsigned int _dim = dimension();\
|
||||
T* pos = a_tmp;\
|
||||
for(unsigned int r=0;r<_dim;r++,pos++) {\
|
||||
*pos = T();\
|
||||
for(unsigned int c=0;c<_dim;c++) *pos += m_vec[r+c*_dim]*a_array[c];\
|
||||
}\
|
||||
{for(unsigned int i=0;i<_dim;i++) a_array[i] = a_tmp[i];}\
|
||||
return true;\
|
||||
}\
|
||||
template <class VEC>\
|
||||
bool mul_vec(VEC& a_vec,T a_tmp[]) const {\
|
||||
/* a_vec = this *= a_vec */\
|
||||
@@ -147,9 +159,9 @@ public:\
|
||||
}\
|
||||
template <class VEC>\
|
||||
bool mul_vec(VEC& a_vec) const {\
|
||||
T* res = new T[dimension()];\
|
||||
bool status = mul_vec(a_vec,res);\
|
||||
delete [] res;\
|
||||
T* _tmp = new T[dimension()];\
|
||||
bool status = mul_vec(a_vec,_tmp);\
|
||||
delete [] _tmp;\
|
||||
return status;\
|
||||
}\
|
||||
\
|
||||
@@ -165,9 +177,9 @@ public:\
|
||||
return true;\
|
||||
}\
|
||||
bool mul_array(T a_vec[]) const {\
|
||||
T* res = new T[dimension()];\
|
||||
bool status = mul_array(a_vec,res);\
|
||||
delete [] res;\
|
||||
T* _tmp = new T[dimension()];\
|
||||
bool status = mul_array(a_vec,_tmp);\
|
||||
delete [] _tmp;\
|
||||
return status;\
|
||||
}\
|
||||
\
|
||||
@@ -225,7 +237,7 @@ public:\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
bool is_proportional(const TOOLS_MAT_CLASS& a_m,const T& a_prec,T& a_factor) const {\
|
||||
bool to_rm_is_proportional(const TOOLS_MAT_CLASS& a_m,const T& a_prec,T& a_factor) const {\
|
||||
if(&a_m==this) {a_factor=one();return true;}\
|
||||
/* If true, then : a_m = a_factor * this.*/\
|
||||
a_factor = zero();\
|
||||
@@ -235,8 +247,8 @@ public:\
|
||||
for(unsigned int i=0;i<dim2();i++,tp++,mp++) {\
|
||||
if( ((*tp)==zero()) && ((*mp)==zero())) {\
|
||||
continue;\
|
||||
} else if( ((*tp)!=zero()) && ((*mp)==zero())) {\
|
||||
return false;\
|
||||
/*} else if( ((*tp)!=zero()) && ((*mp)==zero())) {\
|
||||
return false;*/\
|
||||
} else if( ((*tp)==zero()) && ((*mp)!=zero())) {\
|
||||
return false;\
|
||||
} else {\
|
||||
@@ -254,9 +266,8 @@ public:\
|
||||
}\
|
||||
\
|
||||
public:\
|
||||
template <class PREC>\
|
||||
bool is_proportional_prec(const TOOLS_MAT_CLASS& a_right,const PREC& a_prec,PREC(*a_fabs)(const T&),T& a_factor) const {\
|
||||
/* If true, then : a_right = a_factor * this.*/\
|
||||
bool is_proportional(const TOOLS_MAT_CLASS& a_right,T& a_factor) const {\
|
||||
/* If true, then : a_right = a_factor * this. a_factor could be zero.*/\
|
||||
if(this==&a_right) {a_factor=T(1);return true;}\
|
||||
a_factor = zero();\
|
||||
if(dimension()!=a_right.dimension()) return false;\
|
||||
@@ -265,20 +276,41 @@ public:\
|
||||
bool first = true;\
|
||||
size_t _data_size = data_size();\
|
||||
for(size_t i=0;i<_data_size;i++,lp++,rp++) {\
|
||||
if( is_zero(*lp,a_prec,a_fabs) && is_zero(*rp,a_prec,a_fabs) ) {\
|
||||
continue;\
|
||||
} else if( !is_zero(*lp,a_prec,a_fabs) && is_zero(*rp,a_prec,a_fabs) ) {\
|
||||
if(*lp==zero()) {\
|
||||
if(*rp==zero()) continue;\
|
||||
return false;\
|
||||
} else if( is_zero(*lp,a_prec,a_fabs) && !is_zero(*rp,a_prec,a_fabs) ) {\
|
||||
return false;\
|
||||
} else {\
|
||||
if(first) {\
|
||||
a_factor = (*rp)/(*lp);\
|
||||
first = false;\
|
||||
} else {\
|
||||
if(!numbers_are_equal((*lp)*a_factor,*rp,a_prec,a_fabs)) return false;\
|
||||
}\
|
||||
}\
|
||||
if(first) {\
|
||||
a_factor = (*rp)/(*lp);\
|
||||
first = false;\
|
||||
continue;\
|
||||
}\
|
||||
if((*lp)*a_factor!=(*rp)) return false;\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
template <class PREC>\
|
||||
bool is_proportional_prec(const TOOLS_MAT_CLASS& a_right,const PREC& a_prec,PREC(*a_fabs)(const T&),T& a_factor) const {\
|
||||
/* If true, then : a_right = a_factor * this. a_factor could be zero.*/\
|
||||
if(this==&a_right) {a_factor=T(1);return true;}\
|
||||
a_factor = zero();\
|
||||
if(dimension()!=a_right.dimension()) return false;\
|
||||
T* lp = (T*)m_vec;\
|
||||
T* rp = (T*)a_right.m_vec;\
|
||||
bool first = true;\
|
||||
size_t _data_size = data_size();\
|
||||
for(size_t i=0;i<_data_size;i++,lp++,rp++) {\
|
||||
if(is_zero(*lp,a_prec,a_fabs)) {\
|
||||
if(is_zero(*rp,a_prec,a_fabs)) continue;\
|
||||
return false;\
|
||||
}\
|
||||
if(first) {\
|
||||
a_factor = (*rp)/(*lp);\
|
||||
first = false;\
|
||||
continue;\
|
||||
}\
|
||||
if(!numbers_are_equal((*lp)*a_factor,*rp,a_prec,a_fabs)) return false;\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
@@ -392,7 +424,7 @@ public:\
|
||||
|0 Y|*/\
|
||||
unsigned int _D = dimension();\
|
||||
unsigned int _D_2 = _D/2;\
|
||||
/*if(2*__D_2!=_D) return false;*/\
|
||||
if(2*_D_2!=_D) return false;\
|
||||
for(unsigned int r=0;r<_D_2;r++) {\
|
||||
for(unsigned int c=_D_2;c<_D;c++) {\
|
||||
if(a_fabs(value(r,c))>=a_prec) return false;\
|
||||
@@ -412,7 +444,7 @@ public:\
|
||||
|Y 0|*/\
|
||||
unsigned int _D = dimension();\
|
||||
unsigned int _D_2 = _D/2;\
|
||||
/*if(2*__D_2!=_D) return false;*/\
|
||||
if(2*_D_2!=_D) return false;\
|
||||
for(unsigned int r=0;r<_D_2;r++) {\
|
||||
for(unsigned int c=0;c<_D_2;c++) {\
|
||||
if(a_fabs(value(r,c))>=a_prec) return false;\
|
||||
@@ -425,6 +457,26 @@ public:\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
template <class PREC>\
|
||||
bool is_decomplex(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
|
||||
/* Look if even dim matrix is of the form : | X Y|\
|
||||
|-Y X|*/\
|
||||
unsigned int _D = dimension();\
|
||||
unsigned int _D_2 = _D/2;\
|
||||
if(2*_D_2!=_D) return false;\
|
||||
for(unsigned int r=0;r<_D_2;r++) {\
|
||||
for(unsigned int c=0;c<_D_2;c++) {\
|
||||
if(a_fabs(value(r,c)-value(r+_D_2,c+_D_2))>=a_prec) return false;\
|
||||
}\
|
||||
}\
|
||||
for(unsigned int r=0;r<_D_2;r++) {\
|
||||
for(unsigned int c=_D_2;c<_D;c++) {\
|
||||
if(a_fabs(value(r,c)+value(r+_D_2,c-_D_2))>=a_prec) return false;\
|
||||
}\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
template <class PREC>\
|
||||
T determinant_prec(unsigned int a_tmp_rs[],unsigned int a_tmp_cs[], /*[rord=dim-1]*/\
|
||||
@@ -727,21 +779,31 @@ public:\
|
||||
\
|
||||
void power(unsigned int a_n,TOOLS_MAT_CLASS& a_res) const {\
|
||||
a_res.set_identity();\
|
||||
T* _tmp = new T[dim2()];\
|
||||
for(unsigned int i=0;i<a_n;i++) {\
|
||||
a_res._mul_mtx(m_vec);\
|
||||
a_res._mul_mtx(m_vec,_tmp);\
|
||||
}\
|
||||
delete [] _tmp;\
|
||||
}\
|
||||
\
|
||||
void exp(unsigned int a_le,TOOLS_MAT_CLASS& a_res,TOOLS_MAT_CLASS& a_tmp,T a_tmp_2[]) const { /*OPTIMIZATION*/\
|
||||
/* result = I + M + M**2/2! + M**3/3! + .... */\
|
||||
a_res.set_identity();\
|
||||
a_tmp.set_identity();\
|
||||
for(unsigned int i=1;i<=a_le;i++) {\
|
||||
a_tmp._mul_mtx(m_vec,a_tmp_2);\
|
||||
a_tmp.multiply(one()/T(i));\
|
||||
a_res += a_tmp;\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
void exp(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
|
||||
/* result = I + M + M**2/2! + M**3/3! + .... */\
|
||||
a_res.set_identity();\
|
||||
TOOLS_MAT_CLASS tmp(*this);\
|
||||
tmp.set_identity();\
|
||||
for(unsigned int i=1;i<=a_le;i++) {\
|
||||
tmp._mul_mtx(m_vec);\
|
||||
tmp.multiply(one()/T(i)); \
|
||||
a_res += tmp;\
|
||||
}\
|
||||
T* tmp_2 = new T[dim2()];\
|
||||
exp(a_le,a_res,tmp,tmp_2);\
|
||||
delete [] tmp_2;\
|
||||
}\
|
||||
\
|
||||
void cosh(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
|
||||
@@ -751,12 +813,14 @@ public:\
|
||||
M_2._mul_mtx(m_vec);\
|
||||
TOOLS_MAT_CLASS tmp(*this);\
|
||||
tmp.set_identity();\
|
||||
T* _tmp = new T[dim2()];\
|
||||
for(unsigned int i=1;i<=a_le;i+=2) {\
|
||||
tmp *= M_2;\
|
||||
tmp._mul_mtx(M_2.m_vec,_tmp);\
|
||||
tmp.multiply(one()/T(i+0)); \
|
||||
tmp.multiply(one()/T(i+1)); \
|
||||
a_res += tmp;\
|
||||
}\
|
||||
delete [] _tmp;\
|
||||
}\
|
||||
\
|
||||
void sinh(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
|
||||
@@ -766,12 +830,14 @@ public:\
|
||||
M_2._mul_mtx(m_vec);\
|
||||
TOOLS_MAT_CLASS tmp(*this);\
|
||||
tmp._copy(m_vec);\
|
||||
T* _tmp = new T[dim2()];\
|
||||
for(unsigned int i=1;i<=a_le;i+=2) {\
|
||||
tmp *= M_2;\
|
||||
tmp._mul_mtx(M_2.m_vec,_tmp);\
|
||||
tmp.multiply(one()/T(i+1)); \
|
||||
tmp.multiply(one()/T(i+2)); \
|
||||
a_res += tmp;\
|
||||
}\
|
||||
delete [] _tmp;\
|
||||
}\
|
||||
\
|
||||
void log(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
|
||||
@@ -789,14 +855,37 @@ public:\
|
||||
\
|
||||
TOOLS_MAT_CLASS tmp;\
|
||||
\
|
||||
T* _tmp = new T[dim2()];\
|
||||
for(unsigned int i=0;i<=a_le;i++) {\
|
||||
fact *= minus_one(); \
|
||||
tmp = M_Ip;\
|
||||
tmp.multiply(fact/T(i+1)); \
|
||||
a_res += tmp;\
|
||||
M_Ip._mul_mtx(M_I.m_vec);\
|
||||
M_Ip._mul_mtx(M_I.m_vec,_tmp);\
|
||||
}\
|
||||
delete [] _tmp;\
|
||||
}\
|
||||
\
|
||||
void omega(unsigned int a_le,TOOLS_MAT_CLASS& a_res,TOOLS_MAT_CLASS& a_tmp,T a_tmp_2[]) const { /*OPTIMIZATION*/\
|
||||
/* result = I + M/2! + M**2/3! + M**3/4! + .... */\
|
||||
a_res.set_identity();\
|
||||
a_tmp.set_identity();\
|
||||
for(unsigned int i=1;i<=a_le;i++) {\
|
||||
a_tmp._mul_mtx(m_vec,a_tmp_2);\
|
||||
a_tmp.multiply(one()/T(i+1));\
|
||||
a_res += a_tmp;\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
void omega(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
|
||||
/* result = I + M/2! + M**2/3! + M**3/4! + .... */\
|
||||
TOOLS_MAT_CLASS tmp(*this);\
|
||||
tmp.set_identity();\
|
||||
T* tmp_2 = new T[dim2()];\
|
||||
omega(a_le,a_res,tmp,tmp_2);\
|
||||
delete [] tmp_2;\
|
||||
}\
|
||||
\
|
||||
template <class MAT>\
|
||||
bool copy(const MAT& a_from) {\
|
||||
/*for exa from a double matrix to a symbol matrix*/\
|
||||
@@ -914,26 +1003,26 @@ protected:\
|
||||
}\
|
||||
\
|
||||
void _mul_mtx(const T a_m[]) {\
|
||||
T* res = new T[dim2()];\
|
||||
_mul_mtx(a_m,res);\
|
||||
delete [] res;\
|
||||
T* _tmp = new T[dim2()];\
|
||||
_mul_mtx(a_m,_tmp);\
|
||||
delete [] _tmp;\
|
||||
}\
|
||||
\
|
||||
void _left_mul_mtx(const T a_m[]) {\
|
||||
/* this = a_m * this */\
|
||||
unsigned int _D = dimension();\
|
||||
T* res = new T[dim2()];\
|
||||
T* _tmp = new T[dim2()];\
|
||||
for(unsigned int r=0;r<_D;r++) {\
|
||||
for(unsigned int c=0;c<_D;c++) {\
|
||||
T _value = zero();\
|
||||
for(unsigned int i=0;i<_D;i++) {\
|
||||
_value += (*(a_m+r+i*_D)) * (*(m_vec+i+c*_D)); /*optimize.*/\
|
||||
}\
|
||||
*(res+r+c*_D) = _value;\
|
||||
*(_tmp+r+c*_D) = _value;\
|
||||
}\
|
||||
}\
|
||||
_copy(res);\
|
||||
delete [] res;\
|
||||
_copy(_tmp);\
|
||||
delete [] _tmp;\
|
||||
}\
|
||||
\
|
||||
template <class PREC>\
|
||||
|
||||
@@ -19,6 +19,40 @@ inline bool is_zero(const NUMBER& a_left,const PREC& a_prec,PREC(*a_fabs)(const
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class VEC,class PREC>
|
||||
inline bool vectors_are_equal(const VEC& a_1,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
//bool status = true;
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!numbers_are_equal(a_1[index],a_2[index],a_prec,a_fabs))
|
||||
//{ ::printf("debug : vectors_are_equals : %lu : %g %g\n",index,a_1[index],a_2[index]);
|
||||
return false;
|
||||
//status = false;
|
||||
//}
|
||||
}
|
||||
return true;
|
||||
//return status;
|
||||
}
|
||||
|
||||
template <class VECVEC,class PREC>
|
||||
inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VECVEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!vectors_are_equal(a_1[index],a_2[index],a_prec,a_fabs)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// PREC(*a_fabs)(PREC) : /////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// for histo equals functions.
|
||||
|
||||
template <class NUMBER,class PREC>
|
||||
inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(NUMBER)) {
|
||||
NUMBER diff = a_left - a_right;
|
||||
@@ -54,6 +88,10 @@ inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -232,6 +232,18 @@ inline bool to_real(const CMAT& a_c,RMAT& a_r,typename CMAT::elem_t::value_type
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class RMAT,class CMAT>
|
||||
inline bool to_complex(const RMAT& a_r,CMAT& a_c) {
|
||||
if(a_c.dimension()!=a_r.dimension()) return false;
|
||||
typedef typename RMAT::elem_t RT;
|
||||
const RT* rpos = a_r.data();
|
||||
typedef typename CMAT::elem_t CT;
|
||||
CT* cpos = const_cast<CT*>(a_c.data());
|
||||
unsigned int D2 = a_r.dimension()*a_r.dimension();
|
||||
for(unsigned int i=0;i<D2;i++,rpos++,cpos++) *cpos = CT(*rpos);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class MAT>
|
||||
inline void dagger(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT::elem_t&)) {
|
||||
conjugate<MAT>(a_m,a_conj);
|
||||
@@ -454,18 +466,52 @@ inline nmat<T> operator*(const nmat<T>& a_m,const T& a_fac) {
|
||||
}
|
||||
*/
|
||||
|
||||
template <class MAT,class REAL>
|
||||
inline bool mat_fabs(const MAT& a_in,MAT& a_ou,REAL(*a_fabs)(const typename MAT::elem_t&)) {
|
||||
if(a_in.dimension()!=a_ou.dimension()) {a_ou.set_zero();return false;}
|
||||
typedef typename MAT::elem_t T;
|
||||
T* in_pos = const_cast<T*>(a_in.data());
|
||||
T* ou_pos = const_cast<T*>(a_ou.data());
|
||||
unsigned int D2 = a_in.dimension()*a_in.dimension();
|
||||
for(unsigned int i=0;i<D2;i++,in_pos++,ou_pos++) {*ou_pos = a_fabs(*in_pos);}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
#include <cstdarg>
|
||||
|
||||
namespace tools {
|
||||
|
||||
template <class MAT>
|
||||
inline void matrix_va_set(MAT& a_m,size_t a_dummy,...) {
|
||||
typedef typename MAT::elem_t T;
|
||||
va_list args;
|
||||
va_start(args,a_dummy);
|
||||
unsigned int D = a_m.dimension();
|
||||
for(unsigned int r=0;r<D;r++) {
|
||||
for(unsigned int c=0;c<D;c++) {
|
||||
a_m.set_value(r,c,va_arg(args,T));
|
||||
}
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
namespace tools {
|
||||
|
||||
#define TOOLS_MELEM const typename MAT::elem_t&
|
||||
|
||||
////////////////////////////////////////////////
|
||||
/// specific D=2 ///////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
template <class MAT>
|
||||
inline void matrix_set(MAT& a_m
|
||||
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01
|
||||
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11
|
||||
,TOOLS_MELEM a_00,TOOLS_MELEM a_01
|
||||
,TOOLS_MELEM a_10,TOOLS_MELEM a_11
|
||||
){
|
||||
//a_<R><C>
|
||||
//vec[R + C * 2];
|
||||
@@ -479,9 +525,9 @@ inline void matrix_set(MAT& a_m
|
||||
////////////////////////////////////////////////
|
||||
template <class MAT>
|
||||
inline void matrix_set(MAT& a_m
|
||||
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01,const typename MAT::elem_t& a_02 //1 row
|
||||
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11,const typename MAT::elem_t& a_12 //2 row
|
||||
,const typename MAT::elem_t& a_20,const typename MAT::elem_t& a_21,const typename MAT::elem_t& a_22 //3 row
|
||||
,TOOLS_MELEM a_00,TOOLS_MELEM a_01,TOOLS_MELEM a_02 //1 row
|
||||
,TOOLS_MELEM a_10,TOOLS_MELEM a_11,TOOLS_MELEM a_12 //2 row
|
||||
,TOOLS_MELEM a_20,TOOLS_MELEM a_21,TOOLS_MELEM a_22 //3 row
|
||||
){
|
||||
//a_<R><C>
|
||||
//vec[R + C * 3];
|
||||
@@ -496,10 +542,10 @@ inline void matrix_set(MAT& a_m
|
||||
////////////////////////////////////////////////
|
||||
template <class MAT>
|
||||
inline void matrix_set(MAT& a_m
|
||||
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01,const typename MAT::elem_t& a_02,const typename MAT::elem_t& a_03 //1 row
|
||||
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11,const typename MAT::elem_t& a_12,const typename MAT::elem_t& a_13 //2 row
|
||||
,const typename MAT::elem_t& a_20,const typename MAT::elem_t& a_21,const typename MAT::elem_t& a_22,const typename MAT::elem_t& a_23 //3 row
|
||||
,const typename MAT::elem_t& a_30,const typename MAT::elem_t& a_31,const typename MAT::elem_t& a_32,const typename MAT::elem_t& a_33 //4 row
|
||||
,TOOLS_MELEM a_00,TOOLS_MELEM a_01,TOOLS_MELEM a_02,TOOLS_MELEM a_03 //1 row
|
||||
,TOOLS_MELEM a_10,TOOLS_MELEM a_11,TOOLS_MELEM a_12,TOOLS_MELEM a_13 //2 row
|
||||
,TOOLS_MELEM a_20,TOOLS_MELEM a_21,TOOLS_MELEM a_22,TOOLS_MELEM a_23 //3 row
|
||||
,TOOLS_MELEM a_30,TOOLS_MELEM a_31,TOOLS_MELEM a_32,TOOLS_MELEM a_33 //4 row
|
||||
){
|
||||
//a_<R><C>
|
||||
//vec[R + C * 4];
|
||||
@@ -515,11 +561,11 @@ inline void matrix_set(MAT& a_m
|
||||
////////////////////////////////////////////////
|
||||
template <class MAT>
|
||||
inline void matrix_set(MAT& a_m
|
||||
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01,const typename MAT::elem_t& a_02,const typename MAT::elem_t& a_03,const typename MAT::elem_t& a_04 //1 row
|
||||
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11,const typename MAT::elem_t& a_12,const typename MAT::elem_t& a_13,const typename MAT::elem_t& a_14 //2 row
|
||||
,const typename MAT::elem_t& a_20,const typename MAT::elem_t& a_21,const typename MAT::elem_t& a_22,const typename MAT::elem_t& a_23,const typename MAT::elem_t& a_24 //3 row
|
||||
,const typename MAT::elem_t& a_30,const typename MAT::elem_t& a_31,const typename MAT::elem_t& a_32,const typename MAT::elem_t& a_33,const typename MAT::elem_t& a_34 //4 row
|
||||
,const typename MAT::elem_t& a_40,const typename MAT::elem_t& a_41,const typename MAT::elem_t& a_42,const typename MAT::elem_t& a_43,const typename MAT::elem_t& a_44 //5 row
|
||||
,TOOLS_MELEM a_00,TOOLS_MELEM a_01,TOOLS_MELEM a_02,TOOLS_MELEM a_03,TOOLS_MELEM a_04 //1 row
|
||||
,TOOLS_MELEM a_10,TOOLS_MELEM a_11,TOOLS_MELEM a_12,TOOLS_MELEM a_13,TOOLS_MELEM a_14 //2 row
|
||||
,TOOLS_MELEM a_20,TOOLS_MELEM a_21,TOOLS_MELEM a_22,TOOLS_MELEM a_23,TOOLS_MELEM a_24 //3 row
|
||||
,TOOLS_MELEM a_30,TOOLS_MELEM a_31,TOOLS_MELEM a_32,TOOLS_MELEM a_33,TOOLS_MELEM a_34 //4 row
|
||||
,TOOLS_MELEM a_40,TOOLS_MELEM a_41,TOOLS_MELEM a_42,TOOLS_MELEM a_43,TOOLS_MELEM a_44 //5 row
|
||||
){
|
||||
//a_<R><C>
|
||||
//vec[R + C * 5];
|
||||
@@ -536,12 +582,12 @@ inline void matrix_set(MAT& a_m
|
||||
////////////////////////////////////////////////
|
||||
template <class MAT>
|
||||
inline void matrix_set(MAT& a_m
|
||||
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01,const typename MAT::elem_t& a_02,const typename MAT::elem_t& a_03,const typename MAT::elem_t& a_04,const typename MAT::elem_t& a_05 //1 row
|
||||
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11,const typename MAT::elem_t& a_12,const typename MAT::elem_t& a_13,const typename MAT::elem_t& a_14,const typename MAT::elem_t& a_15 //2 row
|
||||
,const typename MAT::elem_t& a_20,const typename MAT::elem_t& a_21,const typename MAT::elem_t& a_22,const typename MAT::elem_t& a_23,const typename MAT::elem_t& a_24,const typename MAT::elem_t& a_25 //3 row
|
||||
,const typename MAT::elem_t& a_30,const typename MAT::elem_t& a_31,const typename MAT::elem_t& a_32,const typename MAT::elem_t& a_33,const typename MAT::elem_t& a_34,const typename MAT::elem_t& a_35 //4 row
|
||||
,const typename MAT::elem_t& a_40,const typename MAT::elem_t& a_41,const typename MAT::elem_t& a_42,const typename MAT::elem_t& a_43,const typename MAT::elem_t& a_44,const typename MAT::elem_t& a_45 //5 row
|
||||
,const typename MAT::elem_t& a_50,const typename MAT::elem_t& a_51,const typename MAT::elem_t& a_52,const typename MAT::elem_t& a_53,const typename MAT::elem_t& a_54,const typename MAT::elem_t& a_55 //6 row
|
||||
,TOOLS_MELEM a_00,TOOLS_MELEM a_01,TOOLS_MELEM a_02,TOOLS_MELEM a_03,TOOLS_MELEM a_04,TOOLS_MELEM a_05 //1 row
|
||||
,TOOLS_MELEM a_10,TOOLS_MELEM a_11,TOOLS_MELEM a_12,TOOLS_MELEM a_13,TOOLS_MELEM a_14,TOOLS_MELEM a_15 //2 row
|
||||
,TOOLS_MELEM a_20,TOOLS_MELEM a_21,TOOLS_MELEM a_22,TOOLS_MELEM a_23,TOOLS_MELEM a_24,TOOLS_MELEM a_25 //3 row
|
||||
,TOOLS_MELEM a_30,TOOLS_MELEM a_31,TOOLS_MELEM a_32,TOOLS_MELEM a_33,TOOLS_MELEM a_34,TOOLS_MELEM a_35 //4 row
|
||||
,TOOLS_MELEM a_40,TOOLS_MELEM a_41,TOOLS_MELEM a_42,TOOLS_MELEM a_43,TOOLS_MELEM a_44,TOOLS_MELEM a_45 //5 row
|
||||
,TOOLS_MELEM a_50,TOOLS_MELEM a_51,TOOLS_MELEM a_52,TOOLS_MELEM a_53,TOOLS_MELEM a_54,TOOLS_MELEM a_55 //6 row
|
||||
){
|
||||
//a_<R><C>
|
||||
//vec[R + C * 6];
|
||||
@@ -554,6 +600,40 @@ inline void matrix_set(MAT& a_m
|
||||
vec[5] = a_50;vec[11] = a_51;vec[17] = a_52;vec[23] = a_53;vec[29] = a_54;vec[35] = a_55;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
/// specific D=10 //////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
template <class MAT>
|
||||
inline void matrix_set(MAT& a_m
|
||||
,TOOLS_MELEM a_00,TOOLS_MELEM a_01,TOOLS_MELEM a_02,TOOLS_MELEM a_03,TOOLS_MELEM a_04,TOOLS_MELEM a_05,TOOLS_MELEM a_06,TOOLS_MELEM a_07,TOOLS_MELEM a_08,TOOLS_MELEM a_09 //1 row
|
||||
,TOOLS_MELEM a_10,TOOLS_MELEM a_11,TOOLS_MELEM a_12,TOOLS_MELEM a_13,TOOLS_MELEM a_14,TOOLS_MELEM a_15,TOOLS_MELEM a_16,TOOLS_MELEM a_17,TOOLS_MELEM a_18,TOOLS_MELEM a_19 //2 row
|
||||
,TOOLS_MELEM a_20,TOOLS_MELEM a_21,TOOLS_MELEM a_22,TOOLS_MELEM a_23,TOOLS_MELEM a_24,TOOLS_MELEM a_25,TOOLS_MELEM a_26,TOOLS_MELEM a_27,TOOLS_MELEM a_28,TOOLS_MELEM a_29 //3 row
|
||||
,TOOLS_MELEM a_30,TOOLS_MELEM a_31,TOOLS_MELEM a_32,TOOLS_MELEM a_33,TOOLS_MELEM a_34,TOOLS_MELEM a_35,TOOLS_MELEM a_36,TOOLS_MELEM a_37,TOOLS_MELEM a_38,TOOLS_MELEM a_39 //4 row
|
||||
,TOOLS_MELEM a_40,TOOLS_MELEM a_41,TOOLS_MELEM a_42,TOOLS_MELEM a_43,TOOLS_MELEM a_44,TOOLS_MELEM a_45,TOOLS_MELEM a_46,TOOLS_MELEM a_47,TOOLS_MELEM a_48,TOOLS_MELEM a_49 //5 row
|
||||
,TOOLS_MELEM a_50,TOOLS_MELEM a_51,TOOLS_MELEM a_52,TOOLS_MELEM a_53,TOOLS_MELEM a_54,TOOLS_MELEM a_55,TOOLS_MELEM a_56,TOOLS_MELEM a_57,TOOLS_MELEM a_58,TOOLS_MELEM a_59 //6 row
|
||||
,TOOLS_MELEM a_60,TOOLS_MELEM a_61,TOOLS_MELEM a_62,TOOLS_MELEM a_63,TOOLS_MELEM a_64,TOOLS_MELEM a_65,TOOLS_MELEM a_66,TOOLS_MELEM a_67,TOOLS_MELEM a_68,TOOLS_MELEM a_69 //7 row
|
||||
,TOOLS_MELEM a_70,TOOLS_MELEM a_71,TOOLS_MELEM a_72,TOOLS_MELEM a_73,TOOLS_MELEM a_74,TOOLS_MELEM a_75,TOOLS_MELEM a_76,TOOLS_MELEM a_77,TOOLS_MELEM a_78,TOOLS_MELEM a_79 //8 row
|
||||
,TOOLS_MELEM a_80,TOOLS_MELEM a_81,TOOLS_MELEM a_82,TOOLS_MELEM a_83,TOOLS_MELEM a_84,TOOLS_MELEM a_85,TOOLS_MELEM a_86,TOOLS_MELEM a_87,TOOLS_MELEM a_88,TOOLS_MELEM a_89 //9 row
|
||||
,TOOLS_MELEM a_90,TOOLS_MELEM a_91,TOOLS_MELEM a_92,TOOLS_MELEM a_93,TOOLS_MELEM a_94,TOOLS_MELEM a_95,TOOLS_MELEM a_96,TOOLS_MELEM a_97,TOOLS_MELEM a_98,TOOLS_MELEM a_99 //10 row
|
||||
|
||||
){
|
||||
//a_<R><C>
|
||||
//vec[R + C * 10];
|
||||
typename MAT::elem_t* vec = const_cast<typename MAT::elem_t*>(a_m.data());
|
||||
vec[0] = a_00;vec[10] = a_01;vec[20] = a_02;vec[30] = a_03;vec[40] = a_04;vec[50] = a_05;vec[60] = a_06;vec[70] = a_07;vec[80] = a_08;vec[90] = a_09;
|
||||
vec[1] = a_10;vec[11] = a_11;vec[21] = a_12;vec[31] = a_13;vec[41] = a_14;vec[51] = a_15;vec[61] = a_16;vec[71] = a_17;vec[81] = a_18;vec[91] = a_19;
|
||||
vec[2] = a_20;vec[12] = a_21;vec[22] = a_22;vec[32] = a_23;vec[42] = a_24;vec[52] = a_25;vec[62] = a_26;vec[72] = a_27;vec[82] = a_28;vec[92] = a_29;
|
||||
vec[3] = a_30;vec[13] = a_31;vec[23] = a_32;vec[33] = a_33;vec[43] = a_34;vec[53] = a_35;vec[63] = a_36;vec[73] = a_37;vec[83] = a_38;vec[93] = a_39;
|
||||
vec[4] = a_40;vec[14] = a_41;vec[24] = a_42;vec[34] = a_43;vec[44] = a_44;vec[54] = a_45;vec[64] = a_46;vec[74] = a_47;vec[84] = a_48;vec[94] = a_49;
|
||||
vec[5] = a_50;vec[15] = a_51;vec[25] = a_52;vec[35] = a_53;vec[45] = a_54;vec[55] = a_55;vec[65] = a_56;vec[75] = a_57;vec[85] = a_58;vec[95] = a_59;
|
||||
vec[6] = a_60;vec[16] = a_61;vec[26] = a_62;vec[36] = a_63;vec[46] = a_64;vec[56] = a_65;vec[66] = a_66;vec[76] = a_67;vec[86] = a_68;vec[96] = a_69;
|
||||
vec[7] = a_70;vec[17] = a_71;vec[27] = a_72;vec[37] = a_73;vec[47] = a_74;vec[57] = a_75;vec[67] = a_76;vec[77] = a_77;vec[87] = a_78;vec[97] = a_79;
|
||||
vec[8] = a_80;vec[18] = a_81;vec[28] = a_82;vec[38] = a_83;vec[48] = a_84;vec[58] = a_85;vec[68] = a_86;vec[78] = a_87;vec[88] = a_88;vec[98] = a_89;
|
||||
vec[9] = a_90;vec[19] = a_91;vec[29] = a_92;vec[39] = a_93;vec[49] = a_94;vec[59] = a_95;vec[69] = a_96;vec[79] = a_97;vec[89] = a_98;vec[99] = a_99;
|
||||
}
|
||||
|
||||
#undef TOOLS_MELEM
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
@@ -40,9 +40,7 @@ public:
|
||||
a_30,a_31,a_32,a_33);
|
||||
}
|
||||
public:
|
||||
void set_matrix(const mat4<T>& a_m){
|
||||
parent::set_matrix(a_m);
|
||||
}
|
||||
void set_matrix(const mat4<T>& a_m) {parent::set_matrix(a_m);}
|
||||
void set_matrix(
|
||||
const T& a_00,const T& a_01,const T& a_02,const T& a_03, //1 row
|
||||
const T& a_10,const T& a_11,const T& a_12,const T& a_13, //2 row
|
||||
@@ -57,15 +55,9 @@ public:
|
||||
pr::m_vec[3] = a_30;pr::m_vec[7] = a_31;pr::m_vec[11] = a_32;pr::m_vec[15] = a_33;
|
||||
}
|
||||
|
||||
void set_scale(const T& a_s) {
|
||||
_set_scale(a_s,a_s,a_s,pr::m_vec);
|
||||
}
|
||||
void set_scale(const T& a_1,const T& a_2,const T& a_3) {
|
||||
_set_scale(a_1,a_2,a_3,pr::m_vec);
|
||||
}
|
||||
void set_translate(const T& a_x,const T& a_y,const T& a_z) {
|
||||
_set_translate(a_x,a_y,a_z,pr::m_vec);
|
||||
}
|
||||
void set_scale(const T& a_s) {_set_scale(a_s,a_s,a_s,pr::m_vec);}
|
||||
void set_scale(const T& a_1,const T& a_2,const T& a_3) {_set_scale(a_1,a_2,a_3,pr::m_vec);}
|
||||
void set_translate(const T& a_x,const T& a_y,const T& a_z) {_set_translate(a_x,a_y,a_z,pr::m_vec);}
|
||||
void set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
|
||||
_set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec,a_sin,a_cos);
|
||||
}
|
||||
@@ -231,9 +223,7 @@ public:
|
||||
}
|
||||
|
||||
template <class VEC>
|
||||
void mul_dir_3(VEC& a_dir) const {
|
||||
mul_dir_3(a_dir[0],a_dir[1],a_dir[2]);
|
||||
}
|
||||
void mul_dir_3(VEC& a_dir) const {mul_dir_3(a_dir[0],a_dir[1],a_dir[2]);}
|
||||
|
||||
void mul_scale(const T& a_sx,const T& a_sy,const T& a_sz) {
|
||||
// this = this * mat4_scale(a_s[x,y,z]
|
||||
@@ -361,6 +351,7 @@ protected:
|
||||
|
||||
static void _set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T v[],T(*a_sin)(T),T(*a_cos)(T)) {
|
||||
//WARNING : (a_x,a_y,a_z) must be a normalized vector.
|
||||
// v[] = exp(-a_angle*n(a_x,a_y,a_z)*Rs). It models the rotation of an object in the same coordinate system (active rotation).
|
||||
T si = a_sin(a_angle);
|
||||
T co = a_cos(a_angle);
|
||||
T x = a_x;
|
||||
@@ -389,7 +380,7 @@ protected:
|
||||
//
|
||||
// R(r,c) = cos(theta)*Id(r,c)+(1-cos(theta))*nr*nc-sin(theta)*(n.E)(r,c)
|
||||
//
|
||||
// R = exp(-theta*(n.E))
|
||||
// R = exp(-theta*(n.E)) // active rotation (it models the rotation of an object by theta along n).
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
}
|
||||
public:
|
||||
void set_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
|
||||
//WARNING : (a_x,a_y,a_z) must be a normalized vector.
|
||||
parent::set_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
|
||||
}
|
||||
void mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
|
||||
@@ -45,6 +46,13 @@ public:
|
||||
void left_mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
|
||||
parent::left_mul_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
|
||||
}
|
||||
|
||||
template <class VEC>
|
||||
void set_rotate(const VEC& a_dir,float a_angle) {
|
||||
//WARNING : a_dir must be a normalized vector.
|
||||
parent::set_rotate(a_dir[0],a_dir[1],a_dir[2],a_angle,::sinf,::cosf);
|
||||
}
|
||||
|
||||
public: //backward compatibility
|
||||
void mul_2f(float& a_x,float& a_y) const {parent::mul_2(a_x,a_y);}
|
||||
void mul_3f(float& a_x,float& a_y,float& a_z) const {parent::mul_3(a_x,a_y,a_z);}
|
||||
|
||||
@@ -123,6 +123,8 @@ public:
|
||||
|
||||
bool set_value(const VEC3& a_from,const VEC3& a_to,T(*a_sqrt)(T),T(*a_fabs)(T)) {
|
||||
// code taken from coin3d/SbRotation.
|
||||
//NOTE : coin3d/SbMatrix logic is transposed relative to us.
|
||||
|
||||
VEC3 from(a_from);
|
||||
if(from.normalize()==T()) return false;
|
||||
VEC3 to(a_to);
|
||||
@@ -163,16 +165,16 @@ public:
|
||||
|
||||
bool value(VEC3& a_axis,T& a_radians,T(*a_sin)(T),T(*a_acos)(T)) const { //WARNING a_acos and NOT a_cos
|
||||
//WARNING : can fail.
|
||||
if( (m_quat.v3()<minus_one()) || (m_quat.v3()> one()) ){ ////???
|
||||
if( (m_quat.v3()<minus_one()) || (m_quat.v3()> one()) ) {
|
||||
a_axis.set_value(0,0,1);
|
||||
a_radians = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
a_radians = a_acos(m_quat.v3()) * 2;
|
||||
a_radians = a_acos(m_quat.v3()) * 2; //in [0,2*pi]
|
||||
T sineval = a_sin(a_radians/2);
|
||||
|
||||
if(sineval==T()) { //???
|
||||
if(sineval==T()) { //a_radian = 0 or 2*pi.
|
||||
a_axis.set_value(0,0,1);
|
||||
a_radians = 0;
|
||||
return false;
|
||||
@@ -183,10 +185,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
template <class MAT4>
|
||||
void set_value(const MAT4& a_m,T(*a_sqrt)(T)) {
|
||||
//WARNING : not tested.
|
||||
// See tests/qrot.icc.
|
||||
// code taken from coin3d/SbRotation.
|
||||
|
||||
//Set the rotation from the components of the given matrix.
|
||||
|
||||
@@ -196,9 +198,9 @@ public:
|
||||
m_quat.v3(_s * half());
|
||||
_s = half() / _s;
|
||||
|
||||
m_quat.v0((a_m.v12() - a_m.v21()) * _s);
|
||||
m_quat.v1((a_m.v20() - a_m.v02()) * _s);
|
||||
m_quat.v2((a_m.v01() - a_m.v10()) * _s);
|
||||
m_quat.v0((a_m.v21() - a_m.v12()) * _s);
|
||||
m_quat.v1((a_m.v02() - a_m.v20()) * _s);
|
||||
m_quat.v2((a_m.v10() - a_m.v01()) * _s);
|
||||
} else {
|
||||
unsigned int i = 0;
|
||||
if (a_m.v11() > a_m.v00()) i = 1;
|
||||
@@ -212,26 +214,27 @@ public:
|
||||
m_quat.set_value(i,_s * half());
|
||||
_s = half() / _s;
|
||||
|
||||
m_quat.v3((a_m.value(j,k) - a_m.value(k,j)) * _s);
|
||||
m_quat.set_value(j,(a_m.value(i,j) + a_m.value(j,i)) * _s);
|
||||
m_quat.set_value(k,(a_m.value(i,k) + a_m.value(k,i)) * _s);
|
||||
m_quat.v3((a_m.value(k,j) - a_m.value(j,k)) * _s);
|
||||
m_quat.set_value(j,(a_m.value(j,i) + a_m.value(i,j)) * _s);
|
||||
m_quat.set_value(k,(a_m.value(k,i) + a_m.value(i,k)) * _s);
|
||||
}
|
||||
|
||||
if (a_m.v33()!=one()) {
|
||||
m_quat.multiply(one()/a_sqrt(a_m.v33()));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
template <class MAT4>
|
||||
void value(MAT4& a_m) const {
|
||||
//Return this rotation in the form of a matrix.
|
||||
//NOTE : in coin3d/SbRotation, it looks as if "w <-> -w", but coin3d/SbMatrix logic is transposed relative to us.
|
||||
|
||||
const T x = m_quat.v0();
|
||||
const T y = m_quat.v1();
|
||||
const T z = m_quat.v2();
|
||||
const T w = m_quat.v3();
|
||||
// z = w + x * i + y * j + z * k
|
||||
|
||||
// q = w + x * i + y * j + z * k
|
||||
|
||||
// first row :
|
||||
a_m.v00(w*w + x*x - y*y - z*z);
|
||||
a_m.v01(2*x*y - 2*w*z);
|
||||
|
||||
@@ -45,11 +45,12 @@ public:
|
||||
bool set_value(const vec3f& a_from,float a_a){
|
||||
return parent::set_value(a_from,a_a,::sinf,::cosf);
|
||||
}
|
||||
bool value(vec3f& a_from,float a_a) const {
|
||||
bool value(vec3f& a_from,float& a_a) const {
|
||||
return parent::value(a_from,a_a,::sinf,::acosf); //WARNING acos and not cos
|
||||
}
|
||||
//void set_value(const mat4f& a_m) {parent::set_value(a_m,::sqrtf);}
|
||||
|
||||
void value(mat4f& a_m) const {parent::value(a_m);}
|
||||
void set_value(const mat4f& a_m) {parent::set_value(a_m,::sqrtf);}
|
||||
|
||||
//NOTE : don't handle a static object because of mem balance.
|
||||
//static const rotf& identity() {
|
||||
|
||||
@@ -196,16 +196,16 @@ public:
|
||||
m_data[2] -= a2;
|
||||
}
|
||||
|
||||
/*
|
||||
bool cos_angle(const vec3& a_v,T& a_cos) const {
|
||||
bool cos_angle(const vec3& a_v,T& a_cos,T(*a_sqrt)(T)) const {
|
||||
//WARNING : if ret false, a_cos is not set.
|
||||
if(length()==T()) return false;
|
||||
if(a_v.length()==T()) return false;
|
||||
a_cos = dot(a_v)/(length()*a_v.length());
|
||||
T this_length = length(a_sqrt);
|
||||
if(this_length==T()) return false;
|
||||
T a_v_length = a_v.length(a_sqrt);
|
||||
if(a_v_length==T()) return false;
|
||||
a_cos = dot(a_v)/(this_length*a_v_length);
|
||||
return true;
|
||||
}
|
||||
|
||||
*/
|
||||
bool theta_phi(T& a_theta,T& a_phi,T(*a_sqrt)(T),T(*a_atan2)(T,T)) const {
|
||||
//WARNING : if ret false, a_theta, a_phi are not set.
|
||||
if(length(a_sqrt)==T()) return false;
|
||||
|
||||
@@ -68,6 +68,35 @@ public: //operators
|
||||
public:
|
||||
double length() const {return parent::length(::sqrt);}
|
||||
double normalize() {return parent::normalize(::sqrt);}
|
||||
public: //for g4dum/G4ThreeVector :
|
||||
double mag2() const {return m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2];}
|
||||
void set(double a_0,double a_1,double a_2) {
|
||||
m_data[0] = a_0;
|
||||
m_data[1] = a_1;
|
||||
m_data[2] = a_2;
|
||||
}
|
||||
void rotateUz(const vec3d& a_new_uz_vector) { //from CLHEP/ThreeVector.cc.
|
||||
// a_new_uz_vector must be normalized !
|
||||
double& dx = m_data[0];
|
||||
double& dy = m_data[1];
|
||||
double& dz = m_data[2];
|
||||
double u1 = a_new_uz_vector.x();
|
||||
double u2 = a_new_uz_vector.y();
|
||||
double u3 = a_new_uz_vector.z();
|
||||
double up = u1*u1 + u2*u2;
|
||||
if (up>0) {
|
||||
up = std::sqrt(up);
|
||||
double px = dx, py = dy, pz = dz;
|
||||
dx = (u1*u3*px - u2*py)/up + u1*pz;
|
||||
dy = (u2*u3*px + u1*py)/up + u2*pz;
|
||||
dz = -up*px + u3*pz;
|
||||
} else if (u3 < 0.) { // phi=0 teta=pi
|
||||
dx = -dx; dz = -dz;
|
||||
} else {
|
||||
}
|
||||
//return *this;
|
||||
}
|
||||
|
||||
|
||||
private:static void check_instantiation() {vec3d v(0,0,0);v.set_value(1,1,1);}
|
||||
};
|
||||
|
||||
@@ -77,9 +77,19 @@ public:
|
||||
divide(norme);
|
||||
return norme;
|
||||
}
|
||||
bool cos_angle(const vec3f& a_v,float& a_cos) const {
|
||||
//WARNING : if ret false, a_cos is not set.
|
||||
float this_length = length();
|
||||
if(this_length==0.0f) return false;
|
||||
float a_v_length = a_v.length();
|
||||
if(a_v_length==0.0f) return false;
|
||||
a_cos = dot(a_v)/(this_length*a_v_length);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
float length() const {return parent::length(::sqrtf);}
|
||||
float normalize() {return parent::normalize(::sqrtf);}
|
||||
bool cos_angle(const vec3f& a_v,float& a_cos) const {return parent::cos_angle(a_v,a_cos,::sqrtf);}
|
||||
#endif
|
||||
|
||||
bool theta_phi(float& a_theta,float& a_phi) const {
|
||||
|
||||
@@ -92,9 +92,10 @@ public:
|
||||
void v2(const T& a_value) { m_data[2] = a_value;}
|
||||
void v3(const T& a_value) { m_data[3] = a_value;}
|
||||
|
||||
//T x() const {return m_data[0];}
|
||||
//T y() const {return m_data[1];}
|
||||
//T z() const {return m_data[2];}
|
||||
const T& x() const { return m_data[0];}
|
||||
const T& y() const { return m_data[1];}
|
||||
const T& z() const { return m_data[2];}
|
||||
const T& t() const { return m_data[3];}
|
||||
|
||||
void set_value(const T& a0,const T& a1,const T& a2,const T& a3) {
|
||||
m_data[0] = a0;
|
||||
|
||||
@@ -67,6 +67,20 @@ inline void copy(std::map<K,V*>& a_to,const std::map<K,V*>& a_from){
|
||||
}
|
||||
}
|
||||
|
||||
template <class K,class V>
|
||||
inline bool add_unique(std::map<K,V*>& a_map,const K& a_key,V* a_value,bool a_delete) {
|
||||
typedef typename std::map<K,V*>::iterator it_t;
|
||||
it_t it = a_map.find(a_key);
|
||||
if(it==a_map.end()) {a_map[a_key] = a_value;return false;} //false=was not found.
|
||||
if(a_delete) {
|
||||
V* entry = (*it).second;
|
||||
a_map.erase(it);
|
||||
delete entry;
|
||||
}
|
||||
a_map[a_key] = a_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class K,class V>
|
||||
inline bool find(const std::map<K,V>& a_map,const K& a_key,V& a_value) {
|
||||
typedef typename std::map<K,V>::const_iterator it_t;
|
||||
@@ -76,6 +90,14 @@ inline bool find(const std::map<K,V>& a_map,const K& a_key,V& a_value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class K,class V>
|
||||
inline bool is_key(const std::map<K,V>& a_map,const K& a_key) {
|
||||
typedef typename std::map<K,V>::const_iterator it_t;
|
||||
it_t it = a_map.find(a_key);
|
||||
if(it==a_map.end()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -57,10 +57,28 @@ inline double angle_modulo(double a_angle) {
|
||||
|
||||
namespace tools {
|
||||
|
||||
inline double dcos(const double& a_x) {return ::cos(a_x);}
|
||||
inline double dsin(const double& a_x) {return ::sin(a_x);}
|
||||
inline double dpow(const double& a_x,const double& a_y) {return ::pow(a_x,a_y);}
|
||||
|
||||
inline double dconj(const double& a_x) {return a_x;}
|
||||
inline double dfabs(const double& a_x) {return ::fabs(a_x);} //if passing a_fabs(const T&).
|
||||
inline double dsqrt(const double& a_x) {return ::sqrt(a_x);}
|
||||
|
||||
//long double
|
||||
#ifndef ANDROID
|
||||
inline long double ldfabs(const long double& a_x) {return ::fabsl(a_x);}
|
||||
#endif
|
||||
|
||||
inline bool dpow(const double& a_x,const double& a_y,double& a_v) {
|
||||
if((a_x==0)&&(a_y<0)) {
|
||||
a_v = 0;
|
||||
return false;
|
||||
}
|
||||
a_v = dpow(a_x,a_y);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
public: //for MT disconnection (see test/mt_root_ntuple.cpp).
|
||||
static int& counter() {
|
||||
static int s_count = 0;
|
||||
return s_count;
|
||||
@@ -103,6 +104,7 @@ protected:
|
||||
static bool s_check_by_class = false;
|
||||
return s_check_by_class;
|
||||
}
|
||||
protected:
|
||||
|
||||
typedef std::list< std::pair<std::string,int> > mem_list;
|
||||
|
||||
|
||||
@@ -69,6 +69,12 @@ public:
|
||||
m_columns.push_back(column_binding(a_name,_cid_std_vector<T>(),(void*)&a_user_var));
|
||||
}
|
||||
|
||||
// to have consistent naming than in ntuple_booking :
|
||||
template <class T>
|
||||
void add_column_vec(const std::string& a_name,std::vector<T>& a_user_var) {
|
||||
m_columns.push_back(column_binding(a_name,_cid_std_vector<T>(),(void*)&a_user_var));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void add_column_cid(const std::string& a_name,T& a_user_var) {
|
||||
m_columns.push_back(column_binding(a_name,T::id_class(),(void*)&a_user_var));
|
||||
|
||||
@@ -70,14 +70,18 @@ public:
|
||||
void add_column(const std::string& a_name) {
|
||||
m_columns.push_back(column_booking(a_name,_cid(T()),0));
|
||||
}
|
||||
template <class T>
|
||||
void add_column(const std::string& a_name,T& a_user) {
|
||||
m_columns.push_back(column_booking(a_name,_cid(T()),(void*)&a_user));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void add_column_vec(const std::string& a_name) {
|
||||
m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),0));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void add_column(const std::string& a_name,T& a_user) {
|
||||
m_columns.push_back(column_booking(a_name,_cid(T()),(void*)&a_user));
|
||||
void add_column_vec(const std::string& a_name,std::vector<T>& a_user_vec) {
|
||||
m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),(void*)&a_user_vec));
|
||||
}
|
||||
template <class T>
|
||||
void add_column(const std::string& a_name,std::vector<T>& a_user_vec) {
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "sprintf"
|
||||
#include "typedefs"
|
||||
|
||||
#include <cstddef> //ptrdiff_t
|
||||
|
||||
namespace tools {
|
||||
|
||||
/*
|
||||
@@ -59,6 +61,22 @@ inline bool num2s(double a_value,std::string& a_s){
|
||||
return print2s(a_s,32,"%g",a_value);
|
||||
}
|
||||
|
||||
inline bool size_t2s(size_t a_value,std::string& a_s) {
|
||||
if(sizeof(size_t)==8) {
|
||||
return num2s((uint64)a_value,a_s);
|
||||
} else { //assume 4 :
|
||||
return num2s((uint32)a_value,a_s);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool ptrdiff_t2s(ptrdiff_t a_value,std::string& a_s) { //used in write_bsg.
|
||||
if(sizeof(ptrdiff_t)==8) {
|
||||
return num2s((int64)a_value,a_s);
|
||||
} else { //assume 4 :
|
||||
return num2s((int32)a_value,a_s);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
inline bool num2s(bool a_value,std::string& a_s){
|
||||
//a_s = a_value?"true":"false";
|
||||
@@ -75,6 +93,14 @@ inline bool numas(const T& a_value,std::string& a_s){
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool size_tas(const T& a_value,std::string& a_s){
|
||||
std::string stmp;
|
||||
if(!size_t2s(a_value,stmp)) return false;
|
||||
a_s += stmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
inline bool num2s(unsigned int a_linen,const char* a_lines[],std::string& a_s) {
|
||||
a_s.clear();
|
||||
@@ -86,7 +112,7 @@ inline bool num2s(unsigned int a_linen,const char* a_lines[],std::string& a_s) {
|
||||
}
|
||||
*/
|
||||
|
||||
// for the below std::vector num2s in cast T=std::string :
|
||||
// for the below std::vector num2s in case T=std::string :
|
||||
inline bool num2s(const std::string& a_value,std::string& a_s){a_s = a_value;return true;}
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_paper_format
|
||||
#define tools_paper_format
|
||||
|
||||
#include "path"
|
||||
#include "touplow"
|
||||
|
||||
namespace tools {
|
||||
namespace file {
|
||||
|
||||
// file::paper_format_extension() is in file_format.
|
||||
// related files : sg/write_paper.
|
||||
|
||||
inline bool extension_paper_format(const std::string& a_file,std::string& a_fmt) {
|
||||
std::string path,name,suffix;
|
||||
if(!path_name_suffix(a_file,path,name,suffix)) {a_fmt.clear();return false;}
|
||||
tolowercase(suffix);
|
||||
if((suffix=="ps")||(suffix=="eps")) {
|
||||
a_fmt = "inzb_ps";
|
||||
return true;
|
||||
} else if(suffix=="png") {
|
||||
a_fmt = "inzb_png";
|
||||
return true;
|
||||
} else if((suffix=="jpg")||(suffix=="jpeg")) {
|
||||
a_fmt = "inzb_jpeg";
|
||||
return true;
|
||||
|
||||
} else if(suffix=="pdf") {
|
||||
a_fmt = "gl2ps_pdf";
|
||||
return true;
|
||||
} else if(suffix=="svg") {
|
||||
a_fmt = "gl2ps_svg";
|
||||
return true;
|
||||
} else if(suffix=="pgf") {
|
||||
a_fmt = "gl2ps_pgf";
|
||||
return true;
|
||||
} else if(suffix=="tex") {
|
||||
a_fmt = "gl2ps_tex";
|
||||
return true;
|
||||
}
|
||||
a_fmt.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,6 +34,23 @@ inline void nosuffix(const std::string& a_string,std::string& a_value,bool a_bac
|
||||
}
|
||||
}
|
||||
|
||||
inline void path_no_suffix(const std::string& a_string,std::string& a_value){
|
||||
// If a_string = dir0/dir1/dir2/dir3/name.xxx
|
||||
// a_value = dir0/dir1/dir2/dir3/name
|
||||
std::string::size_type dot_pos = a_string.rfind('.');
|
||||
if(dot_pos==std::string::npos) {
|
||||
a_value = a_string;
|
||||
} else {
|
||||
a_value = a_string.substr(0,dot_pos);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool has_dir(const std::string& a_string){
|
||||
if(a_string.rfind('/')!=std::string::npos) return true;
|
||||
if(a_string.rfind('\\')!=std::string::npos) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void base_name(const std::string& a_path,std::string& a_value) {
|
||||
std::string::size_type pos_slash = a_path.rfind('/');
|
||||
std::string::size_type pos_bslash = a_path.rfind('\\');
|
||||
@@ -60,6 +77,14 @@ inline void base_name(const std::string& a_path,std::string& a_value) {
|
||||
a_value = a_path.substr(pos,a_path.size()-pos);
|
||||
}
|
||||
|
||||
//inline bool first_word(const std::string& a_string,std::string& a_value) {
|
||||
// if(a_string.empty()) {a_value.clear();return false;}
|
||||
// std::string::size_type pos = a_string.find(' ');
|
||||
// if(pos==std::string::npos) {a_value = a_string;return true;}
|
||||
// a_value = a_string.substr(0,pos);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
inline std::string suffix(const std::string& a_string,bool a_back = true) {
|
||||
std::string value;
|
||||
suffix(a_string,value,a_back);
|
||||
@@ -112,6 +137,18 @@ inline bool path_name_suffix(const std::string& a_string,std::string& a_path,std
|
||||
// a_path = ".."
|
||||
// a_name.clear()
|
||||
// a_suffix.clear()
|
||||
// If a_string = dir0/dir1/dir2/dir3/
|
||||
// a_path = dir0/dir1/dir2/dir3
|
||||
// a_name.clear()
|
||||
// a_suffix.clear()
|
||||
// If a_string = dir0/dir1/dir2/dir3/.
|
||||
// a_path = dir0/dir1/dir2/dir3
|
||||
// a_name = "."
|
||||
// a_suffix.clear()
|
||||
// If a_string = dir0/dir1/dir2/dir3/..
|
||||
// a_path = dir0/dir1/dir2/dir3
|
||||
// a_name = ".."
|
||||
// a_suffix.clear()
|
||||
if(a_string==".") {
|
||||
a_path = ".";
|
||||
a_name.clear();
|
||||
@@ -178,6 +215,13 @@ inline std::string dir_name(const std::string& a_path,unsigned int a_num = 1){
|
||||
return path;
|
||||
}
|
||||
|
||||
inline void quote(std::string& a_path) {
|
||||
if(a_path.find(' ')==std::string::npos) return;
|
||||
// path with spaces :
|
||||
if(a_path[0]=='"') return; //Already in double quote.
|
||||
a_path = std::string("\"")+a_path+"\"";
|
||||
}
|
||||
|
||||
//used in OpenPAW, BatchLab.
|
||||
inline bool is_f77(const std::string& a_path){
|
||||
std::string sfx = suffix(a_path);
|
||||
@@ -213,6 +257,20 @@ inline bool is_cpp(const std::string& a_path){
|
||||
return false;
|
||||
}
|
||||
|
||||
//used in OpenPAW, BatchLab.
|
||||
inline bool is_python(const std::string& a_path){
|
||||
std::string sfx = suffix(a_path);
|
||||
|
||||
//tolowercase(sfx);
|
||||
for(std::string::iterator it=sfx.begin();it!=sfx.end();++it) {
|
||||
char c = *it;
|
||||
*it = ((c) >= 'A' && (c) <= 'Z' ? c - 'A' + 'a' : c);
|
||||
}
|
||||
|
||||
if(sfx=="py") return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -79,7 +79,7 @@ inline unsigned int tex_mem_limit() {
|
||||
} else {
|
||||
//limit = 4096*4096*3; //=8192*2048 //permit to pass ATLAS big image.
|
||||
//permit to pass fete_science_2010/power2/image_0.jpg
|
||||
return 8192*4096*3;
|
||||
return 8192*4096*3; //100663296
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +116,14 @@ inline const char* os() {
|
||||
return s_s;
|
||||
}
|
||||
|
||||
inline bool _WIN32_defined() {
|
||||
#ifdef _WIN32
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline const char* processor() {
|
||||
|
||||
#if defined(__GNUC__)
|
||||
@@ -175,9 +183,8 @@ inline const char* compiler_name() {
|
||||
|
||||
namespace tools {
|
||||
|
||||
inline char* compiler() {
|
||||
static char s_s[128];
|
||||
char* pos = s_s;
|
||||
inline void compiler(char a_s[128]) {
|
||||
char* pos = a_s;
|
||||
unsigned int l;
|
||||
toss(compiler_name(),pos,l);pos += l;
|
||||
|
||||
@@ -200,7 +207,6 @@ inline char* compiler() {
|
||||
#else
|
||||
#endif
|
||||
*pos = 0;
|
||||
return s_s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
//proxies to have less verbose user programming :
|
||||
|
||||
//WARNING : the plotter must have at least 1x1 plotting area,
|
||||
// else the below will crash because current_plotter()
|
||||
// will return a null pointer.
|
||||
|
||||
tools::sg::plots& plots() {return m_plots;}
|
||||
const tools::sg::plots& plots() const {return m_plots;}
|
||||
|
||||
void next() {m_plots.next();}
|
||||
bool set_current_plotter(unsigned int a_index) {return m_plots.set_current_plotter(a_index);}
|
||||
|
||||
void add_plottable(tools::sg::plottable* a_plottable) {
|
||||
m_plots.current_plotter().add_plottable(a_plottable); //it takes ownership.
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot(const tools::histo::h1d& a_histo) {
|
||||
//tools::sg::plottable* p = new tools::sg::h1d2plot<tools::histo::h1d>(a_histo);
|
||||
tools::sg::plottable* p = new tools::sg::h1d2plot(a_histo);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot(const tools::histo::h2d& a_histo) {
|
||||
//tools::sg::plottable* p = new tools::sg::h2d2plot<tools::histo::h2d>(a_histo);
|
||||
tools::sg::plottable* p = new tools::sg::h2d2plot(a_histo);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot(const tools::histo::p1d& a_histo) {
|
||||
tools::sg::plottable* p = new tools::sg::p1d2plot(a_histo);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot(const tools::histo::c2d& a_cloud) {
|
||||
tools::sg::plottable* p = new tools::sg::c2d2plot(a_cloud);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot(const tools::histo::c3d& a_cloud) {
|
||||
tools::sg::plottable* p = new tools::sg::c3d2plot(a_cloud);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot_cp(const tools::histo::h1d& a_histo) {
|
||||
//tools::sg::plottable* p = new tools::sg::h1d2plot_cp<tools::histo::h1d>(a_histo);
|
||||
tools::sg::plottable* p = new tools::sg::h1d2plot_cp(a_histo);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot_cp(const tools::histo::h2d& a_histo) {
|
||||
//tools::sg::plottable* p = new tools::sg::h2d2plot_cp<tools::histo::h2d>(a_histo);
|
||||
tools::sg::plottable* p = new tools::sg::h2d2plot_cp(a_histo);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot_cp(const tools::histo::p1d& a_histo) {
|
||||
tools::sg::plottable* p = new tools::sg::p1d2plot_cp(a_histo);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
//tools::sg::plottable* plot(const tools::histo::p2d& a_histo) {
|
||||
// tools::sg::plottable* p = new tools::sg::p2d2plot(a_histo);
|
||||
// m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
// return p;
|
||||
//}
|
||||
|
||||
tools::sg::plottable* plot_cp(const tools::histo::c2d& a_cloud) {
|
||||
tools::sg::plottable* p = new tools::sg::c2d2plot_cp(a_cloud);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot_cp(const tools::histo::c3d& a_cloud) {
|
||||
tools::sg::plottable* p = new tools::sg::c3d2plot_cp(a_cloud);
|
||||
m_plots.current_plotter().add_plottable(p); //it takes ownership.
|
||||
return p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
tools::sg::plottable* plot(const T& a_func) {
|
||||
tools::sg::plottable* p = new tools::sg::f1d2plot<T>(a_func);
|
||||
m_plots.current_plotter().add_plottable(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
tools::sg::plottable* plot(const std::vector<T>& a_xs,const std::vector<T>& a_ys) {
|
||||
tools::sg::plottable* p = new tools::sg::xy2plot<T>(a_xs,a_ys);
|
||||
m_plots.current_plotter().add_plottable(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
tools::sg::plottable* plot_fit(const std::vector<std::string>& a_names,const std::vector<double>& a_output) {
|
||||
tools::sg::plottable* p = new tools::sg::fit2plot(a_names,a_output);
|
||||
m_plots.current_plotter().add_plottable(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,490 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_png
|
||||
#define tools_png
|
||||
|
||||
#include <cstdio> //FILE,size_t
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <tools/sout>
|
||||
#include <tools/mnmx>
|
||||
|
||||
#ifdef TOOLS_USE_NATIVE_PNG
|
||||
#include <png.h>
|
||||
#else
|
||||
#include <ourex_png.h> //enforce ourex png
|
||||
#endif
|
||||
|
||||
namespace tools {
|
||||
namespace png {
|
||||
|
||||
inline bool is(const std::string& a_file){
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) return false; //if file does not exist, then it is not a png !
|
||||
png_byte header[8]; // 8 is the maximum size that can be checked
|
||||
size_t nitem = ::fread(header,1,8,file);
|
||||
::fclose(file);
|
||||
if(nitem!=8) return false;
|
||||
return ::png_sig_cmp(header,0,8)?false:true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tools {
|
||||
namespace png {
|
||||
|
||||
inline unsigned char* read_FILE(FILE* a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
|
||||
png_byte header[8]; // 8 is the maximum size that can be checked
|
||||
if(::fread(header,1,8,a_file)!=8) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
if(::png_sig_cmp(header,0,8)) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_structp png_ptr =
|
||||
::png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
|
||||
if(!png_ptr) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_infop info_ptr = ::png_create_info_struct(png_ptr);
|
||||
if(!info_ptr) {
|
||||
::png_destroy_read_struct(&png_ptr,NULL,NULL);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(::setjmp(png_jmpbuf(png_ptr))) {
|
||||
::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
::png_init_io(png_ptr,a_file);
|
||||
::png_set_sig_bytes(png_ptr,8);
|
||||
|
||||
::png_read_info(png_ptr,info_ptr);
|
||||
|
||||
int width = info_ptr->width;
|
||||
int height = info_ptr->height;
|
||||
int bpp = info_ptr->width?info_ptr->rowbytes/info_ptr->width:0;
|
||||
|
||||
if((width<=0)||(height<=0)||(bpp<=0)) {
|
||||
::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
a_bpp = bpp; //avoid the clobbered -W warning.
|
||||
|
||||
//png_byte color_type = info_ptr->color_type;
|
||||
//info_ptr->bit_depth;
|
||||
|
||||
//int number_of_passes = ::png_set_interlace_handling(png_ptr);
|
||||
::png_read_update_info(png_ptr,info_ptr);
|
||||
|
||||
if(::setjmp(png_jmpbuf(png_ptr))) {
|
||||
::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char* buffer = new unsigned char[info_ptr->rowbytes * height];
|
||||
if(!buffer) {
|
||||
::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
|
||||
a_height = 0;
|
||||
a_width = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
{png_bytep* row_pointers = new png_bytep[height];
|
||||
png_byte* pos = buffer+info_ptr->rowbytes*(height-1);
|
||||
for(int y=0;y<height;y++) {
|
||||
row_pointers[y] = pos;
|
||||
pos -= info_ptr->rowbytes;
|
||||
}
|
||||
::png_read_image(png_ptr,row_pointers);
|
||||
delete [] row_pointers;}
|
||||
|
||||
::png_read_end(png_ptr,info_ptr);
|
||||
|
||||
::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
|
||||
|
||||
a_width = width;
|
||||
a_height = height;
|
||||
//a_bpp = bpp; //avoid the clobbered -W warning.
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline unsigned char* read(std::ostream& a_out,const std::string& a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
//a_bpp = number of bytes per pixel.
|
||||
FILE* file = fopen(a_file.c_str(),"rb");
|
||||
if(!file) {
|
||||
a_out << "tools::png::read :"
|
||||
<< " can't open file " << tools::sout(a_file) << "."
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return 0;
|
||||
}
|
||||
unsigned char* buffer = read_FILE(file,a_width,a_height,a_bpp);
|
||||
if(!buffer) {
|
||||
::fclose(file);
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
a_out << "tools::png::read :"
|
||||
<< " read_FILE " << tools::sout(a_file) << " failed."
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
::fclose(file);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
inline unsigned char* read_part(std::ostream& a_out,
|
||||
const std::string& a_file,
|
||||
unsigned int a_sx,unsigned int a_sy,
|
||||
unsigned int a_sw,unsigned int a_sh,
|
||||
unsigned int& a_rw,unsigned int& a_rh,
|
||||
unsigned int& a_rbpp) {
|
||||
a_out << "tools::png::read_part :"
|
||||
<< " not yet implemented."
|
||||
<< std::endl;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
|
||||
unsigned int w,h,bpp;
|
||||
unsigned char* buffer = read(a_out,a_file,w,h,bpp);
|
||||
if(!buffer){
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((a_sx>=w)||(a_sy>=h)){
|
||||
delete [] buffer;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 012345
|
||||
a_rw = tools::mn<unsigned int>(w-a_sx,a_sw);
|
||||
a_rh = tools::mn<unsigned int>(h-a_sy,a_sh);
|
||||
a_rbpp = bpp;
|
||||
|
||||
if(!a_rw||!a_rh||!a_rbpp){
|
||||
delete [] buffer;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char* rb = new unsigned char[a_rw*a_rh*a_rbpp];
|
||||
if(!rb) {
|
||||
delete [] buffer;
|
||||
a_rw = 0;
|
||||
a_rh = 0;
|
||||
a_rbpp = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int rstride = a_rw * a_rbpp;
|
||||
unsigned char* rpos = rb;
|
||||
|
||||
unsigned int stride = w * bpp;
|
||||
unsigned char* pos = buffer+a_sy*stride+a_sx*bpp;
|
||||
|
||||
for(unsigned int j=0;j<a_rh;j++,rpos+=rstride,pos+=stride) {//j=0 -> bottom.
|
||||
::memcpy(rpos,pos,rstride);
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
return rb;
|
||||
}
|
||||
|
||||
inline bool write_FILE(FILE* a_file,unsigned char* a_buffer,unsigned int a_width,unsigned int a_height,unsigned int a_bpp) {
|
||||
//from gl2ps.c.
|
||||
if((a_bpp!=3)&&(a_bpp!=4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
png_structp png_ptr;
|
||||
if(!(png_ptr = ::png_create_write_struct
|
||||
(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL))) return false;
|
||||
|
||||
png_infop info_ptr;
|
||||
if(!(info_ptr = ::png_create_info_struct(png_ptr))){
|
||||
::png_destroy_write_struct(&png_ptr,NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(::setjmp(png_ptr->jmpbuf)) {
|
||||
::png_destroy_write_struct(&png_ptr,&info_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
::png_init_io(png_ptr,a_file);
|
||||
::png_set_compression_level(png_ptr,Z_DEFAULT_COMPRESSION);
|
||||
::png_set_IHDR(png_ptr,info_ptr,a_width,a_height,8,
|
||||
a_bpp==3?PNG_COLOR_TYPE_RGB:PNG_COLOR_TYPE_RGBA,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE,PNG_FILTER_TYPE_BASE);
|
||||
::png_write_info(png_ptr,info_ptr);
|
||||
|
||||
for(unsigned int row=0;row<a_height;row++){
|
||||
unsigned char* pos = a_buffer+(a_height-1-row)*(a_width*a_bpp);
|
||||
::png_write_row(png_ptr,(png_bytep)pos);
|
||||
}
|
||||
|
||||
::png_write_end(png_ptr,info_ptr);
|
||||
::png_destroy_write_struct(&png_ptr,&info_ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool write(std::ostream& a_out,
|
||||
const std::string& a_file,
|
||||
unsigned char* a_buffer,
|
||||
unsigned int a_width,
|
||||
unsigned int a_height,
|
||||
unsigned int a_bpp) {
|
||||
FILE* file = ::fopen(a_file.c_str(),"wb");
|
||||
if(!file) {
|
||||
a_out << "tools::png::write :"
|
||||
<< " can't open file " << tools::sout(a_file) << "."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if(!write_FILE(file,a_buffer,a_width,a_height,a_bpp)) {
|
||||
::fclose(file);
|
||||
a_out << "tools::png::write :"
|
||||
<< " can't write file " << tools::sout(a_file) << "."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
::fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool infos_file(FILE* a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
//a_bpp = number of bytes per pixel.
|
||||
png_byte header[8]; // 8 is the maximum size that can be checked
|
||||
if(::fread(header,1,8,a_file)!=8) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
if(::png_sig_cmp(header,0,8)) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
png_structp png_ptr =
|
||||
::png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
|
||||
if(!png_ptr) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
png_infop info_ptr = ::png_create_info_struct(png_ptr);
|
||||
if(!info_ptr) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(::setjmp(png_jmpbuf(png_ptr))) {
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
::png_init_io(png_ptr,a_file);
|
||||
::png_set_sig_bytes(png_ptr,8);
|
||||
::png_read_info(png_ptr,info_ptr);
|
||||
|
||||
int width = info_ptr->width;
|
||||
int height = info_ptr->height;
|
||||
a_bpp = info_ptr->width?info_ptr->rowbytes/info_ptr->width:0;
|
||||
|
||||
::png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
|
||||
|
||||
a_width = width;
|
||||
a_height = height;
|
||||
//a_bpp = bpp; //avoid the clobbered -W warning.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool infos(std::ostream& a_out,const std::string& a_file,unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) {
|
||||
if(!is(a_file)) {
|
||||
a_out << "tools::png::infos :"
|
||||
<< " file " << a_file << " is not png."
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* file = ::fopen(a_file.c_str(),"rb");
|
||||
if(!file) {
|
||||
a_out << "tools::png::infos :"
|
||||
<< " can't open " << a_file
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int w,h,bpp;
|
||||
bool status = infos_file(file,w,h,bpp);
|
||||
|
||||
::fclose(file);
|
||||
|
||||
if(!status) {
|
||||
a_out << "tools::png::infos :"
|
||||
<< " problem reading " << a_file
|
||||
<< std::endl;
|
||||
a_width = 0;
|
||||
a_height = 0;
|
||||
a_bpp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
a_width = w;
|
||||
a_height = h;
|
||||
a_bpp = bpp;
|
||||
return true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <tools/xpm>
|
||||
|
||||
namespace tools {
|
||||
namespace png {
|
||||
|
||||
inline bool to_xpm(std::ostream& a_out,const std::string& a_file,const std::string& a_name,bool a_verbose = false) {
|
||||
return tools::xpm::to_xpm(a_out,a_file,a_name,read,a_verbose);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#include <tools/image>
|
||||
#include <vector>
|
||||
|
||||
namespace tools {
|
||||
namespace png {
|
||||
|
||||
inline bool concatenate(std::ostream& a_out,
|
||||
const std::vector<std::string>& a_files,
|
||||
unsigned int a_cols,unsigned int a_rows,
|
||||
unsigned int a_bw,unsigned int a_bh,
|
||||
unsigned char a_bc,
|
||||
const std::string& a_file) {
|
||||
unsigned int wa,ha,bppa;
|
||||
unsigned char* ba =
|
||||
tools::image::concatenate
|
||||
(a_out,a_files,a_cols,a_rows,a_bw,a_bh,a_bc,read,wa,ha,bppa);
|
||||
if(!ba) {
|
||||
a_out << "tools::png::concatenate :"
|
||||
<< " failed to concatenate all buffers."
|
||||
<< std::endl;
|
||||
delete [] ba;
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* file = ::fopen(a_file.c_str(),"wb");
|
||||
if(!file) {
|
||||
a_out << "tools::png::concatenate :"
|
||||
<< " can't open " << file << " for writing."
|
||||
<< std::endl;
|
||||
delete [] ba;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!write_FILE(file,ba,wa,ha,bppa)) {
|
||||
a_out << "tools::png::concatenate :"
|
||||
<< " can't write " << a_file << "."
|
||||
<< std::endl;
|
||||
delete [] ba;
|
||||
::fclose(file);
|
||||
return false;
|
||||
}
|
||||
|
||||
delete [] ba;
|
||||
::fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
class reader : public virtual tools::image::ireader {
|
||||
public:
|
||||
virtual tools::image::ireader* copy() const {return new reader(*this);}
|
||||
virtual bool is(const std::string& a_file) const {return tools::png::is(a_file);}
|
||||
virtual bool infos(std::ostream& a_out,const std::string& a_file,
|
||||
unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) const {
|
||||
return tools::png::infos(a_out,a_file,a_width,a_height,a_bpp);
|
||||
}
|
||||
virtual unsigned char* read(std::ostream& a_out,const std::string& a_file,
|
||||
unsigned int& a_width,unsigned int& a_height,unsigned int& a_bpp) const {
|
||||
return tools::png::read(a_out,a_file,a_width,a_height,a_bpp);
|
||||
}
|
||||
virtual unsigned char* read_part(std::ostream& a_out,const std::string& a_file,
|
||||
unsigned int a_sx,unsigned int a_sy,
|
||||
unsigned int a_sw,unsigned int a_sh,
|
||||
unsigned int& a_rw,unsigned int& a_rh,unsigned int& a_rbpp) const {
|
||||
return tools::png::read_part(a_out,a_file,a_sx,a_sy,a_sw,a_sh,a_rw,a_rh,a_rbpp);
|
||||
}
|
||||
public:
|
||||
reader(){}
|
||||
virtual ~reader(){}
|
||||
public:
|
||||
reader(const reader&):ireader(){}
|
||||
reader& operator=(const reader&){return *this;}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
}
|
||||
FLAT& flat() {return m_flat;}
|
||||
void set_seed(unsigned int a_seed) {m_flat.set_seed(a_seed);}
|
||||
void set(REAL a_mean = 0,REAL a_std_dev = 1) {m_mean = a_mean;m_std_dev = a_std_dev;}
|
||||
protected:
|
||||
FLAT& m_flat;
|
||||
REAL m_mean;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user