ug4
Loading...
Searching...
No Matches
raster_impl.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016: G-CSC, Goethe University Frankfurt
3 * Author: Sebastian Reiter
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG_raster_impl
34#define __H__UG_raster_impl
35
36#include <limits>
37#include <cstring>
38#include <algorithm>
39#include <fstream>
40#include "common/error.h"
43#include "raster_kernels.h"
44
45namespace ug{
46
48// Raster::MultiIndex
49
50template <class T, int TDIM>
54
55template <class T, int TDIM>
57MultiIndex(size_t i)
58{
59 set(i);
60}
61
62template <class T, int TDIM>
64dim () const
65{
66 return TDIM;
67}
68
69template <class T, int TDIM>
71set (size_t i)
72{
73 for(int d = 0; d < TDIM; ++d)
74 m_ind[d] = i;
75}
76
77template <class T, int TDIM>
79operator[] (int d)
80{
81 return m_ind[d];
82}
83
84template <class T, int TDIM>
86operator[] (int d) const
87{
88 return m_ind[d];
89}
90
91
93// Raster::Coordinate
94
95template <class T, int TDIM>
99
100template <class T, int TDIM>
106
107template <class T, int TDIM>
110{
111 for(int d = 0; d < TDIM; ++d)
112 m_coord[d] = v[d];
113}
114
115template <class T, int TDIM>
117dim () const
118{
119 return TDIM;
120}
121
122template <class T, int TDIM>
124set (number c)
125{
126 for(int d = 0; d < TDIM; ++d)
127 m_coord[d] = c;
128}
129
130
131template <class T, int TDIM>
133operator[] (int d)
134{
135 return m_coord[d];
136}
137
138template <class T, int TDIM>
140operator[] (int d) const
141{
142 return m_coord[d];
143}
144
145template <class T, int TDIM>
147operator+= (const Coordinate& c)
148{
149 for(int d = 0; d < TDIM; ++d)
150 m_coord[d] += c[d];
151}
152
153template <class T, int TDIM>
155operator-= (const Coordinate& c)
156{
157 for(int d = 0; d < TDIM; ++d)
158 m_coord[d] -= c[d];
159}
160
161template <class T, int TDIM>
164{
165 for(int d = 0; d < TDIM; ++d)
166 m_coord[d] *= s;
167}
168
169
170
172// Raster - public
173
174template <class T, int TDIM>
176Raster () :
177 m_data(NULL),
178 m_numNodes(0),
179 m_selNode(0),
180 m_minCorner(0),
181 m_extension(1),
183 m_cursor(0),
185 m_noDataValue(std::numeric_limits<T>::max())
186{
189}
190
191
192template <class T, int TDIM>
194Raster (const Raster<T, TDIM>& raster) :
195 m_data(NULL),
196 m_numNodes(raster.m_numNodes),
197 m_selNode(raster.m_selNode),
198 m_minCorner(raster.m_minCorner),
199 m_extension(raster.m_extension),
200 m_cellExtension(raster.m_cellExtension),
201 m_cursor(raster.m_cursor),
202 m_numNodesTotal(raster.m_numNodesTotal),
203 m_noDataValue(raster.m_noDataValue)
204{
207
208 create();
209
210 memcpy(m_data, raster.m_data, num_nodes_total() * sizeof(T));
211}
212
213template <class T, int TDIM>
215Raster (const MultiIndex& numNodes) :
216 m_data(NULL),
217 m_numNodes(numNodes),
218 m_selNode(0),
219 m_minCorner(0),
220 m_extension(1),
221 m_cellExtension(1),
222 m_cursor(0),
223 m_numNodesTotal(0),
224 m_noDataValue(std::numeric_limits<T>::max())
225{
227
228 for(int d = 0; d < TDIM; ++d)
229 m_extension[d] = numNodes[d] - 1;
230
232
233 create();
234}
235
236template <class T, int TDIM>
238Raster (const MultiIndex& numNodes,
239 const Coordinate& extension,
240 const Coordinate& minCorner) :
241 m_data(NULL),
242 m_numNodes(numNodes),
243 m_selNode(0),
244 m_minCorner(minCorner),
245 m_extension(extension),
246 m_cellExtension(1),
247 m_cursor(0),
248 m_numNodesTotal(0),
249 m_noDataValue(std::numeric_limits<T>::max())
250{
253 create();
254}
255
256
257template <class T, int TDIM>
259~Raster ()
260{
261 if(m_data)
262 delete[] m_data;
263}
264
265template <class T, int TDIM>
267operator= (const Raster& raster)
268{
269 m_numNodes = raster.m_numNodes;
270 m_selNode = raster.m_selNode;
271 m_minCorner = raster.m_minCorner;
272 m_extension = raster.m_extension;
273 m_cursor = raster.m_cursor;
274 m_noDataValue = raster.m_noDataValue;
275
276 update_num_nodes_total();
277 update_cell_extension();
278
279 create();
280
281 memcpy(m_data, raster.m_data, num_nodes_total() * sizeof(T));
282
283 return *this;
284}
285
286template <class T, int TDIM>
288dim () const
289{
290 return TDIM;
291}
292
293template <class T, int TDIM>
295set_num_nodes (int dim, size_t num)
296{
297 m_numNodes[dim] = num;
298 update_num_nodes_total();
299 update_cell_extension(dim);
300}
301
302template <class T, int TDIM>
305{
306 m_numNodes = mi;
307 update_num_nodes_total();
308 update_cell_extension();
309}
310
311template <class T, int TDIM>
313num_nodes_total () const
314{
315 return m_numNodesTotal;
316}
317
318template <class T, int TDIM>
320num_nodes (int dim) const
321{
322 return m_numNodes[dim];
323}
324
325template <class T, int TDIM>
327num_nodes () const
328{
329 return m_numNodes;
330}
331
332
333template <class T, int TDIM>
335create ()
336{
337 if(m_data){
338 delete[] m_data;
339 m_data = NULL;
340 }
341
342 update_num_nodes_total(); // this isn't strictly necessary if everything works right.
343
344 const size_t num = num_nodes_total();
345 if(num){
346 m_data = new T[num];
347 }
348}
349
350
351template <class T, int TDIM>
353node_value (const MultiIndex& mi)
354{
355 return m_data[data_index(mi)];
356}
357
358template <class T, int TDIM>
360node_value (const MultiIndex& mi) const
361{
362 return m_data[data_index(mi)];
363}
364
365
366template <class T, int TDIM>
368set_min_corner (int dim, number coord)
369{
370 m_minCorner[dim] = coord;
371}
372
373template <class T, int TDIM>
375set_min_corner (const Coordinate& coord)
376{
377 m_minCorner = coord;
378}
379
380template <class T, int TDIM>
382min_corner () const
383{
384 return m_minCorner;
385}
386
387template <class T, int TDIM>
389min_corner (int dim) const
390{
391 return m_minCorner[dim];
392}
393
394template <class T, int TDIM>
396set_extension (int dim, number ext)
397{
398 m_extension[dim] = ext;
399 update_cell_extension(dim);
400}
401
402template <class T, int TDIM>
404set_extension (const Coordinate& ext)
405{
406 m_extension = ext;
407 update_cell_extension();
408}
409
410template <class T, int TDIM>
412extension () const
413{
414 return m_extension;
415}
416
417template <class T, int TDIM>
419extension (int dim) const
420{
421 return m_extension[dim];
422}
423
424
425template <class T, int TDIM>
427interpolate (const Coordinate& coord, int order) const
428{
429 switch(order){
430 case 0: {
431 MultiIndex mi;
432 for(size_t d = 0; d < TDIM; ++d)
433 {
434 mi[d] = static_cast<int>(0.5 + (coord[d] - m_minCorner[d]) / m_cellExtension[d]);
435 if(mi[d] < 0) mi[d] = 0;
436 else if(mi[d] >= num_nodes(d)) mi[d] = num_nodes(d) - 1;
437 }
438 return node_value(mi);
439 } break;
440
441 case 1: {
442 MultiIndex mi;
443 Coordinate lc;
444 for(size_t d = 0; d < TDIM; ++d)
445 {
446 mi[d] = static_cast<int>((coord[d] - m_minCorner[d]) / m_cellExtension[d]);
447 if(mi[d] < 0){
448 mi[d] = 0;
449 lc[d] = 0;
450 }
451 else if(mi[d] + 1 >= num_nodes(d)){
452 mi[d] = num_nodes(d) - 2;
453 lc[d] = 1;
454 }
455 else{
456 lc[d] = ( coord[d]
457 - ((number)mi[d] * m_cellExtension[d]
458 + m_minCorner[d]))
459 / m_cellExtension[d];
460 }
461 }
462
463 return interpolate_linear(mi, lc);
464 } break;
465
466 default:
467 UG_THROW("Raster::interpolate(): Unsupported interpolation order: " << order);
468 }
469 return m_noDataValue;
470}
471
472
473template <class T, int TDIM>
476{
477 m_noDataValue = val;
478}
479
480template <class T, int TDIM>
482no_data_value() const
483{
484 return m_noDataValue;
485}
486
487
488template <class T, int TDIM>
490blur(T alpha, size_t iterations)
491{
492 raster_kernels::Blur<T, TDIM> blurKernel (alpha);
493 const MultiIndex start(0);
494
495 for(size_t iiter = 0; iiter < iterations; ++iiter)
496 run_on_all (blurKernel);
497}
498
499
500template <class T, int TDIM>
501template <class TKernel>
502typename TKernel::result_t Raster<T, TDIM>::
504{
505 TKernel kernel;
506 run_on_all (MultiIndex(0), kernel, TDIM - 1);
507 return kernel.result();
508}
509
510template <class T, int TDIM>
511template <class TKernel>
513run_on_all(TKernel& kernel)
514{
515 run_on_all (MultiIndex(0), kernel, TDIM - 1);
516}
517
518
519template <class T, int TDIM>
520template <class TKernel>
522run_on_all(const MultiIndex& start, TKernel& kernel, int curDim)
523{
524 if(curDim > 0) {
525 const size_t numNodes = num_nodes(curDim);
526 for(MultiIndex cur = start; cur[curDim] < numNodes; ++cur[curDim]){
527 run_on_all(cur, kernel, curDim - 1);
528 }
529 }
530 else {
531 const size_t numNodes = num_nodes(0);
532 for(MultiIndex cur = start; cur[0] < numNodes; ++cur[0]){
533 kernel (*this, cur);
534 }
535 }
536}
537
538
539template <class T, int TDIM>
540template <class TKernel>
541typename TKernel::result_t Raster<T, TDIM>::
542run_on_nbrs(const MultiIndex& center)
543{
544 TKernel kernel;
545 run_on_nbrs(center, kernel, TDIM - 1);
546 return kernel.result();
547}
548
549
550template <class T, int TDIM>
551template <class TKernel>
553run_on_nbrs(const MultiIndex& center, TKernel& kernel)
554{
555 run_on_nbrs(center, kernel, TDIM - 1);
556}
557
558
559template <class T, int TDIM>
560template <class TKernel>
562run_on_nbrs(const MultiIndex& center, TKernel& kernel, int curDim)
563{
564 if(curDim > 0)
565 run_on_nbrs(center, kernel, curDim - 1);
566
567 if(center[curDim] > 0){
568 MultiIndex c = center;
569 --c[curDim];
570 kernel(*this, c);
571 }
572
573 if(center[curDim] + 1 < num_nodes(curDim)){
574 MultiIndex c = center;
575 ++c[curDim];
576 kernel(*this, c);
577 }
578}
579
580
581template <class T, int TDIM>
583select_node (int dim, size_t index)
584{
585 m_selNode[dim] = index;
586}
587
588template <class T, int TDIM>
590select_node (const MultiIndex& mi)
591{
592 m_selNode = mi;
593}
594
595
596template <class T, int TDIM>
599{
600 node_value(m_selNode) = val;
601}
602
603template <class T, int TDIM>
605selected_node_value () const
606{
607 return node_value(m_selNode);
608}
609
610
611template <class T, int TDIM>
613set_cursor (int dim, number coord)
614{
615 m_cursor[dim] = coord;
616}
617
618template <class T, int TDIM>
620set_cursor (const Coordinate& coord)
621{
622 m_cursor = coord;
623}
624
625
626template <class T, int TDIM>
628interpolate_at_cursor (int order) const
629{
630 return interpolate(m_cursor, order);
631}
632
633
634template <class T, int TDIM>
636load_from_asc (const char* filename)
637{
638 using namespace std;
639
640 #define LFA_ERR_WHERE "Error in Raster::load_from_asc('" << filename << "'): "
641// this macro helps with error-checks for bad dimensions
642 #define LFA_CHECK_DIM(d, line)\
643 UG_COND_THROW(d >= TDIM, LFA_ERR_WHERE << "Bad dimension '" << d <<\
644 "' in line " << line << " of file " << filename << "," <<\
645 "while trying to read a " << TDIM << "d raster.");
646
647 std::string fullFileName = FindFileInStandardPaths(filename);
648 UG_COND_THROW(fullFileName.empty(),
649 LFA_ERR_WHERE << "Couldn't find the specified file in any of the standard paths.");
650
651 ifstream in(fullFileName.c_str());
652 UG_COND_THROW(!in, LFA_ERR_WHERE << "Couldn't access file.");
653
654 MultiIndex numNodes(0);
655
656// indicate whether minCoord was specified as cell-center
657 MultiIndex minCoordIsCenter(0);
658
659 Coordinate minCoord(0);
660 Coordinate cellSize(0);
661
662 T noDataValue = T();
663
664// parse header
665// the header lenght varies between different asc files. This depends on the
666// dimension and whether equlateral cells are specified or not, i.e., whether
667// 'cellsize' or whether 'xcellsize', 'ycellsize', ... was specified.
668// We're trying to guess the correct length here.
669 int headerLen = 0;
670 if(TDIM == 1) headerLen = 4;
671 else if(TDIM == 2) headerLen = 6;
672 else if(TDIM == 3) headerLen = 8;
673 else{
674 UG_THROW("Raster::load_from_asc only supports 1, 2, and 3 dimensions\n");
675 }
676
677 for(int i = 0; i < headerLen; ++i){
678 string name;
679 double value;
680 in >> name >> value;
682 "Couldn't parse expected name-value pair in row " << i);
683
684 name = ToLower(name);
685
686 if(name.compare("ncols") == 0){
687 LFA_CHECK_DIM(0, i);
688 numNodes[0] = (int)value;
689 }
690 else if(name.compare("nrows") == 0){
691 LFA_CHECK_DIM(1, i);
692 numNodes[1] = (int)value;
693 }
694 else if(name.compare("nstacks") == 0){
695 LFA_CHECK_DIM(2, i);
696 numNodes[2] = (int)value;
697 }
698
699 else if(name.compare("xllcenter") == 0){
700 LFA_CHECK_DIM(0, i);
701 minCoord[0] = value;
702 minCoordIsCenter[0] = 1;
703 }
704 else if(name.compare("yllcenter") == 0){
705 LFA_CHECK_DIM(1, i);
706 minCoord[1] = value;
707 minCoordIsCenter[1] = 1;
708 }
709 else if(name.compare("zllcenter") == 0){
710 LFA_CHECK_DIM(2, i);
711 minCoord[2] = value;
712 minCoordIsCenter[2] = 1;
713 }
714 else if(name.compare("xllcorner") == 0){
715 LFA_CHECK_DIM(0, i);
716 minCoord[0] = value;
717 }
718 else if(name.compare("yllcorner") == 0){
719 LFA_CHECK_DIM(1, i);
720 minCoord[1] = value;
721 }
722 else if(name.compare("zllcorner") == 0){
723 LFA_CHECK_DIM(2, i);
724 minCoord[2] = value;
725 }
726
727 else if(name.compare("cellsize") == 0){
728 for(int d = 0; d < TDIM; ++d)
729 cellSize[d] = value;
730 }
731
732 else if(name.compare("xcellsize") == 0){
733 LFA_CHECK_DIM(0, i);
734 // we have to read additional cell-sizes for the other dimensions
735 headerLen += (TDIM - 1);
736 cellSize[0] = value;
737 }
738 else if(name.compare("ycellsize") == 0){
739 LFA_CHECK_DIM(1, i);
740 cellSize[1] = value;
741 }
742 else if(name.compare("zcellsize") == 0){
743 LFA_CHECK_DIM(2, i);
744 cellSize[2] = value;
745 }
746
747 else if(name.compare("nodata_value") == 0){
748 noDataValue = value;
749 }
750
751 else{
752 UG_THROW(LFA_ERR_WHERE << "unknown identifier in header: " << name);
753 }
754 }
755
756 for(int d = 0; d < TDIM; ++d){
757 if(minCoordIsCenter[d])
758 minCoord[d] -= 0.5 * cellSize[d];
759 }
760
761// check validity
762 for(int d = 0; d < TDIM; ++d){
763 UG_COND_THROW(numNodes[d] == 0, LFA_ERR_WHERE << "Num nodes may not be 0 for dim " << d);
764 UG_COND_THROW(cellSize[d] <= 0, LFA_ERR_WHERE << "cell-size must be bigger than 0 for dim " << d);
765 }
766
767 set_num_nodes(numNodes);
768 set_min_corner(minCoord);
769 Coordinate extension = cellSize;
770 for(int d = 0; d < TDIM; ++d)
771 extension[d] *= (number)(numNodes[d] - 1);
772 set_extension(extension);
773 set_no_data_value(noDataValue);
774
775 create();
776
777// parse values
778// y and z are inverted
779 size_t num[3] = {0, 1, 1};
780 for(size_t i = 0; i < TDIM; ++i)
781 num[i] = m_numNodes[i];
782
783 for(size_t iz = 0; iz < num[2]; ++iz){
784 for(size_t iy = 0; iy < num[1]; ++iy){
785 for(size_t ix = 0; ix < num[0]; ++ix)
786 {
787 const size_t ty = num[1] - 1 - iy;
788 const size_t tz = num[2] - 1 - iz;
789 in >> m_data[ix + num[0] * (ty + num[1] * tz)];
790 UG_COND_THROW(!in, LFA_ERR_WHERE << "Couldn't read value for at ("
791 << ix << ", " << iy << ", " << iz << ")");
792 }
793 }
794 }
795}
796
797template <class T, int TDIM>
799save_to_asc (const char* filename) const
800{
801 using namespace std;
802 #define STA_ERR_WHERE "Error in Raster::save_to_asc('" << filename << "'): "
803
804 UG_COND_THROW(!m_data, STA_ERR_WHERE << "Can't write an unitinialized raster."
805 "Please call 'create' or 'load_from_asc' first.");
806
807 ofstream out(filename);
808 UG_COND_THROW(!out, STA_ERR_WHERE << "Couldn't open file for writing.");
809
810 out << "ncols " << num_nodes(0) << endl;
811 if(TDIM > 1)
812 out << "nrows " << num_nodes(1) << endl;
813 if(TDIM > 2)
814 out << "nstacks " << num_nodes(2) << endl;
815
816 out << "xllcorner " << setprecision(16) << min_corner(0) << endl;
817 if(TDIM > 1)
818 out << "yllcorner " << setprecision(16) << min_corner(1) << endl;
819 if(TDIM > 2)
820 out << "zllcorner " << setprecision(16) << min_corner(2) << endl;
821
822 bool equlateralCells = true;
823 for(int d = 1; d < TDIM; ++d){
824 if(m_cellExtension[d] != m_cellExtension[0]){
825 equlateralCells = false;
826 break;
827 }
828 }
829
830 if(equlateralCells)
831 out << "cellsize " << m_cellExtension[0] << endl;
832 else{
833 out << "xcellsize " << m_cellExtension[0] << endl;
834 if(TDIM > 1)
835 out << "ycellsize " << m_cellExtension[1] << endl;
836 if(TDIM > 2)
837 out << "zcellsize " << m_cellExtension[2] << endl;
838 }
839
840 out << "NODATA_value " << no_data_value() << endl;
841
842// write values
843// y and z are inverted
844 size_t num[3] = {0, 1, 1};
845 for(size_t i = 0; i < TDIM; ++i)
846 num[i] = num_nodes(i);
847
848 for(size_t iz = 0; iz < num[2]; ++iz){
849 for(size_t iy = 0; iy < num[1]; ++iy){
850 for(size_t ix = 0; ix < num[0]; ++ix)
851 {
852 if(ix > 0)
853 out << " ";
854 const size_t ty = num[1] - 1 - iy;
855 const size_t tz = num[2] - 1 - iz;
856 out << m_data[ix + num[0] * (ty + num[1] * tz)];
857 }
858 out << endl;
859 }
860 out << endl;
861 }
862 out << endl;
863}
864
866// Raster - private
867template <class T, int TDIM>
869data_index (const MultiIndex& mi, int curDim, size_t curVal) const
870{
871 if(curDim == 0)
872 return curVal + mi[0];
873 else{
874 return data_index(mi, curDim - 1, m_numNodes[curDim - 1] * (mi[curDim] + curVal));
875 }
876}
877
878template <class T, int TDIM>
881{
882 m_numNodesTotal = 1;
883 for(int d = 0; d < TDIM; ++d)
884 m_numNodesTotal *= num_nodes(d);
885}
886
887template <class T, int TDIM>
890{
891 for(int d = 0; d < TDIM; ++d)
892 update_cell_extension(d);
893}
894
895template <class T, int TDIM>
898{
899 if(m_numNodes[dim] > 1 && m_extension[dim] > 0)
900 m_cellExtension[dim] = m_extension[dim] / (m_numNodes[dim] - 1);
901 else
902 m_cellExtension[dim] = 1;
903}
904
905
906template <class T, int TDIM>
909 const MultiIndex& minNodeInd,
910 Coordinate& localCoord,
911 int curDim) const
912{
913 if(curDim == 0)
914 return node_value(minNodeInd);
915
916 MultiIndex miMax = minNodeInd;
917 miMax[curDim - 1] += 1;
918
919 T val0 = interpolate_linear(minNodeInd, localCoord, curDim - 1);
920 T val1 = interpolate_linear(miMax, localCoord, curDim - 1);
921
922// perform linear interpolation
923 val0 *= (1. - localCoord[curDim - 1]);
924 val1 *= localCoord[curDim - 1];
925 val0 += val1;
926 return val0;
927}
928
929}// end of namespace
930
931#endif //__H__UG_raster_impl
parameterString s
location name
Definition checkpoint_util.lua:128
a mathematical Vector with N entries.
Definition math_vector.h:97
Definition raster.h:100
Coordinate & operator-=(const Coordinate &c)
Definition raster_impl.hpp:155
Coordinate()
Definition raster_impl.hpp:97
Coordinate & operator*=(number s)
Definition raster_impl.hpp:163
number & operator[](int d)
Definition raster_impl.hpp:133
Coordinate & operator+=(const Coordinate &c)
Definition raster_impl.hpp:147
int dim() const
Definition raster_impl.hpp:117
void set(number c)
Definition raster_impl.hpp:124
Definition raster.h:75
int dim() const
Definition raster_impl.hpp:64
void set(size_t i)
Definition raster_impl.hpp:71
MultiIndex()
Definition raster_impl.hpp:52
size_t & operator[](int d)
Definition raster_impl.hpp:79
Generic raster for arbitrary dimensions.
Definition raster.h:73
void set_cursor(int dim, number coord)
Set the coordinate of the cursor. The cursor can be used to interpolate values.
Definition raster_impl.hpp:613
T & node_value(const MultiIndex &mi)
returns the value at the given multi-index (read/write)
Definition raster_impl.hpp:353
Raster()
Creates an empty raster that has to be initialized before use.
Definition raster_impl.hpp:176
size_t num_nodes_total() const
returns the total number of nodes in the raster
Definition raster_impl.hpp:313
void select_node(int dim, size_t index)
Select a node. 'selected_node_value' provides read/write access to the selected node.
Definition raster_impl.hpp:583
const Coordinate & min_corner() const
returns the min-corner of the raster
Definition raster_impl.hpp:382
void set_num_nodes(int dim, size_t num)
sets the number of nodes that shall be used by the raster.
Definition raster_impl.hpp:295
MultiIndex m_selNode
Definition raster.h:329
void blur(T alpha, size_t iterations)
blurs (smoothens) the values by repeatedly averaging between direct neighbors
Definition raster_impl.hpp:490
Coordinate m_extension
Definition raster.h:331
T interpolate_linear(const MultiIndex &minNodeInd, Coordinate &localCoord, int curDim=TDIM) const
Definition raster_impl.hpp:908
void update_num_nodes_total()
Definition raster_impl.hpp:880
Coordinate m_cursor
Definition raster.h:333
T * m_data
Definition raster.h:327
TKernel::result_t run_on_all()
Creates and runs the specified kernel on all nodes and returns its result.
Definition raster_impl.hpp:503
TKernel::result_t run_on_nbrs(const MultiIndex &center)
Creates and runs the specified kernel on all direct neighbors of a node and returns its result.
Definition raster_impl.hpp:542
void load_from_asc(const char *filename)
Definition raster_impl.hpp:636
T no_data_value() const
returns the value that shall be considered 'no-data-value'
Definition raster_impl.hpp:482
void set_min_corner(int dim, number coord)
sets the min corner of the raster. Used for interpolation at cursor.
Definition raster_impl.hpp:368
T interpolate_at_cursor(int order) const
interpolates the value with the given order at the cursor position
Definition raster_impl.hpp:628
MultiIndex m_numNodes
Definition raster.h:328
void set_extension(int dim, number ext)
sets the extension of the raster. Used for interpolation at cursor.
Definition raster_impl.hpp:396
Coordinate m_cellExtension
Definition raster.h:332
void set_no_data_value(T val)
sets the value that shall be considered as 'no-data-value'
Definition raster_impl.hpp:475
T m_noDataValue
Definition raster.h:335
~Raster()
Definition raster_impl.hpp:259
void create()
creates the raster. Call this method after 'set_num_nodes' has been called for each dimension.
Definition raster_impl.hpp:335
size_t m_numNodesTotal
Definition raster.h:334
size_t data_index(const MultiIndex &mi, int curDim=TDIM - 1, size_t curVal=0) const
Definition raster_impl.hpp:869
T selected_node_value() const
returns the value of the selected node
Definition raster_impl.hpp:605
Coordinate m_minCorner
Definition raster.h:330
T interpolate(const Coordinate &coord, int order) const
interpolates the value with the given order at the given coordinate
Definition raster_impl.hpp:427
Raster & operator=(const Raster &raster)
Definition raster_impl.hpp:267
void update_cell_extension()
Definition raster_impl.hpp:889
const Coordinate & extension() const
returns the extension of the raster
Definition raster_impl.hpp:412
const MultiIndex & num_nodes() const
returns the number of nodes for each dimension in a multi-index.
Definition raster_impl.hpp:327
void set_selected_node_value(T val)
sets the value of the selected node
Definition raster_impl.hpp:598
void save_to_asc(const char *filename) const
Definition raster_impl.hpp:799
int dim() const
Definition raster_impl.hpp:288
Kernel which blurs all values of a raster it was called on.
Definition raster_kernels.h:134
File utility functions.
std::string FindFileInStandardPaths(const char *filename)
searches the file in the standard paths.
Definition file_util.cpp:196
#define UG_THROW(msg)
Definition error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
double number
Definition types.h:124
function util LuaCallbackHelper create(func)
Definition smart_pointer.h:814
the ug namespace
string ToLower(string str)
Definition string_util.cpp:269
#define STA_ERR_WHERE
#define LFA_CHECK_DIM(d, line)
#define LFA_ERR_WHERE