AnyType::operator PointType() { if(type == TypePoint) { return PointType(*(value.pt)); } else if(type == TypeString) { std::stringstream pointStream(*(value.str)); int x, y; char comma; pointStream >> x >> comma >> y; if (pointStream.fail() || comma != ',') throw InvalidConversionException(type, TypePoint); return PointType(ui::Point(x, y)); }
AnyType TPTScriptInterface::eval(std::deque<std::string> * words) { if(words->size() < 1) return AnyType(TypeNull, NULL); std::string word = words->front(); words->pop_front(); char * rawWord = (char *)word.c_str(); ValueType wordType = testType(word); switch(wordType) { case TypeFunction: if(word == "set") return tptS_set(words); else if(word == "create") return tptS_create(words); else if(word == "delete" || word == "kill") return tptS_delete(words); else if(word == "load") return tptS_load(words); else if(word == "reset") return tptS_reset(words); else if(word == "bubble") return tptS_bubble(words); break; case TypeNumber: return NumberType(atoi(rawWord)); case TypePoint: { int pointX, pointY; sscanf(rawWord, "%d,%d", &pointX, &pointY); return PointType(pointX, pointY); } case TypeString: return StringType(word); } }
bool ModelIO::readCSV(QString & fileURL, pcl::PointCloud<PointType>::Ptr cloud) { QFile file(fileURL); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); QRegExp separator(QStringLiteral(",")); float x,y,z; while (!in.atEnd()) { QString line = in.readLine(); QStringList list = line.split(separator); if (!(parseToFloat(list[0], x) && parseToFloat(list[1], y) && parseToFloat(list[2], z))) { addStatus(QObject::tr("Invalid number in file: ") + line); return false; } cloud->push_back(PointType(x, y, z)); } cloud->width = cloud->size(); cloud->height = 1; cloud->is_dense = true; return true; } else { addStatus(QObject::tr("Can not open file.")); return false; } }
AnyType TPTScriptInterface::eval(std::deque<String> * words) { if(words->size() < 1) return AnyType(TypeNull, ValueValue()); String word = words->front(); words->pop_front(); ValueType wordType = testType(word); switch(wordType) { case TypeFunction: if(word == "set") return tptS_set(words); else if(word == "create") return tptS_create(words); else if(word == "delete" || word == "kill") return tptS_delete(words); else if(word == "load") return tptS_load(words); else if(word == "reset") return tptS_reset(words); else if(word == "bubble") return tptS_bubble(words); else if(word == "quit") return tptS_quit(words); break; case TypeNumber: return NumberType(parseNumber(word)); case TypeFloat: return FloatType(atof(word.ToUtf8().c_str())); case TypePoint: { int x, y; if(String::Split comma = word.SplitNumber(x)) if(comma.After().BeginsWith(",")) if(comma.After().Substr(1).SplitNumber(y)) return PointType(x, y); return PointType(0, 0); } case TypeString: return StringType(word); default: break; } return StringType(word); }
void loadPointSet(const std::string& filename, PointSet& ps) { std::fstream fin(filename.c_str(), std::ios_base::in); if (!fin) { std::cout << "cannot open the file!" << std::endl; return; } std::vector<Scalar> m_values; Scalar tmp = 0; size_t i = 0, j = 0; while (fin >> tmp) { m_values.push_back(tmp); } size_t points_size = m_values.size() / Dim; if (points_size * Dim != m_values.size()) { std::cout << "File is broken! Or Dimension is incorrect!" << std::endl; return; } for (size_t i = 0; i < points_size; ++ i) { if (Dim == 3) ps.push_back(PointType(m_values[3*i], m_values[3*i+1], m_values[3*i+2])); else ps.push_back(PointType(m_values[2*i], m_values[2*i+1])); } fin.close(); }
AnyType::operator PointType() { if(type == TypePoint) { return PointType(*((ui::Point*)value)); } else if(type == TypeString) { ui::Point thisPoint = *((ui::Point*)value); std::stringstream pointStream; pointStream << thisPoint.X << "," << thisPoint.Y; return StringType(pointStream.str()); } else throw InvalidConversionException(type, TypePoint); }
void polyLine::getPoint(FILE* file) { int shapeType; readRecord(&shapeType, file); PolyLineType *ret = new PolyLineType; readRecord((char*)ret, file, 40); int a; for (int i = 0; i < ret->numParts; i++) { readRecord(&a, file); ret->Parts.push_back(a); } double cord[2]; for (int i = 0; i < ret->numPoints; i++) { readRecord(cord, file, 2); ret->Points.push_back(PointType(cord[0], cord[1])); } objSet->push_back(ret); }
void FilledBoundaryAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("FilledBoundaryAttributes"); if(searchNode == 0) return; DataNode *node; if((node = searchNode->GetNode("colorType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 3) SetColorType(ColoringMethod(ival)); } else if(node->GetNodeType() == STRING_NODE) { ColoringMethod value; if(ColoringMethod_FromString(node->AsString(), value)) SetColorType(value); } } if((node = searchNode->GetNode("colorTableName")) != 0) SetColorTableName(node->AsString()); if((node = searchNode->GetNode("invertColorTable")) != 0) SetInvertColorTable(node->AsBool()); if((node = searchNode->GetNode("filledFlag")) != 0) SetFilledFlag(node->AsBool()); if((node = searchNode->GetNode("legendFlag")) != 0) SetLegendFlag(node->AsBool()); if((node = searchNode->GetNode("lineStyle")) != 0) SetLineStyle(node->AsInt()); if((node = searchNode->GetNode("lineWidth")) != 0) SetLineWidth(node->AsInt()); if((node = searchNode->GetNode("singleColor")) != 0) singleColor.SetFromNode(node); if((node = searchNode->GetNode("multiColor")) != 0) multiColor.SetFromNode(node); if((node = searchNode->GetNode("boundaryNames")) != 0) SetBoundaryNames(node->AsStringVector()); if((node = searchNode->GetNode("boundaryType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 4) SetBoundaryType(Boundary_Type(ival)); } else if(node->GetNodeType() == STRING_NODE) { Boundary_Type value; if(Boundary_Type_FromString(node->AsString(), value)) SetBoundaryType(value); } } if((node = searchNode->GetNode("opacity")) != 0) SetOpacity(node->AsDouble()); if((node = searchNode->GetNode("wireframe")) != 0) SetWireframe(node->AsBool()); if((node = searchNode->GetNode("drawInternal")) != 0) SetDrawInternal(node->AsBool()); if((node = searchNode->GetNode("smoothingLevel")) != 0) SetSmoothingLevel(node->AsInt()); if((node = searchNode->GetNode("cleanZonesOnly")) != 0) SetCleanZonesOnly(node->AsBool()); if((node = searchNode->GetNode("mixedColor")) != 0) mixedColor.SetFromNode(node); if((node = searchNode->GetNode("pointSize")) != 0) SetPointSize(node->AsDouble()); if((node = searchNode->GetNode("pointType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 8) SetPointType(PointType(ival)); } else if(node->GetNodeType() == STRING_NODE) { PointType value; if(PointType_FromString(node->AsString(), value)) SetPointType(value); } } if((node = searchNode->GetNode("pointSizeVarEnabled")) != 0) SetPointSizeVarEnabled(node->AsBool()); if((node = searchNode->GetNode("pointSizeVar")) != 0) SetPointSizeVar(node->AsString()); if((node = searchNode->GetNode("pointSizePixels")) != 0) SetPointSizePixels(node->AsInt()); // We are no longer using MultiColor as the source for the "mixed" // color (in clean zones only), but someone may have saved their // settings with the "mixed" color in the list. Remove it if it's // in there. // // NOTE: This code can be removed in a few months, as soon as // 1.3 is at least a few versions old, since it represents a little // bit of a hack. bool done = false; while (!done) { done = true; size_t index; for (index=0; index<boundaryNames.size(); index++) { if (boundaryNames[index] == "mixed") { done = false; break; } } if (!done) { multiColor.RemoveColors((int)index); for (size_t i=index+1; i<boundaryNames.size(); i++) boundaryNames[i-1] = boundaryNames[i]; boundaryNames.resize(boundaryNames.size() - 1); } } }
fwData::Image::sptr Resampler::resample(const fwData::Image::csptr& _img, const ::fwData::TransformationMatrix3D::csptr& _trf, const ::fwData::Image::SpacingType& _outputSpacing) { using PointType = ::itk::Point<double, 3>; using VectorContainerType = ::itk::VectorContainer<int, PointType>; using BoundingBoxType = ::itk::BoundingBox<int, 3, double, VectorContainerType>; const auto& inputSize = _img->getSize(); const auto& inputOrigin = _img->getOrigin(); const auto& inputSpacing = _img->getSpacing(); SLM_ASSERT("Image dimension must be 3.", inputOrigin.size() == 3 && inputSpacing.size() == 3 && inputSize.size() == 3); typename BoundingBoxType::Pointer inputBB = BoundingBoxType::New(); const PointType min(inputOrigin.data()); PointType max; for(std::uint8_t i = 0; i < 3; ++i) { max[i] = inputOrigin[i] + static_cast<double>(inputSize[i]) * inputSpacing[i]; } inputBB->SetMinimum(min); inputBB->SetMaximum(max); const auto inputCorners = inputBB->GetCorners(); const ::itk::Matrix<double, 4, 4> matrix(::fwItkIO::helper::Transform::convertToITK(_trf).GetInverse()); // Apply transform matrix to all bounding box corners. typename VectorContainerType::Pointer outputCorners = VectorContainerType::New(); outputCorners->Reserve(inputCorners->Size()); std::transform(inputCorners->begin(), inputCorners->end(), outputCorners->begin(), [&matrix](const PointType& _in) { // Convert input to homogeneous coordinates. const ::itk::Point<double, 4> input(std::array<double, 4>({{_in[0], _in[1], _in[2], 1.}}).data()); const auto p = matrix * input; return PointType(p.GetDataPointer()); }); // Compute the transformed axis aligned bounding box. typename BoundingBoxType::Pointer outputBB = BoundingBoxType::New(); outputBB->SetPoints(outputCorners); outputBB->ComputeBoundingBox(); // Compute output size and origin. ::fwData::Image::sptr output = ::fwData::Image::New(); ::fwData::Image::OriginType outputOrigin(3); ::fwData::Image::SizeType outputSize(3); for(std::uint8_t i = 0; i < 3; ++i) { outputOrigin[i] = outputBB->GetMinimum()[i]; outputSize[i] = size_t((outputBB->GetMaximum()[i] - outputOrigin[i]) / _outputSpacing[i]); } output->setSize(outputSize); output->setSpacing(_outputSpacing); output->setOrigin(outputOrigin); resample(_img, output, _trf, output); return output; }
template< typename T > typename Rectangle2< T >::PointType Rectangle2< T >::getBottomLeft() const { return PointType( x0, y1 ); }
typename Rectangle2< T >::PointType Rectangle2< T >::getTopRight() const { return PointType( x1, y0 ); }
typename Rectangle2< T >::PointType Rectangle2< T >::getOrigin() const { return PointType( x0, y0 ); }
typename Rectangle2< T >::PointType Rectangle2< T >::getBottomRight() const { return PointType( x1, y1 ); }
typename Rectangle2< T >::PointType Rectangle2< T >::getTopLeft() const { return PointType( x0, y0 ); }
SubsetAttributes::PointType SubsetAttributes::GetPointType() const { return PointType(pointType); }
FilledBoundaryAttributes::PointType FilledBoundaryAttributes::GetPointType() const { return PointType(pointType); }
// The code is based on the algorithm described here: // http://en.wikipedia.org/wiki/K-d_tree#Nearest_neighbour_search PointType search(Node* currentRoot, PointType& queryPoint) { // Return dummy point if ( currentRoot == NULL ) return PointType(dimensions, CGAL::ORIGIN); int level = currentRoot->level; Node* branchToFollow; Node* otherBranch; // Choose which path to follow, based on current level'th coordinate if ( queryPoint.cartesian(level) < currentRoot->point.cartesian(level) ) { branchToFollow = currentRoot->less; otherBranch = currentRoot->greater; } else { branchToFollow = currentRoot->greater; otherBranch = currentRoot->less; } // Leaf node reached. A leaf node is a node that has no children in the desired direction if ( branchToFollow == NULL ) { double currentDistance = simpleDistance(currentRoot->point, queryPoint); // First leaf encountered if ( currentBestDistance < 0 ) { currentBest = currentRoot->point; currentBestDistance = currentDistance; } else if ( currentDistance < currentBestDistance ) { currentBest = currentRoot->point; currentBestDistance = currentDistance; } } else { search(branchToFollow, queryPoint); // Compare currentBest with the currentRoot while unwinding the recursion double currentDistance = simpleDistance(currentRoot->point, queryPoint); if ( currentDistance < currentBestDistance ) { currentBest = currentRoot->point; currentBestDistance = currentDistance; } } // Check if there can be any candidate points on the other side of the splitting plane // that can be closer to the queryPoint than the currentBest. In effect check // whether a hypersphere with center the queryPoint and radius equal to the distance // to the currentBest, crosses over the splitting plane. // NOTE: currentBestDistance is a squared distance, and so the distance from the // splitting plane is squared as well before the comparison. double distanceFromSplit = queryPoint.cartesian(level) - currentRoot->point.cartesian(level); if ( (distanceFromSplit * distanceFromSplit) < currentBestDistance ) search(otherBranch, queryPoint); return currentBest; }
typename Rectangle2< T >::PointType Rectangle2< T >::getSize() const { return PointType( getWidth(), getHeight() ); }
void SubsetAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("SubsetAttributes"); if(searchNode == 0) return; DataNode *node; if((node = searchNode->GetNode("colorType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 3) SetColorType(ColoringMethod(ival)); } else if(node->GetNodeType() == STRING_NODE) { ColoringMethod value; if(ColoringMethod_FromString(node->AsString(), value)) SetColorType(value); } } if((node = searchNode->GetNode("colorTableName")) != 0) SetColorTableName(node->AsString()); if((node = searchNode->GetNode("invertColorTable")) != 0) SetInvertColorTable(node->AsBool()); if((node = searchNode->GetNode("filledFlag")) != 0) SetFilledFlag(node->AsBool()); if((node = searchNode->GetNode("legendFlag")) != 0) SetLegendFlag(node->AsBool()); if((node = searchNode->GetNode("lineStyle")) != 0) SetLineStyle(node->AsInt()); if((node = searchNode->GetNode("lineWidth")) != 0) SetLineWidth(node->AsInt()); if((node = searchNode->GetNode("singleColor")) != 0) singleColor.SetFromNode(node); if((node = searchNode->GetNode("multiColor")) != 0) multiColor.SetFromNode(node); if((node = searchNode->GetNode("subsetNames")) != 0) SetSubsetNames(node->AsStringVector()); if((node = searchNode->GetNode("subsetType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 6) SetSubsetType(Subset_Type(ival)); } else if(node->GetNodeType() == STRING_NODE) { Subset_Type value; if(Subset_Type_FromString(node->AsString(), value)) SetSubsetType(value); } } if((node = searchNode->GetNode("opacity")) != 0) SetOpacity(node->AsDouble()); if((node = searchNode->GetNode("wireframe")) != 0) SetWireframe(node->AsBool()); if((node = searchNode->GetNode("drawInternal")) != 0) SetDrawInternal(node->AsBool()); if((node = searchNode->GetNode("smoothingLevel")) != 0) SetSmoothingLevel(node->AsInt()); if((node = searchNode->GetNode("pointSize")) != 0) SetPointSize(node->AsDouble()); if((node = searchNode->GetNode("pointType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 8) SetPointType(PointType(ival)); } else if(node->GetNodeType() == STRING_NODE) { PointType value; if(PointType_FromString(node->AsString(), value)) SetPointType(value); } } if((node = searchNode->GetNode("pointSizeVarEnabled")) != 0) SetPointSizeVarEnabled(node->AsBool()); if((node = searchNode->GetNode("pointSizeVar")) != 0) SetPointSizeVar(node->AsString()); if((node = searchNode->GetNode("pointSizePixels")) != 0) SetPointSizePixels(node->AsInt()); }
void expandBy(Scalar delta) { min -= PointType(delta); max += PointType(delta); }