@@ -63,21 +63,20 @@ namespace dip
6363 return result;
6464 }
6565
66+ std::tuple<unsigned int , unsigned int > updatePartMap (std::map<unsigned int , unsigned int > const &partMap)
67+ {
68+ return *std::max_element (partMap.begin (), partMap.end (),
69+ [](auto const &a, auto const &b)
70+ { return (std::min (1u , a.second ) * a.first ) < (std::min (1u , b.second ) * b.first ); });
71+ }
72+
6673 PreProcessor::PreProcessor (infrastructure::Context &context, PreProcessorOptions o)
6774 : logger(CREATE_LOGGER (context.getLoggerFactory())),
6875 options (std::move(o)),
6976 isEnabled(true ),
7077 partMap(splitPairToMap(splitStringToPair(options.splittingMode))),
71- parts()
78+ parts(updatePartMap(partMap) )
7279 {
73- updatePartMap ();
74- }
75-
76- void PreProcessor::updatePartMap ()
77- {
78- parts = *std::max_element (partMap.begin (), partMap.end (),
79- [](auto const &a, auto const &b)
80- { return (std::min (1u , a.second ) * a.first ) < (std::min (1u , b.second ) * b.first ); });
8180 }
8281
8382 void PreProcessor::enable (bool e)
@@ -99,14 +98,14 @@ namespace dip
9998 std::string PreProcessor::toggleSplit2 ()
10099 {
101100 ::utility::rotate (partMap.at(2 ), 2);
102- updatePartMap ();
101+ parts = updatePartMap (partMap );
103102 return std::to_string (std::get<0 >(parts)) + " /" + std::to_string (std::get<1 >(parts));
104103 }
105104
106105 std::string PreProcessor::toggleSplit4 ()
107106 {
108107 ::utility::rotate (partMap.at(4 ), 4);
109- updatePartMap ();
108+ parts = updatePartMap (partMap );
110109 return std::to_string (std::get<0 >(parts)) + " /" + std::to_string (std::get<1 >(parts));
111110 }
112111
@@ -129,28 +128,35 @@ namespace dip
129128 {
130129 auto const defaultOptions = PreProcessorOptions{};
131130 partMap = splitPairToMap (splitStringToPair (defaultOptions.splittingMode ));
131+ parts = updatePartMap (partMap);
132132 options.rotationDegree = defaultOptions.rotationDegree ;
133133 options.scalePercent = defaultOptions.scalePercent ;
134134 options.flippingMode = defaultOptions.flippingMode ;
135- updatePartMap ();
136135 return " " ;
137136 }
138137
139- input::api::InputElement PreProcessor::get (input::api::InputElement &&element) const
138+ input::api::InputElement PreProcessor::get (input::api::InputElement &&element, std::optional<dip::PreProcessorOptions> tempOptions ) const
140139 {
141140 if (!isEnabled || !element.isValid ())
142141 {
143142 return std::move (element);
144143 }
145144
145+ auto const effectiveOptions = tempOptions.value_or (this ->options );
146+ auto effectiveParts = std::tuple<unsigned int , unsigned int >(parts);
147+ if (tempOptions)
148+ {
149+ effectiveParts = updatePartMap (splitPairToMap (splitStringToPair (tempOptions->splittingMode )));
150+ }
151+
146152 auto image = element.getImage ();
147- if (std::get<1 >(parts ) != 0 )
153+ if (std::get<1 >(effectiveParts ) != 0 )
148154 {
149- image = dip::split (image, std::get<0 >(parts ), std::get<1 >(parts ));
155+ image = dip::split (image, std::get<0 >(effectiveParts ), std::get<1 >(effectiveParts ));
150156 }
151- if (options .flippingMode != 0 )
157+ if (effectiveOptions .flippingMode != 0 )
152158 {
153- switch (options .flippingMode )
159+ switch (effectiveOptions .flippingMode )
154160 {
155161 case 1 :
156162 image = dip::flipX (image);
@@ -163,13 +169,13 @@ namespace dip
163169 break ;
164170 }
165171 }
166- if (options .rotationDegree != 0 )
172+ if (effectiveOptions .rotationDegree != 0 )
167173 {
168- image = dip::rotate (image, (float )options .rotationDegree );
174+ image = dip::rotate (image, (float )effectiveOptions .rotationDegree );
169175 }
170- if (options .scalePercent != 100 )
176+ if (effectiveOptions .scalePercent != 100 )
171177 {
172- image = dip::scale (image, options .scalePercent * 0 .01f );
178+ image = dip::scale (image, effectiveOptions .scalePercent * 0 .01f );
173179 }
174180
175181 return std::move (element.replaceImage (std::move (image)));
0 commit comments