示例#1
0
文件: newick.cpp 项目: askmm/HGTtools
void tree::Tree2Newick(const char* name)
{
	printf("TREE OUTPUT\n");
	FILE* f = stdout;//fopen(name, "w+");
	if (!f)
	{
		printf("Err: output stream ?\n");
		exit(1);
	}
	tre(Root, f);
	fprintf(f, ";\n");
}
示例#2
0
文件: newick.cpp 项目: askmm/HGTtools
void tree::tre(node* r, FILE* f)
{
	int i;
	fprintf(f, "(");
	for (i = 0; i < r->childs.size(); ++i)
	{
		if (r->childs[i]->childs.size() == 0)
		{
			fprintf(f, "%s", r->childs[i]->clade[0].c_str());
			if (r->childs[i]->edge != 0)
				fprintf(f, ":%d", r->childs[i]->edge);
		}
		else
		{
			tre(r->childs[i], f);
		}
		if (i + 1 < r->childs.size()) fprintf(f, ",");
	}
	fprintf(f, ")");
	if (r != Root && r->edge != 0)
	{
		printf(":%d", r->edge);
	}
}
示例#3
0
/* This test should be used to verify the TRE modifications work.
 * It probably should not be added to a core canon of tests, but
 * it is useful to test any changes with the TRE API
 */
int main(int argc, char **argv)
{
    try
    {
        std::string divider(
            "---------------------------------------------------------");

        //create an ACFTA TRE
        nitf::TRE tre("ACFTA");
        //tre.print(); //print it
        std::cout << divider << std::endl;

        //set a field
        tre.setField("AC_MSN_ID", "fly-by");
        //tre.print();
        std::cout << divider << std::endl;

        //re-set the field
        tre.setField("AC_MSN_ID", 1.2345678);
        //tre.print();
        std::cout << divider << std::endl;

        //try setting an invalid tag
        try
        {
            tre.setField("invalid-tag", "some data");
        }
        catch (except::Throwable & t)
        {
            std::cout << t.getMessage() << std::endl;
        }

        // Now, try to create a SANE TRE
        tre = nitf::TRE("JITCID");
        tre.setField("FILCMT", "fyi");
        //tre.print();
        std::cout << divider << std::endl;

        //is sane?
        //std::cout << "Is Sane? " << (tre.isSane() ? "yes" : "no") << std::endl;

        // try cloning the tre
        nitf::TRE dolly = tre.clone();
        //dolly.print();
        std::cout << divider << std::endl;

        //the two should NOT be equal -- underlying object is different
        std::cout << "Equal? : " << (tre == dolly ? "yes" : "no") << std::endl;

        //is dolly sane?
        //std::cout << "Is Sane? " << (dolly.isSane() ? "yes" : "no") << std::endl;


        //let's try getting the TREDescriptions ourselves

        /*        nitf::TREDescriptionInfo *infoPtr = NULL;
                nitf::TREDescriptionSet *descriptions =
                    nitf::TRE::getTREDescriptionSet("ACFTA");
                int numDescriptions = 0;
                infoPtr = descriptions->descriptions;
                while (infoPtr && (infoPtr->description != NULL))
                {
                    numDescriptions++;
                    infoPtr++;
                }
                std::cout << "Found " << numDescriptions << " descriptions for ACFTA" << std::endl;

                infoPtr = descriptions->descriptions;
                while (infoPtr && (infoPtr->description != NULL))
                {
                    std::cout << "Name: " << infoPtr->name << ", Length: " <<
                        infoPtr->lengthMatch << std::endl << divider << std::endl;
                    tre = nitf::TRE("ACFTA", infoPtr->description);
                    tre.print();
                    std::cout << divider << std::endl;
                    infoPtr++;
                }
        */
    }
    catch (except::Throwable & t)
    {
        std::cout << t.getMessage() << std::endl;
    }
    return 0;
}
示例#4
0
int main(int argc, char** argv)
{
    try
    {
        nitf_Error e;

//        Foo<int>* foo = new Bar<int>();
//        delete foo;

        nitf_Field* cField = nitf_Field_construct(100, NITF_BCS_N, &e);
        nitf::Field field(cField);

        {
            nitf::Field field2(cField);
        }

        std::cout << field.isValid() << std::endl;


        nitf_BandInfo* cBandInfo = nitf_BandInfo_construct(&e);
        assert(cBandInfo);

        nitf::BandInfo info(cBandInfo);

        std::cout << (int)info.getNumLUTs() << std::endl;

        std::cout << "HERE!!!!!!!!!!!!!!!!!!!!" << std::endl;
        nitf::SubWindow sub;
        nitf::SubWindow sub2 = sub;
        sub.setNumRows(5);

        nitf::PixelSkip p(1, 1);
        sub.setDownSampler(p);
        sub.setDownSampler(p);
        sub.setDownSampler(p);
        sub.setDownSampler(p);

        nitf::PixelSkip p2(1, 1);
        sub.setDownSampler(p2);
        sub.setDownSampler(p);


        nitf_SubWindow* subw = nitf_SubWindow_construct(&e);
        nitf::SubWindow sub3(subw);
        std::cout << sub.getNumRows() <<  " == " << sub2.getNumRows() << std::endl;


        nitf::List list;
        nitf::List list2 = list;

        {
            nitf::FileHeader header;
            nitf::FileHeader header2(header.clone());
            //should be not equal
            std::cout << "Equal? " << (header == header2) << std::endl;
            nitf::FileHeader header3(header2);
            //these two should be equal
            std::cout << "Equal? " << (header3 == header2) << std::endl;
        }

        nitf::HashTable hash;

        nitf::Extensions extensions;
        {
            nitf::ImageSegment imageSeg;
            nitf::ImageSubheader imageSub;

            imageSeg.getSubheader().getImageId() = "Test Image";
            std::cout << imageSeg.getSubheader().getImageId().toString() << std::endl;
            nitf::Field f = imageSeg.getSubheader().getImageId();
            std::cout << f.toString() << std::endl;

            nitf::ImageSegment imageSeg2 = imageSeg.clone();
            nitf::ImageSubheader imageSub2(imageSub.clone());

            extensions = imageSub.getExtendedSection();
        }

        nitf::TextSegment tSeg;
        nitf::TextSubheader tSub;

        nitf::GraphicSegment gSeg;
        nitf::GraphicSubheader gSub;

        nitf::DESegment dSeg;
        nitf::DESubheader dSub;

        nitf::LabelSegment rSeg;
        nitf::LabelSubheader rSub;

        nitf::TRE tre("JITCID");
        //tre.print();
        std::cout << "HERE!!!!!" << std::endl;

        nitf::Reader reader;
        nitf::Writer writer;


        //open a file
        sys::OS os;
        std::vector< std::string > files;
        for (int i = 1; i < argc; ++i)
        {
            if (!os.exists(argv[i]))
                std::cout << "Error -> File does not exist: " << argv[i] << std::endl;
            else
                files.push_back(argv[i]);
        }

        for (std::vector< std::string >::iterator it = files.begin(); it != files.end(); ++it)
        {
            nitf::IOHandle handle(*it);
            nitf::Reader rdr;
            nitf::Record rec = rdr.read(handle);

            std::cout << "CODEWORDS: " << rec.getHeader().getSecurityGroup().getCodewords().toString() << std::endl;
            rec.getHeader().getSecurityGroup().getCodewords() = "TEST";
            std::cout << "CODEWORDS: " << rec.getHeader().getSecurityGroup().getCodewords().toString() << std::endl;
            nitf::FileSecurity security;
            rec.getHeader().setSecurityGroup(security);
            std::cout << "CODEWORDS: " << rec.getHeader().getSecurityGroup().getCodewords().toString() << std::endl;
            std::cout << "Num Images: " << rec.getImages().getSize() << std::endl;
        }

        nitf_SubWindow_destruct(&subw);
        nitf_Field_destruct(&cField);
        nitf_BandInfo_destruct(&cBandInfo);
    }
    catch(except::Exception& ex)
    {
        std::cerr << "ERROR: " << ex.getMessage() << std::endl;
        return 1;
    }

    return 0;
}
示例#5
0
int main () 
{
	int * arrrr = new int[14];
	int * marrr;
	marrr = (int *) malloc (14);
	for (int i = 0; i < 14; i++) 
	{
		arrrr[i] = i;
		marrr[i] = i + 1;
	}

	// SCOPED POINTER
	std::cout << "SCOPED_PTR: " << std::endl;

	scoped_ptr <int> arr (arrrr, arrdeleter <int> ());
	scoped_ptr <int> array (marrr, mfree <int> ());

	std::cout << arr.pointer() << ": Array created with 'new': ";

	for (int i = 0; i < 14; i++) 
		std::cout << arr.pointer()[i] << " ";

	std::cout << "has an address " << &arr << std::endl;

	std::cout << array.pointer() << ": Array created with 'malloc': ";

	for (int i = 0; i < 14; i++) 
		std::cout << array.pointer()[i] << " ";

	std::cout << "has an address " << &array << std::endl;

	std::cout << "Objects of class 'object' created with 'new' in loop of 3: " << std::endl;

	for (int i = 0; i < 3; i++) 
	{
		object * t = new object (i);
		scoped_ptr <object> tre (t, objdeleter <object> ());
		std::cout << "Pointer object address: " << &tre << " -> " << tre.pointer()->x << std::endl;
	}

	std::cout << std::endl;

	// AUTO POINTER
	std::cout << "AUTO_PTR: " << std::endl;

	auto_ptr <int> aarr(arrrr, arrdeleter <int> ());
	auto_ptr <int> aarray(marrr, mfree <int> ());

	std::cout << aarr.pointer() << ": Array created with 'new': ";
	
	for (int i = 0; i < 14; i++) 
		std::cout << aarr.pointer()[i] << " ";
	
	std::cout << "has an address " << &aarr << std::endl;

	std::cout << aarray.pointer() << ": Array created with 'malloc': ";

	for (int i = 0; i < 14; i++) 
		std::cout << aarray.pointer()[i] << " ";
	
	std::cout << "has an address " << &aarray << std::endl << std::endl;

	auto_ptr <int> copy = aarr;
	
	std::cout << copy.pointer() << ": Copy of pointer to first array: ";
	
	for (int i = 0; i < 14; i++) 
		std::cout << copy.pointer()[i] << " ";
	
	std::cout << "has an address " << &copy << std::endl;
	std::cout << "Old pointer points to address " << aarr.pointer() << std::endl << std::endl;

	std::cout << "Objects of class 'object' created with 'new' in loop of 3: " << std::endl;
	
	for (int i = 0; i < 3; i++) 
	{
		object * t = new object(i);
		auto_ptr <object> tre(t, objdeleter <object> ());
		std::cout << "Pointer object address: " << &tre << " -> " << tre.pointer()->x << std::endl;
	}
	
	std::cout << std::endl;
	return 0;
}
示例#6
0
void NitfWriter::done(PointTableRef table)
{
    LasWriter::done(table);

    try
    {
        ::nitf::Record record(NITF_VER_21);
        ::nitf::FileHeader header = record.getHeader();
        header.getFileHeader().set("NITF");
        header.getComplianceLevel().set(m_cLevel);
        header.getSystemType().set(m_sType);
        header.getOriginStationID().set(m_oStationId);
        header.getFileTitle().set(m_fileTitle);
        header.getClassification().set(m_fileClass);
        header.getMessageCopyNum().set("00000");
        header.getMessageNumCopies().set("00000");
        header.getEncrypted().set("0");
        header.getBackgroundColor().setRawData(const_cast<char*>("000"), 3);
        header.getOriginatorName().set(m_origName);
        header.getOriginatorPhone().set(m_origPhone);
        header.getSecurityGroup().getClassificationSystem().set(m_securityClassificationSystem);
        header.getSecurityGroup().getControlAndHandling().set(m_securityControlAndHandling);
        header.getSecurityGroup().getClassificationText().set(m_sic);

        ::nitf::DESegment des = record.newDataExtensionSegment();

        des.getSubheader().getFilePartType().set("DE");
        des.getSubheader().getTypeID().set("LIDARA DES");
        des.getSubheader().getVersion().set("01");
        des.getSubheader().getSecurityClass().set(m_securityClass);
        ::nitf::FileSecurity security = record.getHeader().getSecurityGroup();
        des.getSubheader().setSecurityGroup(security.clone());

        ::nitf::TRE usrHdr("LIDARA DES", "raw_data");
        usrHdr.setField("raw_data", "not");
        ::nitf::Field fld = usrHdr.getField("raw_data");
        fld.setType(::nitf::Field::BINARY);

        flush();
        m_oss.flush();
        std::streambuf *buf = m_oss.rdbuf();
        long size = buf->pubseekoff(0, m_oss.end);
        buf->pubseekoff(0, m_oss.beg);

        std::vector<char> bytes(size);
        buf->sgetn(bytes.data(), size);

        des.getSubheader().setSubheaderFields(usrHdr);

        ::nitf::ImageSegment image = record.newImageSegment();
        ::nitf::ImageSubheader subheader = image.getSubheader();


        BOX3D bounds =  reprojectBoxToDD(table.spatialRef(), m_bounds);

        //NITF decimal degree values for corner coordinates only has a
        // precision of 3 after the decimal. This may cause an invalid
        // polygon due to rounding errors with a small tile. Therefore
        // instead of rounding min values will use the floor value and
        // max values will use the ceiling values.
        bounds.minx = (floor(bounds.minx * 1000)) / 1000.0;
        bounds.miny = (floor(bounds.miny * 1000)) / 1000.0;
        bounds.maxx = (ceil(bounds.maxx * 1000)) / 1000.0;
        bounds.maxy = (ceil(bounds.maxy * 1000)) / 1000.0;

        double corners[4][2];
        corners[0][0] = bounds.maxy;
        corners[0][1] = bounds.minx;
        corners[1][0] = bounds.maxy;
        corners[1][1] = bounds.maxx;
        corners[2][0] = bounds.miny;
        corners[2][1] = bounds.maxx;
        corners[3][0] = bounds.miny;
        corners[3][1] = bounds.minx;
        subheader.setCornersFromLatLons(NRT_CORNERS_DECIMAL, corners);

        subheader.getImageSecurityClass().set(m_imgSecurityClass);
        subheader.setSecurityGroup(security.clone());
        if (m_imgDate.size())
            subheader.getImageDateAndTime().set(m_imgDate);

        ::nitf::BandInfo info;
        ::nitf::LookupTable lt(0,0);
        info.init("G",    /* The band representation, Nth band */
                  " ",      /* The band subcategory */
                  "N",      /* The band filter condition */
                  "   ",    /* The band standard image filter code */
                  0,        /* The number of look-up tables */
                  0,        /* The number of entries/LUT */
                  lt);     /* The look-up tables */

        std::vector< ::nitf::BandInfo> bands;
        bands.push_back(info);
        subheader.setPixelInformation(
            "INT",      /* Pixel value type */
            8,         /* Number of bits/pixel */
            8,         /* Actual number of bits/pixel */
            "R",       /* Pixel justification */
            "NODISPLY",     /* Image representation */
            "VIS",     /* Image category */
            1,         /* Number of bands */
            bands);

        subheader.setBlocking(
            8,   /*!< The number of rows */
            8,  /*!< The number of columns */
            8, /*!< The number of rows/block */
            8,  /*!< The number of columns/block */
            "P");                /*!< Image mode */

        //Image Header fields to set
        subheader.getImageId().set("None");
        subheader.getImageTitle().set(m_imgIdentifier2);

        // 64 char string
        std::string zeros(64, '0');

        std::unique_ptr< ::nitf::BandSource> band(new ::nitf::MemorySource(
            const_cast<char*>(zeros.c_str()),
            zeros.size() /* memory size */,
            0 /* starting offset */,
            1 /* bytes per pixel */,
            0 /*skip*/));
        ::nitf::ImageSource iSource;
        iSource.addBand(*band);

        //AIMIDB
        if (!m_aimidb.empty())
        {
            boost::optional<const Options&> options = m_aimidb.getOptions();
            if (options)
            {
                ::nitf::TRE tre("AIMIDB");
                std::vector<Option> opts = options->getOptions();
                for (auto i = opts.begin(); i != opts.end(); ++i)
                {
                    tre.setField(i->getName(), i->getValue<std::string>());
                }
                subheader.getExtendedSection().appendTRE(tre);
            }
        }

        //ACFTB
        if (!m_acftb.empty())
        {
            boost::optional<const Options&> options = m_acftb.getOptions();
            if (options)
            {
                ::nitf::TRE tre("ACFTB");
                std::vector<Option> opts = options->getOptions();
                for (auto i = opts.begin(); i != opts.end(); ++i)
                {
                    tre.setField(i->getName(), i->getValue<std::string>());
                }
                subheader.getExtendedSection().appendTRE(tre);
            }
        }

        ::nitf::Writer writer;
        ::nitf::IOHandle output_io(m_filename.c_str(), NITF_ACCESS_WRITEONLY,
            NITF_CREATE);
        writer.prepare(output_io, record);

        ::nitf::SegmentWriter sWriter = writer.newDEWriter(0);

        ::nitf::SegmentMemorySource sSource(bytes.data(), size, 0, 0, false);
        sWriter.attachSource(sSource);

        ::nitf::ImageWriter iWriter = writer.newImageWriter(0);
        iWriter.attachSource(iSource);

        writer.write();
        output_io.close();
    }
    catch (except::Throwable & t)
    {
        std::ostringstream oss;
        // std::cout << t.getTrace();
        throw pdal_error(t.getMessage());
    }
}