Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ShinyZone.c « Shiny « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 99d90d9276d4e42c872863fb2260d188fbd6061a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
The MIT License

Copyright (c) 2007-2010 Aidin Abedi http://code.google.com/p/shinyprofiler/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#ifdef SLIC3R_PROFILE

#include "ShinyZone.h"

#include <memory.h>

/*---------------------------------------------------------------------------*/

void ShinyZone_preUpdateChain(ShinyZone *first) {
	ShinyZone* zone = first;

	while (zone) {
		ShinyData_clearCurrent(&(zone->data));
		zone = zone->next;
	}
}


/*---------------------------------------------------------------------------*/

void ShinyZone_updateChain(ShinyZone *first, float a_damping) {
	ShinyZone* zone = first;

	do {
		ShinyData_computeAverage(&(zone->data), a_damping);
		zone = zone->next;
	} while (zone);
}


/*---------------------------------------------------------------------------*/

void ShinyZone_updateChainClean(ShinyZone *first) {
	ShinyZone* zone = first;

	do {
		ShinyData_copyAverage(&(zone->data));
		zone = zone->next;
	} while (zone);
}


/*---------------------------------------------------------------------------*/

void ShinyZone_resetChain(ShinyZone *first) {
	ShinyZone* zone = first, *temp;

	do {
		zone->_state = SHINY_ZONE_STATE_HIDDEN;
		temp = zone->next;
		zone->next = NULL;
		zone = temp;
	} while (zone);
}

/*---------------------------------------------------------------------------*/

/* A Linked-List Memory Sort
   by Philip J. Erdelsky
   pje@efgh.com
   http://www.alumni.caltech.edu/~pje/

   Modified by Aidin Abedi
*/

ShinyZone* ShinyZone_sortChain(ShinyZone **first) /* return ptr to last zone */
{
	ShinyZone *p = *first;

	unsigned base;
	unsigned long block_size;

	struct tape
	{
		ShinyZone *first, *last;
		unsigned long count;
	} tape[4];

	/* Distribute the records alternately to tape[0] and tape[1]. */

	tape[0].count = tape[1].count = 0L;
	tape[0].first = NULL;
	base = 0;
	while (p != NULL)
	{
		ShinyZone *next = p->next;
		p->next = tape[base].first;
		tape[base].first = p;
		tape[base].count++;
		p = next;
		base ^= 1;
	}

	/* If the list is empty or contains only a single record, then */
	/* tape[1].count == 0L and this part is vacuous.               */

	for (base = 0, block_size = 1L; tape[base+1].count != 0L;
		base ^= 2, block_size <<= 1)
	{
		int dest;
		struct tape *tape0, *tape1;
		tape0 = tape + base;
		tape1 = tape + base + 1;
		dest = base ^ 2;
		tape[dest].count = tape[dest+1].count = 0;
		for (; tape0->count != 0; dest ^= 1)
		{
			unsigned long n0, n1;
			struct tape *output_tape = tape + dest;
			n0 = n1 = block_size;
			while (1)
			{
				ShinyZone *chosen_record;
				struct tape *chosen_tape;
				if (n0 == 0 || tape0->count == 0)
				{
					if (n1 == 0 || tape1->count == 0)
						break;
					chosen_tape = tape1;
					n1--;
				}
				else if (n1 == 0 || tape1->count == 0)
				{
					chosen_tape = tape0;
					n0--;
				}
				else if (ShinyZone_compare(tape1->first, tape0->first) > 0)
				{
					chosen_tape = tape1;
					n1--;
				}
				else
				{
					chosen_tape = tape0;
					n0--;
				}
				chosen_tape->count--;
				chosen_record = chosen_tape->first;
				chosen_tape->first = chosen_record->next;
				if (output_tape->count == 0)
					output_tape->first = chosen_record;
				else
					output_tape->last->next = chosen_record;
				output_tape->last = chosen_record;
				output_tape->count++;
			}
		}
	}

	if (tape[base].count > 1L) {
		ShinyZone* last = tape[base].last;
		*first = tape[base].first;
		last->next = NULL;
		return last;

	} else {
		return NULL;
	}
}


/*---------------------------------------------------------------------------*/

void ShinyZone_clear(ShinyZone* self) {
	memset(self, 0, sizeof(ShinyZone));
}


/*---------------------------------------------------------------------------*/

void ShinyZone_enumerateZones(const ShinyZone* a_zone, void (*a_func)(const ShinyZone*)) {
	a_func(a_zone);

	if (a_zone->next) ShinyZone_enumerateZones(a_zone->next, a_func);
}

#endif /* SLIC3R_PROFILE */