MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
dlaDrift.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file dlaDrift.cpp
5 @author Mitch Richling <https://www.mitchr.me>
6 @brief Read a TIFF image and simulate diffusion limited aggregation with drift 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 = static_cast<int>(rEng() % theRamCanvas.getNumPixX());
64 y = static_cast<int>(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 int rn = static_cast<int>(rEng() % 5);
71 switch (rn) {
72 case 0:
73 x++; break;
74 case 1:
75 x--; break;
76 case 2:
77 y++; break;
78 case 3:
79 x++; y++; break;
80 case 4:
81 x--; y++; break;
82 }
83 if(x<1 || y<1 || x>(theRamCanvas.getNumPixX()-2) || y>(theRamCanvas.getNumPixY()-2)) {
84 numClipRel++;
85 break;
86 }
87 if(theRamCanvas.getPxColor(x+1, y+0).getC2() ||
88 theRamCanvas.getPxColor(x-1, y+0).getC2() ||
89 theRamCanvas.getPxColor(x+0, y+1).getC2() ||
90 theRamCanvas.getPxColor(x+0, y-1).getC2() ||
91 theRamCanvas.getPxColor(x+1, y+1).getC2() ||
92 theRamCanvas.getPxColor(x+1, y-1).getC2() ||
93 theRamCanvas.getPxColor(x-1, y+1).getC2() ||
94 theRamCanvas.getPxColor(x-1, y-1).getC2()
95 ) {
96 theRamCanvas.drawPoint(x, y, mjr::ramCanvas3c8b::colorType(0, 0, 255));
97 numHits++;
98 numHitsRel++;
99 break;
100 }
101 }
102 }
103 if((numPt%1024)==0) {
104 if(linesPrinted == 0) {
105 std::cout << std::setw(10) << "HITS/1k" << " " << std::setw(10) << "CLIPS/1k" << " " << std::setw(10) << "CLOSE/1k";
106 std::cout << " " << std::setw(10) << "HITS" << " @ " << std::setw(10) << "POINTS" << std::endl;
107 }
108 linesPrinted++;
109 if(linesPrinted > 20)
110 linesPrinted = 0;
111 std::cout << std::setw(10) << numHitsRel << " " << std::setw(10) << numClipRel << " " << std::setw(10) << numCloseRel;
112 std::cout << " " << std::setw(10) << numHits << " @ " << std::setw(10) << numPt << std::endl;
113 numCloseRel = 0;
114 numHitsRel = 0;
115 numClipRel = 0;
116 }
117 }
118 if(theRamCanvas.writeTIFFfile(argv[2])) {
119 std::cout << "ERROR: Problem with file: " << argv[2] << std::endl;
120 return 1;
121 }
122
123 std::chrono::duration<double> runTime = std::chrono::system_clock::now() - startTime;
124 std::cout << "Total Runtime " << runTime.count() << " sec" << std::endl;
125}
126/** @endcond */
int main(int argc, char *argv[])