summaryrefslogtreecommitdiffstats
path: root/dis/Neighborhood
diff options
context:
space:
mode:
authorJoshua Bakita <jbakita@cs.unc.edu>2020-10-17 14:43:46 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-17 14:43:46 -0400
commita3886552003d031acb9039e920b7c9ddce946ad6 (patch)
treec3b6a400a9ba31e744e6218365d63bdfbbc45a83 /dis/Neighborhood
parent917499f6257ac51c05e8302af877d56a22f28cb5 (diff)
DIS fixes used for (rejected) RTSS'20 submission
- All: Output times to stderr and nothing to stdout - Field, Update, Pointer: change definition of a job to match other stressmark execution times more closely - Matrix: move all allocations into main() - Update: Use volatile to prevent computations from being optimized out - Transitive: Use volatile to prevent computations from being optimized out - Neighborhood: Use working version of drawLineSegment from original DIS sample code
Diffstat (limited to 'dis/Neighborhood')
-rw-r--r--dis/Neighborhood/initializeImage.c371
-rw-r--r--dis/Neighborhood/neighborhood.c14
-rw-r--r--dis/Neighborhood/utili.h161
3 files changed, 434 insertions, 112 deletions
diff --git a/dis/Neighborhood/initializeImage.c b/dis/Neighborhood/initializeImage.c
new file mode 100644
index 0000000..a030a1a
--- /dev/null
+++ b/dis/Neighborhood/initializeImage.c
@@ -0,0 +1,371 @@
1/* Copyright 2000, Atlantic Aerospace Electronics Corp */
2/*
3 * Name: initializeImage
4 * Input: dimension dimension of image
5 * maxImageValue max legal image value
6 * numberLines number line segments for image
7 * minThickness min thickness for line segment
8 * maxThickness max thickness for line segment
9 * Output: image image initialized
10 * Comment: This routine allocates memory to store an image and fills
11 * in the image structure except for the image data. The
12 * pixels of the image are of type ShortInt. If there
13 * is an error allocating memory, than a NULL pointer is
14 * returned. Assumptions: the image dimensions given are
15 * positive.
16 * Calls: errorMessage()
17 * (system) malloc()
18 * free()
19 * Return: image structure pointer (partially filled in - no data -
20 * and allocated)
21 * NULL (error allocating memory for image/image structure)
22 *
23 * Revision History:
24 * Date Name Revision
25 * --------- ----------- -----------------------------
26 * 25May2000 May Leung Created
27 * 05Jun2000 May Leung Add maxImageValue as input to initializeImage()
28 * XXMay2020 Joshua Bakita Commented out significant portions to allow this to
29 * be #include(d) elsewhere.
30 */
31typedef int Int;
32typedef short int ShortInt;
33typedef float Float;
34void drawRowPoint (Int value,
35 Int pointThickness,
36 Int row,
37 Int column,
38 Image *image);
39void drawColumnPoint (Int value,
40 Int pointThickness,
41 Int row,
42 Int column,
43 Image *image);
44#define MIN_RANDOM_VALUE 0
45#if 0
46#ifndef NDEBUG
47#include <stdio.h>
48#endif /* NDEBUG */
49#include <assert.h> /* define assert() */
50#include <stdlib.h> /* define NULL, malloc(), free() */
51#include "stressmark.h" /* system include file */
52#include "neighborhood.h" /* define types, structures, etc */
53#include "errorMessage.h" /* define errorMessage() */
54#include "random.h" /* define randomUInt() */
55#include "initializeImage.h" /* define initializeImage() */
56
57Image *initializeImage (Int dimension, /* dimension of image */
58 Int maxImageValue, /* max legal image value */
59 Int numberLines, /* number line segments for image */
60 Int minThickness, /* min thickness for line segment */
61 Int maxThickness) /* max thickness for line segment */
62{ /* beginning of initializeImage() */
63
64 Image *image; /* pointer to image structure to allocate */
65 ShortInt *data; /* pointer to the data for the image structure*/
66 Int lineIndex; /* loop index variable for line segments */
67 Int pixelIndex; /* loop index variable for pixels */
68 Int limit; /* limit for loop using pixelIndex */
69
70 Coord startPoint; /* starting point for a line segment */
71 Coord endPoint; /* ending point for a line segment */
72 Int lineThickness; /* thickness for a line segment */
73 Int startValue; /* starting value for a line segment */
74 Int endValue; /* ending value for a line segment */
75
76 /*
77 * Assert the assumptions that the number of columns and number of rows
78 * are positive values. No test on the maximum possible value is done since
79 * numColumns and numRows are of type Int and the maximum value of an Int
80 * type is possible.
81 */
82 assert(dimension > 0);
83 assert(numberLines > 0);
84 assert((minThickness > 0) && (minThickness < dimension));
85 assert((maxThickness > 0) && (maxThickness < dimension));
86 assert(minThickness <= maxThickness);
87
88 /* create image */
89 image = createImage(dimension,dimension,maxImageValue);
90 if (image == NULL) {
91 return(NULL);
92 } /* end error check from createImage */
93
94 /* zero out the image */
95 limit = dimension * dimension;
96 data = image->data;
97 for (pixelIndex = 0; pixelIndex < limit; pixelIndex++) {
98 *data++ = 0;
99 } /* end for loop */
100
101 /*
102 * Populate the image with line segments where the endpoints, values, and
103 * thickness of each line segment are randomly generated.
104 */
105 for (lineIndex = 0; lineIndex < numberLines; lineIndex++) {
106 randomImageLocation(image, &startPoint);
107 randomImageLocation(image, &endPoint);
108 lineThickness = randomUInt(minThickness,maxThickness);
109 startValue = randomUInt(MIN_RANDOM_VALUE, maxImageValue);
110 endValue = randomUInt(MIN_RANDOM_VALUE, maxImageValue);
111
112 /* add line segment to the image */
113 drawLineSegment(&startPoint, &endPoint, startValue, endValue, lineThickness,
114 image);
115
116 } /* end for loop */
117
118 return(image);
119} /* end initializeImage() */
120#endif
121
122/*
123 * drawLineSegment() This routine draws a line segment into the given image
124 * starting at the coordinate startPoint and ending at the
125 * coordinate endPoint. The values along this line segment
126 * vary linearly from the given starting value startValue to
127 * the end value endValue and have a lineThickness associated
128 * to it.
129 *
130 * This routine is modeled after the routine draw_line() from
131 * "Practical Computer Vision using C", by J.R. Parker, Wiley, 1994, pp 114-116.
132 * It has been enhanced to have values on the line segment vary and to have
133 * a thickness to the line segment.
134 */
135void drawLineSegment (Coord *startPoint, /* starting point for line segment */
136 Coord *endPoint, /* ending point for line segment */
137 Int startValue, /* starting value for line segment */
138 Int endValue, /* ending value for line segment */
139 Int lineThickness, /* thickness for line segment */
140 Image *image) /* image to add line segment to */
141{ /* beginning of drawLineSegment() */
142
143 /*
144 * Modeled after draw_line() from "Practical Computer Vision using C",
145 * by J.R. Parker, Wiley, 1994, pp 114-116. Enhanced to have values
146 * on the line segment vary and to have a thickness to the line segment.
147 * The value along the line segment is kept in a float variable so that
148 * fractional increments along the line segment can accumulate to integer
149 * values.
150 */
151 Int changeColumn, changeRow; /* change along line segment in col/row */
152 Int absColumn, absRow; /* absolute value of change in col/row */
153 Int signColumn, signRow; /* sign of change along line segment col/row */
154 Int delta; /* increment alone line segment */
155 Int column, row; /* column & row of coordinate along line seg */
156 Float value, valueDelta; /* value & value change along line segment */
157
158// assert(validImage(image));
159 assert(startPoint != NULL);
160 assert(endPoint != NULL);
161
162#ifdef DEBUG0
163 fprintf(stderr,
164 "drawLineSegment: start row %6ld col %6ld\tend row %6ld col %6ld\n",
165 startPoint->row,startPoint->column,endPoint->row,endPoint->column);
166 fprintf(stderr," startVal %6ld endVal %6ld thickness %6ld\n",
167 startValue, endValue, lineThickness);
168#endif /* DEBUG0 */
169
170 changeColumn = endPoint->column - startPoint->column;
171 if (changeColumn < 0) {
172 absColumn = - changeColumn;
173 signColumn = - 1;
174 } /* end changeColumn < 0 */
175 else { /* changeColumn >= 0 */
176 absColumn = changeColumn;
177 signColumn = 1;
178 } /* end changeColumn >= 0 */
179 absColumn *= 2;
180
181 changeRow = endPoint->row - startPoint->row;
182 if (changeRow < 0) {
183 absRow = - changeRow;
184 signRow = - 1;
185 } /* end changeRow < 0 */
186 else { /* changeRow >= 0 */