Field3D
FieldGroup.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------//
2
3#ifndef __F3DUTIL_FIELDGROUP_H__
4#define __F3DUTIL_FIELDGROUP_H__
5
6//------------------------------------------------------------------------------
7
8// Boost includes
9#include <boost/foreach.hpp>
10#include <boost/tokenizer.hpp>
11#include <boost/thread/mutex.hpp>
12#include <boost/mpl/vector.hpp>
13#include <boost/mpl/for_each.hpp>
14#include <boost/mpl/placeholders.hpp>
15#include <boost/mpl/push_back.hpp>
16#include <boost/mpl/transform.hpp>
17#include <boost/fusion/mpl.hpp>
18#include <boost/fusion/algorithm/iteration/for_each.hpp>
19#include <boost/fusion/include/for_each.hpp>
20#include <boost/fusion/include/as_vector.hpp>
21
22// Field3D includes
23#include "DenseField.h"
24#include "Field3DFile.h"
25#include "FieldInterp.h"
26#include "InitIO.h"
27#include "MIPField.h"
28#include "MIPUtil.h"
29#include "SparseField.h"
30#include "MinMaxUtil.h"
31
32// Project includes
33#include "FieldWrapper.h"
34
35//----------------------------------------------------------------------------//
36
37#include "ns.h"
38
40
41//------------------------------------------------------------------------------
42// MPL stuff
43//------------------------------------------------------------------------------
44
45namespace mpl = boost::mpl;
46namespace ph = mpl::placeholders;
47namespace fusion = boost::fusion;
48namespace fusion_ro = boost::fusion::result_of;
49
50typedef mpl::vector<Field3D::half, float, double> ScalarTypes;
51typedef mpl::vector<Field3D::V3h, Field3D::V3f, Field3D::V3d> VectorTypes;
52
53//------------------------------------------------------------------------------
54// Detail namespace
55//------------------------------------------------------------------------------
56
57namespace detail {
58
59//------------------------------------------------------------------------------
60
61static const char* k_minSuffix = "_min";
62static const char* k_maxSuffix = "_max";
63
64//------------------------------------------------------------------------------
65
67template <typename T>
69{
71};
72
73//------------------------------------------------------------------------------
74
76template <typename T>
78{
80};
81
82//------------------------------------------------------------------------------
83
85template <typename T>
87{
88 // typedef typename MIPFieldWrapper<Field3D::MIPDenseField<T> >::Vec type;
89 typedef typename
91};
92
93//------------------------------------------------------------------------------
94
96template <typename T>
98{
99 // typedef typename MIPFieldWrapper<Field3D::MIPSparseField<T> >::Vec type;
100 typedef typename
102};
103
104//------------------------------------------------------------------------------
105
106template <int Dims_T>
108
110{
111 LoadFieldsParams(Field3D::Field3DInputFile &a_in,
112 const std::string &a_name,
113 const std::string &a_attribute,
114 Field3D::FieldRes::Vec &a_results,
115 Field3D::FieldRes::Vec &a_minResults,
116 Field3D::FieldRes::Vec &a_maxResults)
117 : in(a_in),
118 name(a_name),
119 attribute(a_attribute),
120 results(a_results),
121 minResults(a_minResults),
122 maxResults(a_maxResults)
123 { }
124 Field3D::Field3DInputFile &in;
125 const std::string &name;
126 const std::string &attribute;
127 Field3D::FieldRes::Vec &results;
128 Field3D::FieldRes::Vec &minResults;
129 Field3D::FieldRes::Vec &maxResults;
130};
131
132template <>
133struct LoadFields<1>
134{
135 // Ctor
137 : m_p(params)
138 { }
139 // Functor
140 template <typename T>
142 {
143 // Load all fields of type T
144 typename Field3D::Field<T>::Vec fields =
145 m_p.in.readScalarLayers<T>(m_p.name, m_p.attribute);
146 // Add the fields to the result
147 BOOST_FOREACH (const typename Field3D::Field<T>::Ptr &ptr, fields) {
148 m_p.results.push_back(ptr);
149 }
150 // Load 'min' fields
151 typename Field3D::Field<T>::Vec minFields =
152 m_p.in.readScalarLayers<T>(m_p.name, m_p.attribute + k_minSuffix);
153 // Add the fields to the result
154 BOOST_FOREACH (const typename Field3D::Field<T>::Ptr &ptr, minFields) {
155 m_p.minResults.push_back(ptr);
156 }
157 // Load 'max' fields
158 typename Field3D::Field<T>::Vec maxFields =
159 m_p.in.readScalarLayers<T>(m_p.name, m_p.attribute + k_maxSuffix);
160 // Add the fields to the result
161 BOOST_FOREACH (const typename Field3D::Field<T>::Ptr &ptr, maxFields) {
162 m_p.maxResults.push_back(ptr);
163 }
164 }
165 // Data members
167};
168
169template <>
170struct LoadFields<3>
171{
172 // Ctor
174 : m_p(params)
175 { }
176 // Functor
177 template <typename Vec_T>
178 void operator()(Vec_T)
179 {
180 typedef typename Vec_T::BaseType T;
181
182 // Load all fields of type T
183 typename Field3D::Field<Vec_T>::Vec fields =
184 m_p.in.readVectorLayers<T>(m_p.name, m_p.attribute);
185 // Add the fields to the result
186 BOOST_FOREACH (const typename Field3D::Field<Vec_T>::Ptr &ptr, fields) {
187 m_p.results.push_back(ptr);
188 }
189 // Load 'min' fields
190 typename Field3D::Field<Vec_T>::Vec minFields =
191 m_p.in.readVectorLayers<T>(m_p.name, m_p.attribute + k_minSuffix);
192 // Add the fields to the result
193 BOOST_FOREACH (const typename Field3D::Field<Vec_T>::Ptr &ptr, minFields) {
194 m_p.minResults.push_back(ptr);
195 }
196 // Load 'max' fields
197 typename Field3D::Field<Vec_T>::Vec maxFields =
198 m_p.in.readVectorLayers<T>(m_p.name, m_p.attribute + k_maxSuffix);
199 // Add the fields to the result
200 BOOST_FOREACH (const typename Field3D::Field<Vec_T>::Ptr &ptr, maxFields) {
201 m_p.maxResults.push_back(ptr);
202 }
203 }
204 // Data members
206};
207
208//----------------------------------------------------------------------------//
209
210inline std::vector<V3d>
212{
213 std::vector<V3d> result;
214 result.push_back(V3d(box.min.x, box.min.y, box.min.z));
215 result.push_back(V3d(box.max.x, box.min.y, box.min.z));
216 result.push_back(V3d(box.min.x, box.max.y, box.min.z));
217 result.push_back(V3d(box.max.x, box.max.y, box.min.z));
218 result.push_back(V3d(box.min.x, box.min.y, box.max.z));
219 result.push_back(V3d(box.max.x, box.min.y, box.max.z));
220 result.push_back(V3d(box.min.x, box.max.y, box.max.z));
221 result.push_back(V3d(box.max.x, box.max.y, box.max.z));
222 return result;
223}
224
225//----------------------------------------------------------------------------//
226
227inline std::vector<V3d>
229{
230 std::vector<V3d> result;
231 result.push_back(V3d(0.0, 0.0, 0.0));
232 result.push_back(V3d(1.0, 0.0, 0.0));
233 result.push_back(V3d(0.0, 1.0, 0.0));
234 result.push_back(V3d(1.0, 1.0, 0.0));
235 result.push_back(V3d(0.0, 0.0, 1.0));
236 result.push_back(V3d(1.0, 0.0, 1.0));
237 result.push_back(V3d(0.0, 1.0, 1.0));
238 result.push_back(V3d(1.0, 1.0, 1.0));
239 return result;
240}
241
242//------------------------------------------------------------------------------
243
244inline bool
245intersect(const Ray3d &ray, const Box3d &box, double &outT0, double &outT1)
246{
247 double tNear = -std::numeric_limits<double>::max();
248 double tFar = std::numeric_limits<double>::max();
249 const double epsilon = std::numeric_limits<double>::epsilon() * 10.0;
250
251 for (size_t dim = 0; dim < 3; ++dim) {
252 double t0, t1;
253 if (std::abs(ray.dir[dim]) < epsilon) {
254 // Ray is parallel, check if inside slab
255 if (ray.pos[dim] < box.min[dim] || ray.pos[dim] > box.max[dim]) {
256 return false;
257 }
258 }
259 t0 = (box.min[dim] - ray.pos[dim]) / ray.dir[dim];
260 t1 = (box.max[dim] - ray.pos[dim]) / ray.dir[dim];
261 if (t0 > t1) {
262 std::swap(t0, t1);
263 }
264 tNear = std::max(tNear, t0);
265 tFar = std::min(tFar, t1);
266 if (tNear > tFar) {
267 return false;
268 }
269 if (tFar < 0.0) {
270 return false;
271 }
272 }
273 outT0 = tNear;
274 outT1 = tFar;
275 return true;
276}
277
278//------------------------------------------------------------------------------
279
280} // namespace detail
281
282//------------------------------------------------------------------------------
283// FieldGroup
284//------------------------------------------------------------------------------
285
302template <typename BaseTypeList_T, int Dims_T>
304{
305 // MPL Typedefs --------------------------------------------------------------
306
307 // The list of basic types to support.
308 typedef BaseTypeList_T MPLBaseTypes;
309
310 // Instantiate FieldWrapper<Field_T> for each family with each basic type
311 typedef typename mpl::transform<
314 typedef typename mpl::transform<
317 typedef typename mpl::transform<
320 typedef typename mpl::transform<
323
324 // Map MPL types to boost fusion types
325 typedef typename fusion_ro::as_vector<MPLDenseTypes>::type DenseTypes;
326 typedef typename fusion_ro::as_vector<MPLSparseTypes>::type SparseTypes;
327 typedef typename fusion_ro::as_vector<MPLMIPDenseTypes>::type MIPDenseTypes;
328 typedef typename fusion_ro::as_vector<MPLMIPSparseTypes>::type MIPSparseTypes;
329
330 // Enums ---------------------------------------------------------------------
331
333 {
334 Add = 0,
335 Avg
336 };
337
338 // Constants -----------------------------------------------------------------
339
341 static const int k_missingFile = -1;
342
343 // Ctors ---------------------------------------------------------------------
344
346 FieldGroup();
348 FieldGroup(const Field3D::FieldRes::Vec &fields);
349
350 // Main methods --------------------------------------------------------------
351
355 void setOsToWs(const Imath::M44d &osToWs);
360 virtual void setWsBoundsOptimization(const bool doWsBoundsOptimization);
368 virtual void setup(const Field3D::FieldRes::Ptr field);
370 virtual void setup(const Field3D::FieldRes::Vec &fields);
373 virtual void setup(const Field3D::FieldRes::Vec &fields,
374 const Field3D::FieldRes::Vec &minFields,
375 const Field3D::FieldRes::Vec &maxFields);
379 int load(const std::string &filename, const std::string &attribute);
381 void makeMinMax(const float resMult);
383 virtual size_t size() const;
385 size_t sizeMIP() const;
388 void sample(const V3d &wsP, const float wsSpotSize, const float time,
389 float *result, const CompositeOp compOp = Add);
393 void sample(const V3d &vsP, float *result, bool isVs) const;
396 void sampleMIP(const V3d &vsP, const float wsSpotSize,
397 float *result, bool isVs) const;
399 void sampleMultiple(const size_t n, const float *wsP, float *result) const;
401 void sampleMIPMultiple(const size_t n, const float *wsP, const float *wsSpotSize,
402 float *result) const;
404 Box3d wsBounds() const;
406 bool intersects(const V3d &wsP) const;
408 bool getIntersections(const Ray3d &ray, IntervalVec &intervals) const;
410 void getMinMax(const Box3d &wsBounds, float *min, float *max) const;
412 bool hasPrefiltMinMax() const
413 { return m_hasPrefiltMinMax; }
415 long long int memSize() const;
417 const FieldRes::Vec& fields() const
418 { return m_allFields; }
419
420protected:
421
422 // Utility methods -----------------------------------------------------------
423
425 void setupMinMax(const FieldRes::Vec &minFields,
426 const FieldRes::Vec &maxFields);
427
428 // Data members --------------------------------------------------------------
429
434
437
440
443
446
451
452 // Functors ------------------------------------------------------------------
453
454 struct GrabFields;
456 struct CountFields;
457 struct MakeMinMax;
458 struct MakeMinMaxMIP;
459 struct Sample;
460 struct SampleMIP;
461 struct SampleMultiple;
462 struct SampleMIPMultiple;
463 struct GetWsBounds;
464 struct GetIntersections;
465 struct GetMinMax;
466 struct GetMinMaxMIP;
467 struct GetMinMaxPrefilt;
468 struct PointIsect;
469 struct MemSize;
470
471};
472
473//------------------------------------------------------------------------------
474
477
478//------------------------------------------------------------------------------
479// Template implementations
480//------------------------------------------------------------------------------
481
482template <typename BaseTypeList_T, int Dims_T>
484 : m_hasPrefiltMinMax(false), m_doWsBoundsOptimization(false)
485{ }
486
487//------------------------------------------------------------------------------
488
489template <typename BaseTypeList_T, int Dims_T>
491(const Field3D::FieldRes::Vec &fields)
492 : m_hasPrefiltMinMax(false), m_doWsBoundsOptimization(false)
493{
494 // Perform setup
495 setup(fields);
496}
497
498//------------------------------------------------------------------------------
499
500template <typename BaseTypeList_T, int Dims_T>
501void
503{
504 m_osToWs = osToWs;
505}
506
507//------------------------------------------------------------------------------
508
509template <typename BaseTypeList_T, int Dims_T>
510void
512{
513 m_doWsBoundsOptimization = doWsBoundsOptimization;
514
515 if (doWsBoundsOptimization) {
516 DoWsBoundsOptimization op(m_doWsBoundsOptimization);
517
518 fusion::for_each(m_dense, op);
519 fusion::for_each(m_sparse, op);
520 fusion::for_each(m_mipDense, op);
521 fusion::for_each(m_mipSparse, op);
522 }
523}
524
525//------------------------------------------------------------------------------
526
527template <typename BaseTypeList_T, int Dims_T>
528void
533
534//------------------------------------------------------------------------------
535
536template <typename BaseTypeList_T, int Dims_T>
537void
538FieldGroup<BaseTypeList_T, Dims_T>::setup(const Field3D::FieldRes::Ptr field)
539{
540 FieldRes::Vec fields, minFields, maxFields;
541 fields.push_back(field);
542 // Perform setup
543 setup(fields, minFields, maxFields);
544}
545
546//------------------------------------------------------------------------------
547
548template <typename BaseTypeList_T, int Dims_T>
549void
550FieldGroup<BaseTypeList_T, Dims_T>::setup(const Field3D::FieldRes::Vec &fields)
551{
552 FieldRes::Vec minFields, maxFields;
553 // Perform setup
554 setup(fields, minFields, maxFields);
555}
556
557//------------------------------------------------------------------------------
558
559template <typename BaseTypeList_T, int Dims_T>
560void
562(const Field3D::FieldRes::Vec &fields,
563 const Field3D::FieldRes::Vec &minFields,
564 const Field3D::FieldRes::Vec &maxFields)
565{
566 // Record fields in m_allFields
567 m_allFields = fields;
568
569 // Pick out primary fields
570 for (size_t i = 0, end = fields.size(); i < end; ++i) {
571 GrabFields op(fields[i], m_osToWs, m_valueRemapOp, m_doWsBoundsOptimization);
572 fusion::for_each(m_dense, op);
573 fusion::for_each(m_sparse, op);
574 fusion::for_each(m_mipDense, op);
575 fusion::for_each(m_mipSparse, op);
576 }
577
578 // Pick out min/max fields
579 setupMinMax(minFields, maxFields);
580}
581
582template <typename BaseTypeList_T, int Dims_T>
583void
585(const Field3D::FieldRes::Vec &minFields,
586 const Field3D::FieldRes::Vec &maxFields)
587{
588 // Record minFields and maxFields as auxiliary fields
589 m_auxFields.insert(m_auxFields.end(), minFields.begin(), minFields.end());
590 m_auxFields.insert(m_auxFields.end(), maxFields.begin(), maxFields.end());
591
592 // Pick out min fields
593 for (size_t i = 0, end = minFields.size(); i < end; ++i) {
594 GrabFields op(minFields[i], m_osToWs, m_valueRemapOp, m_doWsBoundsOptimization);
595 fusion::for_each(m_mipDenseMin, op);
596 fusion::for_each(m_mipSparseMin, op);
597 }
598 // Pick out max fields
599 for (size_t i = 0, end = maxFields.size(); i < end; ++i) {
600 GrabFields op(maxFields[i], m_osToWs, m_valueRemapOp, m_doWsBoundsOptimization);
601 fusion::for_each(m_mipDenseMax, op);
602 fusion::for_each(m_mipSparseMax, op);
603 }
604 // Check if we have pre-filtered fields
605 CountFields countMinOp, countMaxOp;
606 fusion::for_each(m_mipDenseMin, countMinOp);
607 fusion::for_each(m_mipDenseMax, countMaxOp);
608 fusion::for_each(m_mipSparseMin, countMinOp);
609 fusion::for_each(m_mipSparseMax, countMaxOp);
610 if (countMinOp.count > 0 && countMaxOp.count > 0) {
611 m_hasPrefiltMinMax = true;
612 }
613}
614
615//------------------------------------------------------------------------------
616
617template <typename BaseTypeList_T, int Dims_T>
618int
620(const std::string &filename, const std::string &attribute)
621{
622 using namespace Field3D;
623
624 // Storage for the primary fields
625 FieldRes::Vec results;
626 // Storage for the auxiliary fields
627 FieldRes::Vec minResults, maxResults;
628
629 // Track number of fields in group before loading.
630 const size_t sizeBeforeLoading = size();
631
632 // Open each file ---
633
634 std::vector<std::string> filenames;
635 filenames.push_back(filename);
636
637 BOOST_FOREACH (const std::string fn, filenames) {
638
640 if (!in.open(fn)) {
641 return k_missingFile;
642 }
643
644 // Use partition names to determine if fields should be loaded
645 std::vector<std::string> names;
646 in.getPartitionNames(names);
647
648 BOOST_FOREACH (const std::string &name, names) {
649 detail::LoadFieldsParams params(in, name, attribute, results,
650 minResults, maxResults);
652 mpl::for_each<BaseTypeList_T>(op);
653 }
654
655 }
656
657 // Set up from fields
658 setup(results, minResults, maxResults);
659
660 // Done. Return the number of fields that were loaded.
661 return size() - sizeBeforeLoading;
662}
663
664//------------------------------------------------------------------------------
665
666template <typename BaseTypeList_T, int Dims_T>
667void
669(const float resMult)
670{
671 // Storage for the auxiliary fields
672 FieldRes::Vec minFields, maxFields;
673
674 MakeMinMax op(minFields, maxFields, resMult);
675 fusion::for_each(m_dense, op);
676 fusion::for_each(m_sparse, op);
677
678 MakeMinMaxMIP opMIP(minFields, maxFields, resMult);
679 fusion::for_each(m_mipDense, opMIP);
680 fusion::for_each(m_mipSparse, opMIP);
681
682 setupMinMax(minFields, maxFields);
683}
684
685//------------------------------------------------------------------------------
686
687template <typename BaseTypeList_T, int Dims_T>
688size_t
690{
691 CountFields op;
692 fusion::for_each(m_dense, op);
693 fusion::for_each(m_sparse, op);
694 fusion::for_each(m_mipDense, op);
695 fusion::for_each(m_mipSparse, op);
696 return op.count;
697}
698
699//------------------------------------------------------------------------------
700
701template <typename BaseTypeList_T, int Dims_T>
702size_t
704{
705 CountFields op;
706 fusion::for_each(m_mipDense, op);
707 fusion::for_each(m_mipSparse, op);
708 return op.count;
709}
710
711//------------------------------------------------------------------------------
712
713template <typename BaseTypeList_T, int Dims_T>
714void
716 const float wsSpotSize,
717 const float /* time */,
718 float *result,
719 const CompositeOp compOp)
720{
721 size_t numHits = 0;
722
723 // Handle ordinary fields
724 Sample op(wsP, result, numHits);
725 fusion::for_each(m_dense, op);
726 fusion::for_each(m_sparse, op);
727
728 // Handle MIP fields
729 SampleMIP mipOp(wsP, wsSpotSize, result, numHits);
730 fusion::for_each(m_mipDense, mipOp);
731 fusion::for_each(m_mipSparse, mipOp);
732
733 // Check composite op
734 if (compOp == Add) {
735 // Nothing
736 } else {
737 if (numHits > 1) {
738 for (size_t i = 0; i < Dims_T; ++i) {
739 result[i] /= static_cast<float>(numHits);
740 }
741 }
742 }
743}
744
745//------------------------------------------------------------------------------
746
747template <typename BaseTypeList_T, int Dims_T>
748void
750 float *result,
751 bool /* isVs */) const
752{
753 size_t numHits = 0;
754
755 Sample op(vsP, result, numHits);
756 fusion::for_each(m_dense, op);
757 fusion::for_each(m_sparse, op);
758}
759
760//------------------------------------------------------------------------------
761
762template <typename BaseTypeList_T, int Dims_T>
763void
765 const float *wsP,
766 float *result) const
767{
768 size_t numHits = 0;
769
770 SampleMultiple op(n, wsP, result, numHits);
771 fusion::for_each(m_dense, op);
772 fusion::for_each(m_sparse, op);
773}
774
775//------------------------------------------------------------------------------
776
777template <typename BaseTypeList_T, int Dims_T>
778void
780 const float wsSpotSize,
781 float *result,
782 bool /* isVs */) const
783{
784 size_t numHits = 0;
785
786 SampleMIP op(vsP, wsSpotSize, result, numHits);
787 fusion::for_each(m_mipDense, op);
788 fusion::for_each(m_mipSparse, op);
789}
790
791//------------------------------------------------------------------------------
792
793template <typename BaseTypeList_T, int Dims_T>
794void
796 const float *wsP,
797 const float *wsSpotSize,
798 float *result) const
799{
800 size_t numHits = 0;
801
802 SampleMIPMultiple op(n, wsP, wsSpotSize, result, numHits);
803 fusion::for_each(m_mipDense, op);
804 fusion::for_each(m_mipSparse, op);
805}
806
807//------------------------------------------------------------------------------
808
809template <typename BaseTypeList_T, int Dims_T>
810Box3d
812{
813 Box3d wsBounds;
814 GetWsBounds op(wsBounds);
815 fusion::for_each(m_dense, op);
816 fusion::for_each(m_sparse, op);
817 fusion::for_each(m_mipDense, op);
818 fusion::for_each(m_mipSparse, op);
819 return wsBounds;
820}
821
822//------------------------------------------------------------------------------
823
824template <typename BaseTypeList_T, int Dims_T>
825bool
827{
828 PointIsect op(wsP);
829 fusion::for_each(m_dense, op);
830 fusion::for_each(m_sparse, op);
831 fusion::for_each(m_mipDense, op);
832 fusion::for_each(m_mipSparse, op);
833 return op.result();
834}
835
836//------------------------------------------------------------------------------
837
838template <typename BaseTypeList_T, int Dims_T>
839bool
841(const Ray3d &ray, IntervalVec &intervals) const
842{
843 GetIntersections op(ray, intervals);
844 fusion::for_each(m_dense, op);
845 fusion::for_each(m_sparse, op);
846 fusion::for_each(m_mipDense, op);
847 fusion::for_each(m_mipSparse, op);
848 return intervals.size() > 0;
849}
850
851//------------------------------------------------------------------------------
852
853template <typename BaseTypeList_T, int Dims_T>
854void
856 float *min,
857 float *max) const
858{
859 if (m_hasPrefiltMinMax) {
860 // Pre-filtered types
861 GetMinMaxPrefilt opMin(wsBounds, min, GetMinMaxPrefilt::Min);
862 GetMinMaxPrefilt opMax(wsBounds, max, GetMinMaxPrefilt::Max);
863 fusion::for_each(m_mipDenseMin, opMin);
864 fusion::for_each(m_mipSparseMin, opMin);
865 fusion::for_each(m_mipDenseMax, opMax);
866 fusion::for_each(m_mipSparseMax, opMax);
867 } else {
868 // Non-prefiltered types
869 GetMinMax op(wsBounds, min, max);
870 fusion::for_each(m_dense, op);
871 fusion::for_each(m_sparse, op);
872 // Non-prefiltered MIP types
873 GetMinMaxMIP opMIP(wsBounds, min, max);
874 fusion::for_each(m_mipDense, opMIP);
875 fusion::for_each(m_mipSparse, opMIP);
876 }
877}
878
879//------------------------------------------------------------------------------
880
881template <typename BaseTypeList_T, int Dims_T>
882long long int
884{
885 long long int result = 0;
886 MemSize op(result);
887 fusion::for_each(m_dense, op);
888 fusion::for_each(m_sparse, op);
889 fusion::for_each(m_mipDense, op);
890 fusion::for_each(m_mipSparse, op);
891 return result;
892}
893
894//------------------------------------------------------------------------------
895// Functor implementations
896//------------------------------------------------------------------------------
897
898template <typename BaseTypeList_T, int Dims_T>
899struct FieldGroup<BaseTypeList_T, Dims_T>::GrabFields
900{
902 GrabFields(Field3D::FieldRes::Ptr f,
903 const M44d &osToWs,
905 const bool doWsBoundsOptimization)
906 : m_field(f), m_osToWs(osToWs), m_op(op),
907 m_doWsBoundsOptimization(doWsBoundsOptimization)
908 { }
910 template <typename WrapperVec_T>
911 void operator()(WrapperVec_T &vec) const
912 {
913 // Typedefs
914 typedef typename WrapperVec_T::value_type Wrapper_T;
915 typedef typename Wrapper_T::field_type Field_T;
916 typedef typename Field_T::Ptr FieldPtr;
917 // Grab field if type matches
918 if (FieldPtr f =
919 Field3D::field_dynamic_cast<Field_T>(m_field)) {
920 // Add to FieldWrapper vector
921 vec.push_back(f);
922 // Grab just-inserted entry
923 Wrapper_T &entry = vec.back();
924 // Set up transform
925 M44d id;
926 if (m_osToWs != id) {
927 entry.setOsToWs(m_osToWs);
928 }
929
930 // Set toggle to use world axis aligned bounding boxes in
931 // lookups
933 entry.setWsBoundsOptimization(m_doWsBoundsOptimization);
934 }
935
936 // Set up value remap op
937 if (m_op) {
938 entry.setValueRemapOp(m_op);
939 }
940 }
941 }
942private:
944 Field3D::FieldRes::Ptr m_field;
951};
952
953//------------------------------------------------------------------------------
954
955template <typename BaseTypeList_T, int Dims_T>
956struct FieldGroup<BaseTypeList_T, Dims_T>::DoWsBoundsOptimization
957{
959 DoWsBoundsOptimization(const bool doWsBoundsOptimization)
960 : m_doWsBoundsOptimization(doWsBoundsOptimization)
961 { }
963 template <typename WrapperVec_T>
964 void operator()(WrapperVec_T &vec) const
965 {
966 for (size_t i = 0, end = vec.size(); i < end; ++i) {
967 vec[i].setWsBoundsOptimization(m_doWsBoundsOptimization);
968 }
969 }
972};
973
974//------------------------------------------------------------------------------
975
976template <typename BaseTypeList_T, int Dims_T>
977struct FieldGroup<BaseTypeList_T, Dims_T>::CountFields
978{
981 : count(0)
982 { }
984 template <typename T>
985 void operator()(const T &vec) const
986 { count += vec.size(); }
987 // Data members
988 mutable int count;
989};
990
991//------------------------------------------------------------------------------
992
993template <typename BaseTypeList_T, int Dims_T>
994struct FieldGroup<BaseTypeList_T, Dims_T>::MakeMinMax
995{
997 MakeMinMax(Field3D::FieldRes::Vec &minFields,
998 Field3D::FieldRes::Vec &maxFields,
999 const float resMult)
1000 : m_minFields(minFields),
1001 m_maxFields(maxFields),
1002 m_resMult(resMult),
1003 m_numThreads(Field3D::numIOThreads())
1004 { }
1006 template <typename WrapperVec_T>
1007 void operator()(const WrapperVec_T &vec)
1008 {
1009 // Typedefs
1010 typedef typename WrapperVec_T::value_type Wrapper_T;
1011 typedef typename Wrapper_T::field_type Field_T;
1012 typedef typename Field3D::MIPField<Field_T> MIPField_T;
1013 typedef typename Field_T::value_type Value_T;
1014 typedef typename Field3D::Field<Value_T>::Ptr FieldPtr;
1015
1016 std::pair<FieldPtr, FieldPtr> result;
1017 for (size_t i = 0, end = vec.size(); i < end; ++i) {
1018 const Field_T &f = *(vec[i].field);
1019 result = Field3D::makeMinMax<MIPField_T>(f, m_resMult, m_numThreads);
1020 m_minFields.push_back(result.first);
1021 m_maxFields.push_back(result.second);
1022 }
1023 }
1024 // Data members
1025 Field3D::FieldRes::Vec &m_minFields;
1026 Field3D::FieldRes::Vec &m_maxFields;
1027 const float m_resMult;
1028 const size_t m_numThreads;
1029};
1030
1031//------------------------------------------------------------------------------
1032
1033template <typename BaseTypeList_T, int Dims_T>
1034struct FieldGroup<BaseTypeList_T, Dims_T>::MakeMinMaxMIP
1035{
1037 MakeMinMaxMIP(Field3D::FieldRes::Vec &minFields,
1038 Field3D::FieldRes::Vec &maxFields,
1039 const float resMult)
1040 : m_minFields(minFields),
1041 m_maxFields(maxFields),
1042 m_resMult(resMult),
1043 m_numThreads(Field3D::numIOThreads())
1044 { }
1046 template <typename WrapperVec_T>
1047 void operator()(const WrapperVec_T &vec)
1048 {
1049 // Typedefs
1050 typedef typename WrapperVec_T::value_type Wrapper_T;
1051 typedef typename Wrapper_T::field_type MIPField_T;
1052 typedef typename MIPField_T::NestedType Field_T;
1053 typedef typename Field_T::value_type Value_T;
1054 typedef typename Field3D::Field<Value_T>::Ptr FieldPtr;
1055
1056 std::pair<FieldPtr, FieldPtr> result;
1057 for (size_t i = 0, end = vec.size(); i < end; ++i) {
1058 const Field_T &f = *(vec[i].field->concreteMipLevel(0));
1059 result = Field3D::makeMinMax<MIPField_T>(f, m_resMult, m_numThreads);
1060 m_minFields.push_back(result.first);
1061 m_maxFields.push_back(result.second);
1062 }
1063 }
1064 // Data members
1065 Field3D::FieldRes::Vec &m_minFields;
1066 Field3D::FieldRes::Vec &m_maxFields;
1067 const float m_resMult;
1068 const size_t m_numThreads;
1069};
1070
1071//------------------------------------------------------------------------------
1072
1073template <typename BaseTypeList_T, int Dims_T>
1074struct FieldGroup<BaseTypeList_T, Dims_T>::Sample
1075{
1077 Sample(const V3d &p, float *result, size_t &numHits)
1078 : m_p(p), m_result(result), m_numHits(numHits)
1079 { }
1081 template <typename T>
1082 void operator()(const T &vec) const
1083 {
1084 FieldSampler<T, Dims_T>::sample(vec, m_p, m_result, m_numHits);
1085 }
1086 // Data members
1087 const V3d &m_p;
1088 float *m_result;
1089 size_t &m_numHits;
1090};
1091
1092//------------------------------------------------------------------------------
1093
1094template <typename BaseTypeList_T, int Dims_T>
1095struct FieldGroup<BaseTypeList_T, Dims_T>::SampleMIP
1096{
1098 SampleMIP(const V3d &p, const float wsSpotSize, float *result,
1099 size_t &numHits)
1100 : m_p(p), m_wsSpotSize(wsSpotSize), m_result(result), m_numHits(numHits)
1101 { }
1103 template <typename T>
1104 void operator()(const T &vec) const
1105 {
1106 FieldSampler<T, Dims_T>::sampleMIP(vec, m_p, m_wsSpotSize, m_result,
1107 m_numHits);
1108 }
1109 // Data members
1110 const V3d &m_p;
1111 const float m_wsSpotSize;
1112 float *m_result;
1113 size_t &m_numHits;
1114};
1115
1116//------------------------------------------------------------------------------
1117
1118template <typename BaseTypeList_T, int Dims_T>
1119struct FieldGroup<BaseTypeList_T, Dims_T>::SampleMultiple
1120{
1122 SampleMultiple(const size_t n, const float *p, float *result,
1123 size_t *numHits)
1124 : m_n(n), m_p(p), m_result(result), m_numHits(numHits)
1125 { }
1127 template <typename T>
1128 void operator()(const T &vec) const
1129 {
1130 FieldSampler<T, Dims_T>::sampleMultiple(vec, m_n, m_p, m_result, m_numHits);
1131 }
1132 // Data members
1133 const int m_n;
1134 const float *m_p;
1135 float *m_result;
1136 size_t *m_numHits;
1137};
1138
1139//------------------------------------------------------------------------------
1140
1141template <typename BaseTypeList_T, int Dims_T>
1142struct FieldGroup<BaseTypeList_T, Dims_T>::SampleMIPMultiple
1143{
1145 SampleMIPMultiple(const size_t n, const float *p, const float *wsSpotSize,
1146 float *result, size_t *numHits)
1147 : m_n(n), m_p(p), m_wsSpotSize(wsSpotSize), m_result(result),
1148 m_numHits(numHits)
1149 { }
1151 template <typename T>
1152 void operator()(const T &vec) const
1153 {
1154 FieldSampler<T, Dims_T>::sampleMIPMultiple(vec, m_n, m_p, m_wsSpotSize,
1155 m_result, m_numHits);
1156 }
1157 // Data members
1158 const int m_n;
1159 const float *m_p;
1160 const float *m_wsSpotSize;
1161 float *m_result;
1162 size_t *m_numHits;
1163};
1164
1165//------------------------------------------------------------------------------
1166
1167template <typename BaseTypeList_T, int Dims_T>
1168struct FieldGroup<BaseTypeList_T, Dims_T>::GetWsBounds
1169{
1172 : m_wsBounds(wsBounds)
1173 { }
1175 template <typename T>
1176 void operator()(const T &vec) const
1177 {
1178 for (size_t field = 0, end = vec.size(); field < end; ++field) {
1179 // Pointer to mapping
1180 const FieldMapping* mapping = vec[field].mapping;
1181 if (mapping) {
1182 // Corner vertices in local space
1183 std::vector<V3d> lsP = detail::unitCornerPoints();
1184 // Transform to world space and pad resulting bounds
1185 for (size_t i = 0; i < 8; ++i) {
1186 V3d wsP;
1187 if (vec[field].doOsToWs) {
1188 V3d osP;
1189 mapping->localToWorld(lsP[i], osP);
1190 vec[field].osToWs.multVecMatrix(osP, wsP);
1191 } else {
1192 mapping->localToWorld(lsP[i], wsP);
1193 }
1194 m_wsBounds.extendBy(wsP);
1195 }
1196 }
1197 }
1198 }
1199 // Data members
1201};
1202
1203//------------------------------------------------------------------------------
1204
1205template <typename BaseTypeList_T, int Dims_T>
1206struct FieldGroup<BaseTypeList_T, Dims_T>::GetIntersections
1207{
1209 GetIntersections(const Ray3d &wsRay, IntervalVec &intervals)
1210 : m_wsRay(wsRay), m_intervals(intervals)
1211 {
1212
1213 }
1216 const MatrixFieldMapping *mtx,
1217 const float worldScale) const
1218 {
1219 using std::min;
1220
1221 const float time = 0.0f;
1222
1223 // Transform ray to local space for intersection test
1224 Ray3d lsRay;
1225 mtx->worldToLocal(wsRay.pos, lsRay.pos, time);
1226 mtx->worldToLocalDir(wsRay.dir, lsRay.dir);
1227 // Use unit bounding box to intersect against
1228 Box3d lsBBox(V3d(0.0), V3d(1.0));
1229 // Calculate intersection points
1230 double t0, t1;
1231 // Add the interval if the ray intersects the box
1232 if (detail::intersect(lsRay, lsBBox, t0, t1)) {
1233 const V3d wsVoxelSize = mtx->wsVoxelSize(0, 0, 0);
1234 const double minLen = min(min(wsVoxelSize.x, wsVoxelSize.y),
1235 wsVoxelSize.z);
1236 m_intervals.push_back(Interval(t0, t1, minLen * worldScale));
1237 }
1238 }
1241 const FrustumFieldMapping *mtx,
1242 const float worldScale) const
1243 {
1244 using std::min;
1245
1246 typedef std::vector<V3d> PointVec;
1247
1248 const float time = 0.0f;
1249
1250 // Get the eight corners of the local space bounding box
1251 Box3d lsBounds(V3d(0.0), V3d(1.0));
1252 PointVec lsCorners = detail::cornerPoints(lsBounds);
1253 // Get the world space positions of the eight corners of the frustum
1254 PointVec wsCorners(lsCorners.size());
1255 for (PointVec::iterator lsP = lsCorners.begin(), wsP = wsCorners.begin(),
1256 end = lsCorners.end(); lsP != end; ++lsP, ++wsP) {
1257 mtx->localToWorld(*lsP, *wsP, time);
1258 }
1259
1260 // Construct plane for each face of frustum
1261 Plane3d planes[6];
1262 planes[0] = Plane3d(wsCorners[4], wsCorners[0], wsCorners[6]);
1263 planes[1] = Plane3d(wsCorners[1], wsCorners[5], wsCorners[3]);
1264 planes[2] = Plane3d(wsCorners[4], wsCorners[5], wsCorners[0]);
1265 planes[3] = Plane3d(wsCorners[2], wsCorners[3], wsCorners[6]);
1266 planes[4] = Plane3d(wsCorners[0], wsCorners[1], wsCorners[2]);
1267 planes[5] = Plane3d(wsCorners[5], wsCorners[4], wsCorners[7]);
1268
1269 // Intersect ray against planes
1270 double t0 = -std::numeric_limits<double>::max();
1271 double t1 = std::numeric_limits<double>::max();
1272 for (int i = 0; i < 6; ++i) {
1273 double t;
1274 const Plane3d &p = planes[i];
1275 if (p.intersectT(wsRay, t)) {
1276 if (wsRay.dir.dot(p.normal) > 0.0) {
1277 // Non-opposing plane
1278 t1 = std::min(t1, t);
1279 } else {
1280 // Opposing plane
1281 t0 = std::max(t0, t);
1282 }
1283 }
1284 }
1285 if (t0 < t1) {
1286 t0 = std::max(t0, 0.0);
1287 const V3d wsVoxelSize = mtx->wsVoxelSize(0, 0, 0);
1288 const double minLen = min(min(wsVoxelSize.x, wsVoxelSize.y),
1289 wsVoxelSize.z);
1290 m_intervals.push_back(Interval(t0, t1, minLen * worldScale));
1291 }
1292 }
1294 template <typename T>
1295 void operator()(const T &vec) const
1296 {
1297 // Intersect the ray against all the fields
1298 for (size_t field = 0, end = vec.size(); field < end; ++field) {
1299 // Check object space transform
1300 Ray3d wsRay = m_wsRay;
1301 if (vec[field].doOsToWs) {
1302 vec[field].wsToOs.multVecMatrix(m_wsRay.pos, wsRay.pos);
1303 vec[field].wsToOs.multDirMatrix(m_wsRay.dir, wsRay.dir);
1304 }
1305 // Pointer to mapping
1306 const FieldMapping* m = vec[field].mapping;
1307 // Check matrix mapping
1308 if (const MatrixFieldMapping *mtx =
1309 dynamic_cast<const MatrixFieldMapping*>(m)) {
1310 intersectMatrixMapping(wsRay, mtx, vec[field].worldScale);
1311 }
1312 // Check frustum mapping
1313 if (const FrustumFieldMapping *f =
1314 dynamic_cast<const FrustumFieldMapping*>(m)) {
1315 intersectFrustumMapping(wsRay, f, vec[field].worldScale);
1316 }
1317 }
1318 }
1319 // Data members
1322};
1323
1324//------------------------------------------------------------------------------
1325
1326template <typename BaseTypeList_T, int Dims_T>
1327struct FieldGroup<BaseTypeList_T, Dims_T>::GetMinMax
1328{
1330 GetMinMax(const Box3d &wsBounds, float *min, float *max)
1331 : m_wsBounds(wsBounds), m_min(min), m_max(max)
1332 { }
1334 template <typename T>
1335 void operator()(const T &vec) const
1336 {
1337 FieldSampler<T, Dims_T>::getMinMax(vec, m_wsBounds, m_min, m_max);
1338 }
1339 // Data members
1341 float *m_min;
1342 float *m_max;
1343};
1344
1345//------------------------------------------------------------------------------
1346
1347template <typename BaseTypeList_T, int Dims_T>
1348struct FieldGroup<BaseTypeList_T, Dims_T>::GetMinMaxMIP
1349{
1351 GetMinMaxMIP(const Box3d &wsBounds, float *min, float *max)
1352 : m_wsBounds(wsBounds), m_min(min), m_max(max)
1353 { }
1355 template <typename T>
1356 void operator()(const T &vec) const
1357 {
1358 FieldSampler<T, Dims_T>::getMinMaxMIP(vec, m_wsBounds, m_min, m_max);
1359 }
1360 // Data members
1362 float *m_min;
1363 float *m_max;
1364};
1365
1366//------------------------------------------------------------------------------
1367
1368template <typename BaseTypeList_T, int Dims_T>
1369struct FieldGroup<BaseTypeList_T, Dims_T>::GetMinMaxPrefilt
1370{
1373 Max
1376 GetMinMaxPrefilt(const Box3d &wsBounds, float *result, MinMaxMode mode)
1377 : m_wsBounds(wsBounds), m_result(result), m_mode(mode)
1378 { }
1380 template <typename T>
1381 void operator()(const T &vec) const
1382 {
1383 if (m_mode == Min) {
1384 FieldSampler<T, Dims_T>::getMinMaxPrefilt(vec, m_wsBounds, m_result,
1386 } else {
1387 FieldSampler<T, Dims_T>::getMinMaxPrefilt(vec, m_wsBounds, m_result,
1389 }
1390 }
1391 // Data members
1393 float *m_result;
1395};
1396
1397//------------------------------------------------------------------------------
1398
1399template <typename BaseTypeList_T, int Dims_T>
1400struct FieldGroup<BaseTypeList_T, Dims_T>::MemSize
1401{
1403 MemSize(long long int &memSize)
1404 : m_memSize(&memSize)
1405 { }
1407 template <typename T>
1408 void operator()(const T &vec) const
1409 {
1410 for (size_t field = 0, end = vec.size(); field < end; ++field) {
1411 *m_memSize += vec[field].field->memSize();
1412 }
1413 }
1415 long long int result() const
1416 { return m_memSize; }
1417 // Data members
1418 long long int *m_memSize;
1419};
1420
1421//------------------------------------------------------------------------------
1422
1423template <typename BaseTypeList_T, int Dims_T>
1424struct FieldGroup<BaseTypeList_T, Dims_T>::PointIsect
1425{
1427 PointIsect(const V3d &wsP)
1428 : m_wsP(wsP), m_doesIntersect(false)
1429 { }
1431 template <typename T>
1432 void operator()(const T &vec) const
1433 {
1434 for (size_t field = 0, end = vec.size(); field < end; ++field) {
1435 // Loop over fields in vector
1436 for (size_t i = 0, end = vec.size(); i < end; ++i) {
1437 V3d vsP;
1438 // Apply world to object transform
1439 if (vec[i].doOsToWs) {
1440 V3d osP;
1441 vec[i].wsToOs.multVecMatrix(m_wsP, osP);
1442 vec[i].mapping->worldToVoxel(osP, vsP);
1443 } else {
1444 vec[i].mapping->worldToVoxel(m_wsP, vsP);
1445 }
1446 // Sample
1447 if (vec[i].vsBounds.intersects(vsP)) {
1448 m_doesIntersect = true;
1449 }
1450 }
1451 }
1452 }
1454 bool result() const
1455 { return m_doesIntersect; }
1456private:
1457 // Data members
1460};
1461
1462//----------------------------------------------------------------------------//
1463
1465
1466//------------------------------------------------------------------------------
1467
1468#endif // include guard
1469
1470//------------------------------------------------------------------------------
Contains the DenseField class.
Contains the Field3DFile classes.
MinMaxMode
FIELD3D_NAMESPACE_OPEN typedef mpl::vector< Field3D::half, float, double > ScalarTypes
Definition FieldGroup.h:50
FieldGroup< ScalarTypes, 1 > ScalarFieldGroup
Definition FieldGroup.h:475
FieldGroup< VectorTypes, 3 > VectorFieldGroup
Definition FieldGroup.h:476
mpl::vector< Field3D::V3h, Field3D::V3f, Field3D::V3d > VectorTypes
Definition FieldGroup.h:51
Contains the FieldInterp base class and some standard interpolation classes.
Contains the initIO function.
FIELD3D_API size_t numIOThreads()
Returns the number of I/O threads to use.
Definition InitIO.cpp:92
Contains the MIPField class.
Contains MIP-related utility functions.
Contains MIP-related utility functions.
Contains the SparseField class.
Imath::Box3d Box3d
Definition SpiMathLib.h:79
Imath::V3d V3d
Definition SpiMathLib.h:74
Imath::Plane3d Plane3d
Definition SpiMathLib.h:83
Imath::M44d M44d
Definition SpiMathLib.h:82
Imath::Line3d Ray3d
Definition StdMathLib.h:94
std::vector< Interval > IntervalVec
Definition Types.h:87
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
Provides reading of .f3d (internally, hdf5 or Ogawa) files.
bool open(const std::string &filename)
Opens the given file.
Base class for mapping between world-, local- and voxel coordinates.
virtual void localToWorld(const V3d &lsP, V3d &wsP) const =0
Transform from local space position into world space.
std::vector< Ptr > Vec
Definition Field.h:214
Represents the mapping of a field by a perspective transform.
virtual void localToWorld(const V3d &lsP, V3d &wsP) const
Transform from local space position into world space.
virtual V3d wsVoxelSize(int i, int j, int k) const
Returns world-space size of a voxel at the specified coordinate.
Represents the mapping of a field by a matrix transform.
virtual V3d wsVoxelSize(int, int, int) const
Returns world-space size of a voxel at the specified coordinate.
virtual void worldToLocal(const V3d &wsP, V3d &lsP) const
Transform from world space position into local space.
void worldToLocalDir(const V3d &wsV, V3d &lsV) const
boost::shared_ptr< ValueRemapOp > Ptr
static const char * k_minSuffix
Definition FieldGroup.h:61
std::vector< V3d > cornerPoints(const Box3d &box)
Definition FieldGroup.h:211
std::vector< V3d > unitCornerPoints()
Definition FieldGroup.h:228
bool intersect(const Ray3d &ray, const Box3d &box, double &outT0, double &outT1)
Definition FieldGroup.h:245
static const char * k_maxSuffix
Definition FieldGroup.h:62
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58
void operator()(const T &vec) const
Functor.
Definition FieldGroup.h:985
void operator()(WrapperVec_T &vec) const
Functor.
Definition FieldGroup.h:964
bool m_doWsBoundsOptimization
Enable world space bounds optimization.
Definition FieldGroup.h:971
DoWsBoundsOptimization(const bool doWsBoundsOptimization)
Ctor.
Definition FieldGroup.h:959
void intersectFrustumMapping(const Ray3d &wsRay, const FrustumFieldMapping *mtx, const float worldScale) const
Intersect frustum mapping.
void intersectMatrixMapping(const Ray3d &wsRay, const MatrixFieldMapping *mtx, const float worldScale) const
Intersect matrix mapping.
GetIntersections(const Ray3d &wsRay, IntervalVec &intervals)
Ctor.
void operator()(const T &vec) const
Functor.
void operator()(const T &vec) const
Functor.
GetMinMaxMIP(const Box3d &wsBounds, float *min, float *max)
Ctor.
void operator()(const T &vec) const
Functor.
GetMinMaxPrefilt(const Box3d &wsBounds, float *result, MinMaxMode mode)
Ctor.
const Box3d & m_wsBounds
GetMinMax(const Box3d &wsBounds, float *min, float *max)
Ctor.
void operator()(const T &vec) const
Functor.
void operator()(const T &vec) const
Functor.
GetWsBounds(Box3d &wsBounds)
Ctor.
GrabFields(Field3D::FieldRes::Ptr f, const M44d &osToWs, ValueRemapOp::Ptr op, const bool doWsBoundsOptimization)
Ctor.
Definition FieldGroup.h:902
M44d m_osToWs
Object to world transform.
Definition FieldGroup.h:946
void operator()(WrapperVec_T &vec) const
Functor.
Definition FieldGroup.h:911
bool m_doWsBoundsOptimization
Enable world space bounds optimization.
Definition FieldGroup.h:950
ValueRemapOp::Ptr m_op
Value remap operator.
Definition FieldGroup.h:948
Field3D::FieldRes::Ptr m_field
The field to work on. Will be matched against the type of operator().
Definition FieldGroup.h:944
MakeMinMaxMIP(Field3D::FieldRes::Vec &minFields, Field3D::FieldRes::Vec &maxFields, const float resMult)
Ctor.
void operator()(const WrapperVec_T &vec)
Functor.
Field3D::FieldRes::Vec & m_maxFields
Field3D::FieldRes::Vec & m_minFields
Field3D::FieldRes::Vec & m_minFields
void operator()(const WrapperVec_T &vec)
Functor.
const size_t m_numThreads
MakeMinMax(Field3D::FieldRes::Vec &minFields, Field3D::FieldRes::Vec &maxFields, const float resMult)
Ctor.
Definition FieldGroup.h:997
Field3D::FieldRes::Vec & m_maxFields
long long int * m_memSize
MemSize(long long int &memSize)
Ctor.
void operator()(const T &vec) const
Functor.
long long int result() const
Result.
PointIsect(const V3d &wsP)
Ctor.
bool result() const
Result.
void operator()(const T &vec) const
Functor.
SampleMIPMultiple(const size_t n, const float *p, const float *wsSpotSize, float *result, size_t *numHits)
Ctor.
void operator()(const T &vec) const
Functor.
SampleMIP(const V3d &p, const float wsSpotSize, float *result, size_t &numHits)
Ctor.
void operator()(const T &vec) const
Functor.
const float m_wsSpotSize
void operator()(const T &vec) const
Functor.
SampleMultiple(const size_t n, const float *p, float *result, size_t *numHits)
Ctor.
Sample(const V3d &p, float *result, size_t &numHits)
Ctor.
void operator()(const T &vec) const
Functor.
bool hasPrefiltMinMax() const
Whether the FieldGroup has a pre-filtered min/max representation.
Definition FieldGroup.h:412
void sampleMIPMultiple(const size_t n, const float *wsP, const float *wsSpotSize, float *result) const
Samples all the MIP fields in the group.
Definition FieldGroup.h:795
ValueRemapOp::Ptr m_valueRemapOp
Current value remap op. Defaults to null pointer.
Definition FieldGroup.h:445
int load(const std::string &filename, const std::string &attribute)
Loads all fields from a given file and optional attribute pattern.
Definition FieldGroup.h:620
void sampleMIP(const V3d &vsP, const float wsSpotSize, float *result, bool isVs) const
Samples all the MIP fields in the group.
Definition FieldGroup.h:779
void makeMinMax(const float resMult)
Make min/max representations of the fields in the group.
Definition FieldGroup.h:669
mpl::transform< MPLBaseTypes, detail::MakeSparse< ph::_1 > >::type MPLSparseTypes
Definition FieldGroup.h:316
bool m_doWsBoundsOptimization
Enable world space bounds optimization.
Definition FieldGroup.h:442
virtual size_t size() const
The number of fields in the group.
Definition FieldGroup.h:689
virtual void setWsBoundsOptimization(const bool doWsBoundsOptimization)
Enable world axis aligned bounding box in lookups. This will be used for subsequent setup() and load(...
Definition FieldGroup.h:511
MIPSparseTypes m_mipSparse
Definition FieldGroup.h:433
void setOsToWs(const Imath::M44d &osToWs)
Sets the current object to world transform. This will be used for subsequent setup() and load() calls...
Definition FieldGroup.h:502
mpl::transform< MPLBaseTypes, detail::MakeDense< ph::_1 > >::type MPLDenseTypes
Definition FieldGroup.h:313
void setupMinMax(const FieldRes::Vec &minFields, const FieldRes::Vec &maxFields)
Set up the min/max MIP representations.
Definition FieldGroup.h:585
MIPDenseTypes m_mipDenseMin
Definition FieldGroup.h:432
DenseTypes m_dense
Definition FieldGroup.h:430
const FieldRes::Vec & fields() const
Returns a vector of FieldRes::Ptrs to the fields in the group.
Definition FieldGroup.h:417
bool getIntersections(const Ray3d &ray, IntervalVec &intervals) const
Gets the intersection intervals between the ray and the fields.
Definition FieldGroup.h:841
fusion_ro::as_vector< MPLMIPSparseTypes >::type MIPSparseTypes
Definition FieldGroup.h:328
void sampleMultiple(const size_t n, const float *wsP, float *result) const
Samples the fields in the group.
Definition FieldGroup.h:764
virtual void setup(const Field3D::FieldRes::Ptr field)
Adds a single field to the group.
Definition FieldGroup.h:538
MIPSparseTypes m_mipSparseMax
Definition FieldGroup.h:433
fusion_ro::as_vector< MPLDenseTypes >::type DenseTypes
Definition FieldGroup.h:325
FieldRes::Vec m_allFields
Stores all the fields owned by the FieldGroup.
Definition FieldGroup.h:448
FieldRes::Vec m_auxFields
Stores all the auxiliary fields owned by the FieldGroup.
Definition FieldGroup.h:450
FieldGroup()
Default constructor, does nothing.
Definition FieldGroup.h:483
M44d m_osToWs
Current object to world transform.
Definition FieldGroup.h:439
fusion_ro::as_vector< MPLMIPDenseTypes >::type MIPDenseTypes
Definition FieldGroup.h:327
size_t sizeMIP() const
The number of MIP fields in the group.
Definition FieldGroup.h:703
bool m_hasPrefiltMinMax
Whether pre-filtered min/max are present.
Definition FieldGroup.h:436
SparseTypes m_sparse
Definition FieldGroup.h:431
bool intersects(const V3d &wsP) const
Whether the given point intersects any of the fields in the FieldGroup.
Definition FieldGroup.h:826
MIPDenseTypes m_mipDense
Definition FieldGroup.h:432
void getMinMax(const Box3d &wsBounds, float *min, float *max) const
Returns the min/max range within a given bounding box.
Definition FieldGroup.h:855
mpl::transform< MPLBaseTypes, detail::MakeMIPDense< ph::_1 > >::type MPLMIPDenseTypes
Definition FieldGroup.h:319
BaseTypeList_T MPLBaseTypes
Definition FieldGroup.h:308
MIPSparseTypes m_mipSparseMin
Definition FieldGroup.h:433
Box3d wsBounds() const
Returns the bounds of the group.
Definition FieldGroup.h:811
static const int k_missingFile
Used by load() to indicate missing file.
Definition FieldGroup.h:341
long long int memSize() const
Returns the memory use in bytes for the fields in the group.
Definition FieldGroup.h:883
MIPDenseTypes m_mipDenseMax
Definition FieldGroup.h:432
fusion_ro::as_vector< MPLSparseTypes >::type SparseTypes
Definition FieldGroup.h:326
mpl::transform< MPLBaseTypes, detail::MakeMIPSparse< ph::_1 > >::type MPLMIPSparseTypes
Definition FieldGroup.h:322
void setValueRemapOp(ValueRemapOp::Ptr op)
Sets the current ValueRemap operator. This will be used for subsequent setup() and load() calls....
Definition FieldGroup.h:529
void sample(const V3d &wsP, const float wsSpotSize, const float time, float *result, const CompositeOp compOp=Add)
Unified sampling of the group's fields. Will handle both MIP and non-MIP data with optional compositi...
Definition FieldGroup.h:715
Interface for sampling a vector of fields of the same type.
static void sampleMIP(const WrapperVec_T &f, const V3d &wsP, const float wsSpotSize, float *value, size_t &numHits)
static void sample(const WrapperVec_T &f, const V3d &wsP, float *value, size_t &numHits)
static void sampleMultiple(const WrapperVec_T &f, const size_t neval, const float *wsPs, float *value, size_t *numHits)
static void getMinMaxMIP(const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
static void getMinMax(const WrapperVec_T &f, const Box3d &wsBounds, float *min, float *max)
static void sampleMIPMultiple(const WrapperVec_T &f, const size_t neval, const float *wsPs, const float *wsSpotSizes, float *value, size_t *numHits)
static void getMinMaxPrefilt(const WrapperVec_T &f, const Box3d &wsBounds, float *result, const Mode mode)
This class wraps up a single field to make its interpolator and its mapping easily accessible....
Represents a single integration interval. The interval is assumed to be inclusive,...
Definition Types.h:66
This class wraps up a single MIP field to make its interpolator and its mapping easily accessible....
Field3D::Field3DInputFile & in
Definition FieldGroup.h:124
LoadFieldsParams(Field3D::Field3DInputFile &a_in, const std::string &a_name, const std::string &a_attribute, Field3D::FieldRes::Vec &a_results, Field3D::FieldRes::Vec &a_minResults, Field3D::FieldRes::Vec &a_maxResults)
Definition FieldGroup.h:111
Field3D::FieldRes::Vec & minResults
Definition FieldGroup.h:128
Field3D::FieldRes::Vec & maxResults
Definition FieldGroup.h:129
Field3D::FieldRes::Vec & results
Definition FieldGroup.h:127
const std::string & attribute
Definition FieldGroup.h:126
const std::string & name
Definition FieldGroup.h:125
LoadFieldsParams & m_p
Definition FieldGroup.h:166
LoadFields(LoadFieldsParams &params)
Definition FieldGroup.h:136
LoadFields(LoadFieldsParams &params)
Definition FieldGroup.h:173
LoadFieldsParams & m_p
Definition FieldGroup.h:205
MPL utility.
Definition FieldGroup.h:69
FieldWrapper< Field3D::DenseField< T > >::Vec type
Definition FieldGroup.h:70
MIPFieldWrapper< Field3D::MIPField< Field3D::DenseField< T > > >::Vec type
Definition FieldGroup.h:90
MIPFieldWrapper< Field3D::MIPField< Field3D::SparseField< T > > >::Vec type
Definition FieldGroup.h:101
MPL utility.
Definition FieldGroup.h:78
FieldWrapper< Field3D::SparseField< T > >::Vec type
Definition FieldGroup.h:79