MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
dlaBrownian.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file dlaBrownian.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Read a TIFF image and simulate brownian diffusion limited aggregation of blue pixels.@EOL
7 @keywords dla fractal brownian motion brown
8 @parblock
9 Copyright (c) 1988-2015, Mitchell Jay Richling <https://www.mitchr.me> All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
12
13 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
14
15 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17
18 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
19 without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 @endparblock
28*/
29/*******************************************************************************************************************************************************.H.E.**/
30/** @cond exj */
31
32//--------------------------------------------------------------------------------------------------------------------------------------------------------------
33#include "ramCanvas.hpp"
34
35//--------------------------------------------------------------------------------------------------------------------------------------------------------------
36int main(int argc, char *argv[]) {
37 int numHits = 1, numHitsRel = 0, numClipRel = 0, numCloseRel = 0, linesPrinted = 0;
38 std::random_device rd;
39 std::minstd_rand0 rEng(rd());
40 std::chrono::time_point<std::chrono::system_clock> startTime = std::chrono::system_clock::now();
41 mjr::ramCanvas3c8b theRamCanvas(7680/2, 4320/2, -2.2, 2.2, -2.2, 2.2);
42 theRamCanvas.clrCanvas(mjr::ramCanvas3c8b::colorType(255, 0, 0));
43 int MAXNUMPT = 524288; // Number of random points to pick
44 int MAXCOUNT = 524288; // Number of times to move each random point
45
46 if((argc < 3) || (argc > 5)) {
47 std::cout << "ERROR: Useage: dlaBrownian inFile.tiff outFile.tiff [ITERATIONS [POINTS]]" << std::endl;
48 }
49
50 if(theRamCanvas.readTIFFfile(argv[1])) {
51 std::cout << "ERROR: Problem with file: " << argv[2] << std::endl;
52 return 1;
53 }
54
55 if(argc > 3)
56 MAXCOUNT = std::stoi(argv[3]);
57 if(argc > 4)
58 MAXNUMPT = std::stoi(argv[4]);
59
60 for(int numPt=1;numPt<MAXNUMPT;numPt++) {
61 // Get a random point not near the tree
62 mjr::ramCanvas3c8b::coordIntType x, y;
63 x = rEng() % theRamCanvas.getNumPixX();
64 y = rEng() % theRamCanvas.getNumPixY();
65 if(theRamCanvas.getPxColor(x+0, y+0).getC2()) {
66 numCloseRel++;
67 } else {
68 // move arround till we go out of range, or hit the tree
69 for(int count=0;count<MAXCOUNT;count++) {
70 mjr::ramCanvas3c8b::colorType aColor;
71 int rn = rEng() % 8;
72 switch (rn) {
73 case 0:
74 x++; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
75 case 1:
76 x--; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
77 case 2:
78 y++; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
79 case 3:
80 y--; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
81 case 4:
82 x++; y++; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
83 case 5:
84 x++; y--; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
85 case 6:
86 x--; y++; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
87 case 7:
88 x--; y--; aColor = mjr::ramCanvas3c8b::colorType(0, 0, 255); break;
89 }
90 if(x<1 || y<1 || x>(theRamCanvas.getNumPixX()-2) || y>(theRamCanvas.getNumPixY()-2)) {
91 numClipRel++;
92 break;
93 }
94 if(theRamCanvas.getPxColor(x+1, y+0).getC2() ||
95 theRamCanvas.getPxColor(x-1, y+0).getC2() ||
96 theRamCanvas.getPxColor(x+0, y+1).getC2() ||
97 theRamCanvas.getPxColor(x+0, y-1).getC2() ||
98 theRamCanvas.getPxColor(x+1, y+1).getC2() ||
99 theRamCanvas.getPxColor(x+1, y-1).getC2() ||
100 theRamCanvas.getPxColor(x-1, y+1).getC2() ||
101 theRamCanvas.getPxColor(x-1, y-1).getC2()
102 ) {
103 theRamCanvas.drawPoint(x, y, aColor);
104 numHits++;
105 numHitsRel++;
106 break;
107 }
108 }
109 }
110 if((numPt%1024)==0) {
111 if(linesPrinted == 0) {
112 std::cout << std::setw(10) << "HITS/1k" << " " << std::setw(10) << "CLIPS/1k" << " " << std::setw(10) << "CLOSE/1k";
113 std::cout << " " << std::setw(10) << "HITS" << " @ " << std::setw(10) << "POINTS" << std::endl;
114 }
115 linesPrinted++;
116 if(linesPrinted > 20)
117 linesPrinted = 0;
118 std::cout << std::setw(10) << numHitsRel << " " << std::setw(10) << numClipRel << " " << std::setw(10) << numCloseRel;
119 std::cout << " " << std::setw(10) << numHits << " @ " << std::setw(10) << numPt << std::endl;
120 numCloseRel = 0;
121 numHitsRel = 0;
122 numClipRel = 0;
123 }
124 }
125 if(theRamCanvas.writeTIFFfile(argv[2])) {
126 std::cout << "ERROR: Problem with file: " << argv[2] << std::endl;
127 return 1;
128 }
129
130 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
131 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
132}
133/** @endcond */
int main(int argc, char *argv[])