void oms::SingleImageChain::setViewCut(const ossimDrect& rect, bool imageSpaceFlag)
{
   if(!imageSpaceFlag)
   {
      
      const ossimProjection* proj = getViewProjection();
      
      if(proj)
      {
         std::vector<ossimGpt> pointList(4);
         proj->lineSampleToWorld(rect.ul(), pointList[0]);
         proj->lineSampleToWorld(rect.ur(), pointList[1]);
         proj->lineSampleToWorld(rect.lr(), pointList[2]);
         proj->lineSampleToWorld(rect.ll(), pointList[3]);
         setViewCut(pointList);
      }
   }
   else
   {
      std::vector<ossimDpt> pointList(4);
      pointList[0] = rect.ul();
      pointList[1] = rect.ur();
      pointList[2] = rect.lr();
      pointList[3] = rect.ll();
      theViewCutter->setEnableFlag(false);
      theViewImageCutter->setEnableFlag(true);
      theViewImageCutter->setPolygon(pointList);
      theViewImageCutter->initialize();
      ossimPropertyEvent evt(theViewImageCutter);
      theViewImageCutter->propagateEventToOutputs(evt);
   }
}
void FlagComponent::remove( int index ) {
    // check if flag of required index exists
    if ( index > pointList().size() - 1 ) {
        return;
    }

    pointList().removeAt( index );
    m_Epoch.removeAt( index );
    m_FlagImages.removeAt( index );
    m_Labels.removeAt( index );
    m_LabelColors.removeAt( index );

    // request SkyMap update
    SkyMap::Instance()->forceUpdate();
}
void FlagComponent::saveToFile() {
    /*
    TODO: This is a really bad way of storing things. Adding one flag shouldn't
    involve writing a new file/table every time. Needs fixing.
    */
    KStarsData::Instance()->userdb()->EraseAllFlags();

    for ( int i=0; i < size(); ++i ) {
        KStarsData::Instance()->userdb()->AddFlag(QString::number( pointList().at( i )->ra0().Degrees() ),
                                                  QString::number( pointList().at( i )->dec0().Degrees() ),
                                                  epoch ( i ),
                                                  imageName( i ).replace( ' ', '_' ),
                                                  label( i ),
                                                  labelColor( i ).name());
    }
}
void FlagComponent::updateFlag( int index, SkyPoint *flagPoint, QString epoch, QString image, QString label, QColor labelColor ) {
    if ( index > pointList().size() -1 ) {
        return;
    }
    delete pointList().at( index );
    pointList().replace( index, flagPoint);

    m_Epoch.replace( index, epoch );

    for(int i = 0; i<m_Names.size(); i++ ) {
        if( image == m_Names.at( i ) )
            m_FlagImages.replace( index, i );
    }

    m_Labels.replace( index, label );
    m_LabelColors.replace( index, labelColor );
}
void HorizonComponent::update( KSNumbers * )
{
    if ( ! selected() )
        return;
    KStarsData *data = KStarsData::Instance();
    foreach ( SkyPoint *p, pointList() ) {
        p->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
    }
void oms::SingleImageChain::setViewCut(const ossimGrect& grect)
{
   std::vector<ossimGpt> pointList(4);
   pointList[0] = grect.ul();
   pointList[1] = grect.ur();
   pointList[2] = grect.lr();
   pointList[3] = grect.ll();
   setViewCut(pointList);
};
void oms::SingleImageChain::setImageCut(const ossimDrect& rect)
{
   std::vector<ossimDpt> pointList(4);
   pointList[0] = rect.ul();
   pointList[1] = rect.ur();
   pointList[2] = rect.lr();
   pointList[3] = rect.ll();
   
   setImageCut(pointList);
}
void FlagComponent::add( SkyPoint* flagPoint, QString epoch, QString image, QString label, QColor labelColor ) {
    pointList().append( flagPoint );
    m_Epoch.append( epoch );

    for(int i = 0; i<m_Names.size(); i++ ) {
        if( image == m_Names.at( i ) )
            m_FlagImages.append( i );
    }

    m_Labels.append( label );
    m_LabelColors.append( labelColor );
}
void AMBeamConfigurationWizard::addPoint(QPointF position)
{

	int index = relativeId() - numberOfPoints()/2;
	QPointF* newPoint;

	if(topLeft_)
	{
		newPoint = (*pointList())[2*(index)];
		connect(view(), SIGNAL(mouseMoved(QPointF)), this, SLOT(addPoint(QPointF)));
		topLeft_ = !topLeft_;
	}
	else
	{
		newPoint = (*pointList())[2*(index) + 1];
	}

	*newPoint = mapPointToVideo(position);

	emit showShape(index);


}
void SVGPolygonElement::toPathData(Path& path) const
{
    ASSERT(path.isEmpty());

    SVGPointList& points = pointList();
    if (points.isEmpty())
        return;

    path.moveTo(points.first());

    unsigned size = points.size();
    for (unsigned i = 1; i < size; ++i)
        path.addLineTo(points.at(i));

    path.closeSubpath();
}
HorizonComponent::HorizonComponent(SkyComposite *parent )
        : PointListComponent( parent )
{
    KStarsData *data = KStarsData::Instance();
    emitProgressText( i18n("Creating horizon" ) );

    //Define Horizon
    for ( unsigned int i=0; i<NCIRCLE; ++i ) {
        SkyPoint *o = new SkyPoint();
        o->setAz( i*360./NCIRCLE );
        o->setAlt( 0.0 );

        o->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
        pointList().append( o );
    }
}
void FlagComponent::loadFromFile() {
    bool imageFound = false;

    QList<QStringList> flagList=KStarsData::Instance()->userdb()->ReturnAllFlags();
    for (int i=0; i<flagList.size(); ++i){
        QStringList flagEntry = flagList.at(i);

        // Read coordinates
        dms r( flagEntry.at( 0 ) );
        dms d( flagEntry.at( 1 ) );
        SkyPoint* flagPoint = new SkyPoint( r, d );
        pointList().append( flagPoint );

        // Read epoch
        m_Epoch.append( flagEntry.at( 2 ) );

        // Read image name
        QString str = flagEntry.at( 3 );
        str = str.replace( '_', ' ');
        for(int i = 0; i < m_Names.size(); ++i ) {
            if ( str == m_Names.at( i ) ) {
                m_FlagImages.append( i );
                imageFound = true;
            }
        }

        // If the image sprecified in db does not exist,
        // use the default one
        if ( ! imageFound )
            m_FlagImages.append( 0 );

        imageFound = false;

        // If there is no label, use an empty string, red color and continue.
        m_Labels.append(flagEntry.at(4));

        // color label

        QRegExp rxLabelColor( "^#[a-fA-F0-9]{6}$" );
        if ( rxLabelColor.exactMatch( flagEntry.at(5) ) ) {
            m_LabelColors.append( QColor( flagEntry.at(5) ) );
        } else {
            m_LabelColors.append( QColor( "red" ) );
        }

    }
}
Exemple #13
0
void CSMTools::PathgridCheckStage::perform (int stage, CSMDoc::Messages& messages)
{
    const CSMWorld::Record<CSMWorld::Pathgrid>& record = mPathgrids.getRecord (stage);

    if (record.isDeleted())
        return;

    const CSMWorld::Pathgrid& pathgrid = record.get();

    CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Pathgrid, pathgrid.mId);

    // check the number of pathgrid points
    if (pathgrid.mData.mS2 > static_cast<int>(pathgrid.mPoints.size()))
        messages.push_back (std::make_pair (id, pathgrid.mId + " has less points than expected"));
    else if (pathgrid.mData.mS2 > static_cast<int>(pathgrid.mPoints.size()))
        messages.push_back (std::make_pair (id, pathgrid.mId + " has more points than expected"));

    std::vector<Point> pointList(pathgrid.mPoints.size());
    std::vector<int> duplList;

    for (unsigned int i = 0; i < pathgrid.mEdges.size(); ++i)
    {
        if (pathgrid.mEdges[i].mV0 < static_cast<int>(pathgrid.mPoints.size()) && pathgrid.mEdges[i].mV0 >= 0)
        {
            pointList[pathgrid.mEdges[i].mV0].mConnectionNum++;
            // first check for duplicate edges
            unsigned int j = 0;
            for (; j < pointList[pathgrid.mEdges[i].mV0].mOtherIndex.size(); ++j)
            {
                if (pointList[pathgrid.mEdges[i].mV0].mOtherIndex[j] == pathgrid.mEdges[i].mV1)
                {
                    std::ostringstream ss;
                    ss << "has a duplicate edge between points" << pathgrid.mEdges[i].mV0
                        << " and " << pathgrid.mEdges[i].mV1;
                    messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
                    break;
                }
            }

            // only add if not a duplicate
            if (j == pointList[pathgrid.mEdges[i].mV0].mOtherIndex.size())
                pointList[pathgrid.mEdges[i].mV0].mOtherIndex.push_back(pathgrid.mEdges[i].mV1);
        }
        else
        {
            std::ostringstream ss;
            ss << " has an edge connecting a non-existent point " << pathgrid.mEdges[i].mV0;
            messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
        }
    }

    for (unsigned int i = 0; i < pathgrid.mPoints.size(); ++i)
    {
        // check the connection number for each point matches the edge connections
        if (pathgrid.mPoints[i].mConnectionNum > pointList[i].mConnectionNum)
        {
            std::ostringstream ss;
            ss << " has has less edges than expected for point " << i;
            messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
        }
        else if (pathgrid.mPoints[i].mConnectionNum < pointList[i].mConnectionNum)
        {
            std::ostringstream ss;
            ss << " has has more edges than expected for point " << i;
            messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
        }

        // check that edges are bidirectional
        bool foundReverse = false;
        for (unsigned int j = 0; j < pointList[i].mOtherIndex.size(); ++j)
        {
            for (unsigned int k = 0; k < pointList[pointList[i].mOtherIndex[j]].mOtherIndex.size(); ++k)
            {
                if (pointList[pointList[i].mOtherIndex[j]].mOtherIndex[k] == static_cast<int>(i))
                {
                    foundReverse = true;
                    break;
                }
            }

            if (!foundReverse)
            {
                std::ostringstream ss;
                ss << " has a missing edge between points " << i << " and " << pointList[i].mOtherIndex[j];
                messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
            }
        }

        // check duplicate points
        // FIXME: how to do this efficiently?
        for (unsigned int j = 0; j < pathgrid.mPoints.size(); ++j)
        {
            if (j == i)
                continue;

            if (pathgrid.mPoints[i].mX == pathgrid.mPoints[j].mX &&
                pathgrid.mPoints[i].mY == pathgrid.mPoints[j].mY &&
                pathgrid.mPoints[i].mZ == pathgrid.mPoints[j].mZ)
            {
                std::vector<int>::const_iterator it = find(duplList.begin(), duplList.end(), i);
                if (it == duplList.end())
                {
                    std::ostringstream ss;
                    ss << " has a duplicated point (" << i
                        << ") x=" << pathgrid.mPoints[i].mX
                        << ", y=" << pathgrid.mPoints[i].mY
                        << ", z=" << pathgrid.mPoints[i].mZ;
                    messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));

                    duplList.push_back(i);
                    break;
                }
            }
        }
    }

    // check pathgrid points that are not connected to anything
    for (unsigned int i = 0; i < pointList.size(); ++i)
    {
        if (pointList[i].mConnectionNum == 0)
        {
            std::ostringstream ss;
            ss << " has an orphaned point (" << i
                << ") x=" << pathgrid.mPoints[i].mX
                << ", y=" << pathgrid.mPoints[i].mY
                << ", z=" << pathgrid.mPoints[i].mZ;
            messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
        }
    }

    // TODO: check whether there are disconnected graphs
}
Exemple #14
0
    void DepthVideoApp::AlignPointCloudList(int groupSize, bool isSubThread)
    {
        if (IsCommandAvaliable() == false)
        {
            return;
        }
        if (isSubThread)
        {
            mCommandType = CT_ALIGN_POINTCLOUD;
            mGroupSize = groupSize;
            DoCommand(true);
        }
        else
        {
            std::vector<std::string> fileNames;
            char filterName[] = "ASC Files(*.asc)\0*.asc\0OBJ Files(*.obj)\0*.obj\0PLY Files(*.ply)\0*.ply\0Geometry++ Point Cloud(*.gpc)\0*.gpc\0";
            if (MagicCore::ToolKit::MultiFileOpenDlg(fileNames, filterName))
            {
                int fileCount = fileNames.size();
                InfoLog << "fileCount = " << fileCount << std::endl;
                if (fileCount < 2)
                {
                    return;
                }

                //int groupSize = 45;
                int groupCount = fileCount / groupSize;
                if (fileCount % groupSize > 5)
                {
                    groupCount++;
                }
                for (int groupId = 0; groupId < groupCount; groupId++)
                {
                    ClearPointCloudList();
                    std::vector<GPP::Matrix4x4> initTransformList;
                    initTransformList.reserve(fileCount);
                    GPP::PointCloud* lastPointCloud = NULL;
                    GPP::Matrix4x4 transformAcc;
                    transformAcc.InitIdentityTransform();
                    int startFileId = groupId * groupSize;
                    int endFileId = startFileId + groupSize;
                    endFileId = endFileId > fileCount ? fileCount : endFileId;
                    for (int depthId = startFileId; depthId < endFileId; depthId++)
                    {
                        GPP::PointCloud* curPointCloud = GPP::Parser::ImportPointCloud(fileNames.at(depthId));
                        if (curPointCloud == NULL || curPointCloud->GetPointCount() < 10000)
                        {
                            InfoLog << "Point Cloud " << depthId << " Import failed" << std::endl;
                            continue;
                        }
                        GPP::PointCloud* originPointCloud = GPP::CopyPointCloud(curPointCloud); 
                        // Align point cloud
                        if (lastPointCloud != NULL)
                        {
                            int curPointCount = curPointCloud->GetPointCount();
                            for (int pid = 0; pid < curPointCount; pid++)
                            {
                                curPointCloud->SetPointCoord(pid, transformAcc.TransformPoint(curPointCloud->GetPointCoord(pid)));
                                curPointCloud->SetPointNormal(pid, transformAcc.RotateVector(curPointCloud->GetPointNormal(pid)));
                            }

                            GPP::Matrix4x4 transformLocal;
                            transformLocal.InitIdentityTransform();
                            GPP::ErrorCode res = GPP::RegistratePointCloud::AlignPointCloud(lastPointCloud, curPointCloud, &transformLocal, 
                                1000);
                            if (res != GPP_NO_ERROR)
                            {
                                InfoLog << "Point Cloud " << depthId << " AlignPointCloud failed" << std::endl;
                                GPPFREEPOINTER(curPointCloud);
                                GPPFREEPOINTER(originPointCloud);
                                continue;
                            }
                            else
                            {
                                for (int pid = 0; pid < curPointCount; pid++)
                                {
                                    curPointCloud->SetPointCoord(pid, transformLocal.TransformPoint(curPointCloud->GetPointCoord(pid)));
                                    curPointCloud->SetPointNormal(pid, transformLocal.RotateVector(curPointCloud->GetPointNormal(pid)));
                                }
                                GPP::Matrix4x4 icpLocal;
                                icpLocal.InitIdentityTransform();
                                res = GPP::RegistratePointCloud::ICPRegistrate(lastPointCloud, NULL, curPointCloud, NULL, 
                                    &icpLocal, NULL, true);
                                if (res == GPP_NO_ERROR)
                                {
                                    for (int pid = 0; pid < curPointCount; pid++)
                                    {
                                        curPointCloud->SetPointCoord(pid, icpLocal.TransformPoint(curPointCloud->GetPointCoord(pid)));
                                        curPointCloud->SetPointNormal(pid, icpLocal.RotateVector(curPointCloud->GetPointNormal(pid)));
                                    }
                                    transformLocal = icpLocal * transformLocal;
                                }
                                else
                                {
                                    InfoLog << "Point Cloud " << depthId << " ICPRegistrate failed" << std::endl;
                                    GPPFREEPOINTER(curPointCloud);
                                    GPPFREEPOINTER(originPointCloud);
                                    continue;
                                }
                                transformAcc = transformLocal * transformAcc;
                            }
                        }  
                        GPPFREEPOINTER(lastPointCloud);
                        lastPointCloud = curPointCloud;

                        mPointCloudList.push_back(originPointCloud);
                        initTransformList.push_back(transformAcc);
                        // Export point cloud
                        std::string inputModelName = fileNames.at(depthId);
                        size_t dotPos = inputModelName.rfind('.');
                        std::stringstream dumpStream;
                        dumpStream << inputModelName.substr(0, dotPos) << "_align.asc";
                        std::string outputModelName;
                        dumpStream >> outputModelName;
                        GPP::Parser::ExportPointCloud(outputModelName, curPointCloud);

                        mProgressValue = int(depthId * 100.0 / fileCount);
                        mUpdateUIScrollBar = true;
                        mUpdatePointCloudListRendering = true;
                    }
                    GPPFREEPOINTER(lastPointCloud);
                    if (mPointCloudList.size() < 2)
                    {
                        MessageBox(NULL, "³õʼƴ½Óʧ°Ü", "ÎÂÜ°Ìáʾ", MB_OK);
                        return;
                    }
                    //mProgressValue = -1;
                    // Global registrate
                    std::vector<GPP::IPointCloud*> pointCloudList;
                    for (std::vector<GPP::PointCloud*>::iterator itr = mPointCloudList.begin(); itr != mPointCloudList.end(); ++itr)
                    {
                        pointCloudList.push_back(*itr);
                    }
                    std::vector<GPP::Matrix4x4> resultTransform;
                    GPP::ErrorCode res = GPP::RegistratePointCloud::GlobalRegistrate(&pointCloudList, 10, &resultTransform, 
                        &initTransformList, true, 0);
                    if (res != GPP_NO_ERROR)
                    {
                        MessageBox(NULL, "È«¾Ö×¢²áʧ°Ü", "ÎÂÜ°Ìáʾ", MB_OK);
                        return;
                    }

                    int cloudCount = mPointCloudList.size();   
                    // Fuse point cloud
                    GPP::Vector3 bboxMin, bboxMax;
                    res = GPP::CalculatePointCloudListBoundingBox(pointCloudList, &resultTransform, bboxMin, bboxMax);
                    if (res != GPP_NO_ERROR)
                    {
                        MessageBox(NULL, "°üΧºÐ¼ÆËãʧ°Ü", "ÎÂÜ°Ìáʾ", MB_OK);
                        return;
                    }
                    GPP::Vector3 deltaVec(0.1, 0.1, 0.1);
                    bboxMin -= deltaVec;
                    bboxMax += deltaVec;
                    GPP::PointCloudPointList pointList(pointCloudList.at(0));
                    double epsilon = 0;
                    res = GPP::CalculatePointListDensity(&pointList, 4, epsilon);
                    int resolutionX = int((bboxMax[0] - bboxMin[0]) / epsilon) + 1;
		            int resolutionY = int((bboxMax[1] - bboxMin[1]) / epsilon) + 1;
		            int resolutionZ = int((bboxMax[2] - bboxMin[2]) / epsilon) + 1;
                    InfoLog << "epsilon=" << epsilon << " resX=" << resolutionX << " resY=" << resolutionY << " resZ=" << resolutionZ << std::endl;
                    GPP::SignedDistanceFunction sdf(resolutionX, resolutionY, resolutionZ, bboxMin, bboxMax);
                    for (int cid = 0; cid < cloudCount; cid++)
                    {
                        //mProgressValue = int(cid * 100.0 / cloudCount);
                        res = sdf.UpdateFunction(pointCloudList.at(cid), &(resultTransform.at(cid)));
                        if (res != GPP_NO_ERROR)
                        {
                            MessageBox(NULL, "µãÔÆÈÚºÏʧ°Ü", "ÎÂÜ°Ìáʾ", MB_OK);
                            return;
                        }
                    }
                    GPP::PointCloud* fusedPointCloud = new GPP::PointCloud;
                    res = sdf.ExtractPointCloud(fusedPointCloud);
                    if (res != GPP_NO_ERROR)
                    {
                        MessageBox(NULL, "µãÔÆÝÍȡʧ°Ü", "ÎÂÜ°Ìáʾ", MB_OK);
                        return;
                    }
                    mPointCloudList.push_back(fusedPointCloud);
                    mUpdateUIScrollBar = true;
                    mUpdatePointCloudListRendering = true;
                    // save result
                    std::stringstream outputStream;
                    outputStream << "fuse_res_" << groupId << ".asc";
                    std::string outputModelName;
                    outputStream >> outputModelName;
                    res = GPP::Parser::ExportPointCloud(outputModelName, fusedPointCloud);
                    if (res != GPP_NO_ERROR)
                    {
                        MessageBox(NULL, "µ¼³öµãÔÆʧ°Ü", "ÎÂÜ°Ìáʾ", MB_OK);
                    }
                }
            }
            else
            {
                InfoLog << "Open file failed" << std::endl;
            }
        }