42 Plugin ProjectionFactory::m_projPlugin;
71 if (m_projPlugin.fileName() ==
"") {
72 FileName localFile(
"Projection.plugin");
73 if (localFile.fileExists())
74 m_projPlugin.read(localFile.expanded());
76 FileName systemFile(
"$ISISROOT/lib/Projection.plugin");
77 if (systemFile.fileExists())
78 m_projPlugin.read(systemFile.expanded());
84 QString proj = mapGroup[
"ProjectionName"];
89 ptr = m_projPlugin.GetPlugin(proj);
92 QString msg =
"Unsupported projection, unable to find plugin for [" +
105 QString message =
"Unable to initialize Projection information ";
106 message +=
"from group [Mapping]";
137 bool allowDefaults) {
142 if (m_projPlugin.fileName() ==
"") {
143 FileName localFile(
"Projection.plugin");
144 if (localFile.fileExists())
145 m_projPlugin.read(localFile.expanded());
147 FileName systemFile(
"$ISISROOT/lib/Projection.plugin");
148 if (systemFile.fileExists())
149 m_projPlugin.read(systemFile.expanded());
155 QString proj = mapGroup[
"ProjectionName"];
160 ptr = m_projPlugin.GetPlugin(proj);
163 QString msg =
"Unsupported projection, unable to find plugin for [" +
172 return (
Projection *) (*plugin)(label, allowDefaults);
175 QString message =
"Unable to initialize Projection information ";
176 message +=
"from group [Mapping]";
205 int &samples,
int &lines,
210 double localRadius = proj->
LocalRadius(trueScaleLat);
216 double scale, pixelResolution;
219 pixelResolution = mapGroup[
"PixelResolution"];
220 scale = (2.0 *
Isis::PI * localRadius) / (360.0 * pixelResolution);
227 scale = mapGroup[
"Scale"];
228 pixelResolution = (2.0 *
Isis::PI * localRadius) / (360.0 * scale);
240 bool sizeFound =
false;
241 double upperLeftX =
Null, upperLeftY =
Null;
244 samples = dims[
"Samples"];
245 lines = dims[
"Lines"];
247 upperLeftX = mapGroup[
"UpperLeftCornerX"];
248 upperLeftY = mapGroup[
"UpperLeftCornerY"];
251 if (!sizeMatch) sizeFound =
false;
259 QString msg =
"Invalid ground range [MinimumLatitude,MaximumLatitude,";
260 msg +=
"MinimumLongitude,MaximumLongitude] missing or invalid";
264 double minX, maxX, minY, maxY;
265 if (!proj->
XYRange(minX, maxX, minY, maxY)) {
266 QString msg =
"Invalid ground range [MinimumLatitude,MaximumLatitude,";
267 msg +=
"MinimumLongitude,MaximumLongitude] cause invalid computation ";
268 msg +=
"of image size";
278 if (fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
279 if (pixelResolution - fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
280 double sampleOffset = floor(minX / pixelResolution);
281 minX = sampleOffset * pixelResolution;
286 if (maxX < minX + pixelResolution) {
287 maxX = minX + pixelResolution;
290 if (fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
291 if (pixelResolution - fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
292 double lineOffset = -1.0 * ceil(maxY / pixelResolution);
293 maxY = -1.0 * lineOffset * pixelResolution;
298 if (minY > maxY - pixelResolution) {
299 minY = maxY - pixelResolution;
303 samples = (int)((maxX - minX) / pixelResolution + 0.5);
304 lines = (int)((maxY - minY) / pixelResolution + 0.5);
329 (QString) mapGroup[
"PixelResolution"],
330 "meters/pixel"), Isis::Pvl::Replace);
333 (QString) mapGroup[
"Scale"],
334 "pixels/degree"), Isis::Pvl::Replace);
337 (QString) mapGroup[
"UpperLeftCornerX"],
338 "meters"), Isis::Pvl::Replace);
341 (QString) mapGroup[
"UpperLeftCornerY"],
342 "meters"), Isis::Pvl::Replace);
345 (QString) mapGroup[
"EquatorialRadius"],
346 "meters"), Isis::Pvl::Replace);
349 (QString) mapGroup[
"PolarRadius"],
350 "meters"), Isis::Pvl::Replace);
360 QString msg =
"Unable to create projection";
363 finalError.
append(errors);
395 int &samples,
int &lines,
bool sizeMatch) {
407 double scale, pixelResolution;
410 pixelResolution = mapGroup[
"PixelResolution"];
411 scale = (2.0 *
Isis::PI * localRadius) / (360.0 * pixelResolution);
417 scale = mapGroup[
"Scale"];
418 pixelResolution = (2.0 *
Isis::PI * localRadius) / (360.0 * scale);
434 bool sizeFound =
false;
435 double upperLeftX =
Null, upperLeftY =
Null;
438 samples = dims[
"Samples"];
439 lines = dims[
"Lines"];
441 upperLeftX = mapGroup[
"UpperLeftCornerX"];
442 upperLeftY = mapGroup[
"UpperLeftCornerY"];
456 QString msg =
"Invalid ring range [MinimumRingRadius,MaximumRingRadius,";
457 msg +=
"MinimumRingLongitude,MaximumRingLongitude] missing or invalid";
461 double minX, maxX, minY, maxY;
462 if (!proj->
XYRange(minX, maxX, minY, maxY)) {
463 QString msg =
"Invalid ring range [MinimumRingRadius,MaximumRingRadius,";
464 msg +=
"MinimumRingLongitude,MaximumRingLongitude] cause invalid computation ";
465 msg +=
"of image size";
475 if (fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
476 if (pixelResolution - fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
477 double sampleOffset = floor(minX / pixelResolution);
478 minX = sampleOffset * pixelResolution;
483 if (maxX < minX + pixelResolution) {
484 maxX = minX + pixelResolution;
486 if (fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
487 if (pixelResolution - fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
488 double lineOffset = -1.0 * ceil(maxY / pixelResolution);
489 maxY = -1.0 * lineOffset * pixelResolution;
494 if (minY > maxY - pixelResolution) {
495 minY = maxY - pixelResolution;
499 samples = (int)((maxX - minX) / pixelResolution + 0.5);
500 lines = (int)((maxY - minY) / pixelResolution + 0.5);
517 mapGroup.AddKeyword(
Isis::PvlKeyword(
"SampleProjectionOffset", sampleOffset),
525 (QString) mapGroup[
"PixelResolution"],
526 "meters/pixel"), Isis::Pvl::Replace);
529 (QString) mapGroup[
"Scale"],
530 "pixels/degree"), Isis::Pvl::Replace);
533 (QString) mapGroup[
"UpperLeftCornerX"],
534 "meters"), Isis::Pvl::Replace);
537 (QString) mapGroup[
"UpperLeftCornerY"],
538 "meters"), Isis::Pvl::Replace);
548 QString msg =
"Unable to create projection";
551 finalError.
append(errors);
584 int &samples,
int &lines,
589 double localRadius = proj->
LocalRadius(trueScaleLat);
594 double scale, pixelResolution;
597 pixelResolution = mapGroup[
"PixelResolution"];
598 scale = (2.0 *
Isis::PI * localRadius) / (360.0 * pixelResolution);
603 scale = mapGroup[
"Scale"];
604 pixelResolution = (2.0 *
Isis::PI * localRadius) / (360.0 * scale);
615 double minX = DBL_MAX;
616 double maxX = -DBL_MAX;
617 double minY = DBL_MAX;
618 double maxY = -DBL_MAX;
621 int eband = cam.
Bands();
623 for(
int band = 1; band <= eband; band++) {
627 for(
int line = 0; line <= cam.
Lines(); line++) {
631 for(samp = 0; samp <= cam.
Samples(); samp++) {
632 if (cam.
SetImage((
double)samp + 0.5, (
double)line + 0.5)) {
641 if ((line != 0) && (line != cam.
Lines()))
break;
648 for(samp = cam.
Samples(); samp >= 0; samp--) {
649 if (cam.
SetImage((
double)samp + 0.5, (
double)line + 0.5)) {
667 if (cam.
Sample() >= 0.5 && cam.
Line() >= 0.5 &&
682 if (cam.
Sample() >= 0.5 && cam.
Line() >= 0.5 &&
700 for(
double lat = p_minlat; lat <= p_maxlat; lat += (p_maxlat - p_minlat) / 10.0) {
701 if (SetUniversalGround(lat, 0.0)) {
702 if (Sample() >= 0.5 && Line() >= 0.5 &&
703 Sample() <= p_samples + 0.5 && Line() <= p_lines + 0.5) {
714 for(
double lat = p_minlat; lat <= p_maxlat; lat += (p_maxlat - p_minlat) / 10.0) {
715 if (SetUniversalGround(lat, 180.0)) {
716 if (Sample() >= 0.5 && Line() >= 0.5 &&
717 Sample() <= p_samples + 0.5 && Line() <= p_lines + 0.5) {
718 p_minlon180 = -180.0;
733 if (fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
734 if (pixelResolution - fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
735 double sampleOffset = floor(minX / pixelResolution);
736 minX = sampleOffset * pixelResolution;
741 if (maxX < minX + pixelResolution) {
742 maxX = minX + pixelResolution;
744 if (fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
745 if (pixelResolution - fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
746 double lineOffset = -1.0 * ceil(maxY / pixelResolution);
747 maxY = -1.0 * lineOffset * pixelResolution;
752 if (minY > maxY - pixelResolution) {
753 minY = maxY - pixelResolution;
757 samples = (int)((maxX - minX) / pixelResolution + 0.5);
758 lines = (int)((maxY - minY) / pixelResolution + 0.5);
761 double upperLeftX = minX;
765 double upperLeftY = maxY;
771 (QString) mapGroup[
"PixelResolution"],
772 "meters/pixel"), Isis::Pvl::Replace);
775 (QString) mapGroup[
"Scale"],
776 "pixels/degree"), Isis::Pvl::Replace);
779 (QString) mapGroup[
"UpperLeftCornerX"],
780 "meters"), Isis::Pvl::Replace);
783 (QString) mapGroup[
"UpperLeftCornerY"],
784 "meters"), Isis::Pvl::Replace);
787 (QString) mapGroup[
"EquatorialRadius"],
788 "meters"), Isis::Pvl::Replace);
791 (QString) mapGroup[
"PolarRadius"],
792 "meters"), Isis::Pvl::Replace);
802 QString msg =
"Unable to create projection";
835 int &samples,
int &lines,
Camera &cam) {
845 double scale, pixelResolution;
848 pixelResolution = mapGroup[
"PixelResolution"];
849 scale = (2.0 *
Isis::PI * localRadius) / (360.0 * pixelResolution);
856 scale = mapGroup[
"Scale"];
857 pixelResolution = (2.0 *
Isis::PI * localRadius) / (360.0 * scale);
861 "meters/pixel"), Isis::Pvl::Replace);
867 double minX = DBL_MAX;
868 double maxX = -DBL_MAX;
869 double minY = DBL_MAX;
870 double maxY = -DBL_MAX;
873 int eband = cam.
Bands();
875 for(
int band = 1; band <= eband; band++) {
879 for(
int line = 0; line <= cam.
Lines(); line++) {
883 for(samp = 0; samp <= cam.
Samples(); samp++) {
884 if (cam.
SetImage((
double)samp + 0.5, (
double)line + 0.5)) {
893 if ((line != 0) && (line != cam.
Lines()))
break;
900 for(samp = cam.
Samples(); samp >= 0; samp--) {
901 if (cam.
SetImage((
double)samp + 0.5, (
double)line + 0.5)) {
921 for(
double rad = p_minRadius; rad <= p_maxRadius; rad += (p_maxRadius - p_minRadius) / 10.0) {
922 if (SetUniversalGround(rad, 0.0)) {
923 if (Sample() >= 0.5 && Line() >= 0.5 &&
924 Sample() <= p_samples + 0.5 && Line() <= p_lines + 0.5) {
935 for(
double rad = p_minrad; rad <= p_maxrad; rad += (p_maxrad - p_minrad) / 10.0) {
936 if (SetUniversalGround(rad, 180.0)) {
937 if (Sample() >= 0.5 && Line() >= 0.5 &&
938 Sample() <= p_samples + 0.5 && Line() <= p_lines + 0.5) {
954 if (fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
955 if (pixelResolution - fabs(fmod(minX, pixelResolution)) > 1.0e-6) {
956 double sampleOffset = floor(minX / pixelResolution);
957 minX = sampleOffset * pixelResolution;
962 if (maxX < minX + pixelResolution) {
963 maxX = minX + pixelResolution;
966 if (fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
967 if (pixelResolution - fabs(fmod(maxY, pixelResolution)) > 1.0e-6) {
968 double lineOffset = -1.0 * ceil(maxY / pixelResolution);
969 maxY = -1.0 * lineOffset * pixelResolution;
974 if (minY > maxY - pixelResolution) {
975 minY = maxY - pixelResolution;
979 samples = (int)((maxX - minX) / pixelResolution + 0.5);
980 lines = (int)((maxY - minY) / pixelResolution + 0.5);
983 double upperLeftX = minX;
987 double upperLeftY = maxY;
993 (QString) mapGroup[
"PixelResolution"],
994 "meters/pixel"), Isis::Pvl::Replace);
997 (QString) mapGroup[
"Scale"],
998 "pixels/degree"), Isis::Pvl::Replace);
1001 (QString) mapGroup[
"UpperLeftCornerX"],
1002 "meters"), Isis::Pvl::Replace);
1005 (QString) mapGroup[
"UpperLeftCornerY"],
1006 "meters"), Isis::Pvl::Replace);
1016 QString msg =
"Unable to create projection";
1017 if (label.
fileName() !=
"") msg +=
" from file [" + label.
fileName() +
"]";
1032 return CreateFromCube(*cube.
label());
1044 return RingsCreateFromCube(*cube.
label());
1062 double pixelResolution = mapGroup[
"PixelResolution"];
1065 double upperLeftX = mapGroup[
"UpperLeftCornerX"];
1066 double upperLeftY = mapGroup[
"UpperLeftCornerY"];
1079 QString msg =
"Unable to initialize cube projection";
1080 if (label.
fileName() !=
"") msg +=
" from file [" + label.
fileName() +
"]";
1101 double pixelResolution = mapGroup[
"PixelResolution"];
1104 double upperLeftX = mapGroup[
"UpperLeftCornerX"];
1105 double upperLeftY = mapGroup[
"UpperLeftCornerY"];
1118 QString msg =
"Unable to initialize cube projection";
1119 if (label.
fileName() !=
"") msg +=
" from file [" + label.
fileName() +
"]";