<commit_before>/*
 * DISTRHO Plugin Framework (DPF)
 * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any purpose with
 * or without fee is hereby granted, provided that the above copyright notice and this
 * permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef DISTRHO_PLUGIN_UTILS_HPP_INCLUDED
#define DISTRHO_PLUGIN_UTILS_HPP_INCLUDED

#include "DistrhoPlugin.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------------------------------------------

/**
   Handy class to help keep audio buffer in sync with incoming MIDI events.
   To use it, create a local variable (on the stack) and call nextEvent() until it returns false.
   @code
    for (AudioMidiSyncHelper amsh(outputs, frames, midiEvents, midiEventCount); amsh.nextEvent();)
    {
        float* const outL = amsh.outputs[0];
        float* const outR = amsh.outputs[1];

        for (uint32_t i=0; i<amsh.midiEventCount; ++i)
        {
            const MidiEvent& ev(amsh.midiEvents[i]);
            // ... do something with the midi event
        }

        renderSynth(outL, outR, amsh.frames);
    }
   @endcode

   Some important notes when using this class:
    1. MidiEvent::frame retains its original value, but it is useless, do not use it.
    2. The class variable names are the same as the default ones in the run function.
       Keep that in mind and try to avoid typos. :)
 */
class AudioMidiSyncHelper {
public:
    /** Parameters from the run function, adjusted for event sync */
    float* outputs[DISTRHO_PLUGIN_NUM_OUTPUTS];
    uint32_t frames;
    const MidiEvent* midiEvents;
    uint32_t midiEventCount;

    /**
       Constructor, using values from the run function.
    */
    AudioMidiSyncHelper(float** const o, uint32_t f, const MidiEvent* m, uint32_t mc)
        : outputs(),
          frames(0),
          midiEvents(m),
          midiEventCount(0),
          remainingFrames(f),
          remainingMidiEventCount(mc),
          totalFramesUsed(0)
    {
        for (uint i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
            outputs[i] = o[i];
    }

    /**
       Process a batch of events untill no more are available.
       You must not read any more values from this class after this function returns false.
    */
    bool nextEvent()
    {
        // nothing else to do
        if (remainingFrames == 0)
            return false;

        // initial setup, need to find first MIDI event
        if (totalFramesUsed == 0)
        {
            // no MIDI events at all in this process cycle
            if (remainingMidiEventCount == 0)
            {
                frames = remainingFrames;
                remainingFrames = 0;
                totalFramesUsed += frames;
                return true;
            }

            // render audio until first midi event, if needed
            if (const uint32_t firstEventFrame = midiEvents[0].frame)
            {
                DISTRHO_SAFE_ASSERT_UINT2_RETURN(firstEventFrame < remainingFrames,
                                                 firstEventFrame, remainingFrames, false);
                frames = firstEventFrame;
                remainingFrames -= firstEventFrame;
                totalFramesUsed += firstEventFrame;
                return true;
            }
        }
        else
        {
            for (uint32_t i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
                outputs[i] += frames;
        }

        // no more MIDI events available
        if (remainingMidiEventCount == 0)
        {
            frames = remainingFrames;
            midiEvents = nullptr;
            midiEventCount = 0;
            remainingFrames = 0;
            totalFramesUsed += frames;
            return true;
        }

        // if there were midi events before, increment pointer
        if (midiEventCount != 0)
            midiEvents += midiEventCount;

        const uint32_t firstEventFrame = midiEvents[0].frame;
        DISTRHO_SAFE_ASSERT_UINT2_RETURN(firstEventFrame >= totalFramesUsed,
                                         firstEventFrame, totalFramesUsed, false);

        midiEventCount = 1;
        while (midiEventCount < remainingMidiEventCount)
        {
            if (midiEvents[midiEventCount].frame == firstEventFrame)
                ++midiEventCount;
            else
                break;
        }

        frames = firstEventFrame - totalFramesUsed;
        remainingFrames -= frames;
        remainingMidiEventCount -= midiEventCount;
        totalFramesUsed += frames;
        return true;
    }

private:
    /** @internal */
    uint32_t remainingFrames;
    uint32_t remainingMidiEventCount;
    uint32_t totalFramesUsed;
};

// -----------------------------------------------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_PLUGIN_UTILS_HPP_INCLUDED
<commit_msg>Change AudioMidiSyncHelper to be a struct<commit_after>/*
 * DISTRHO Plugin Framework (DPF)
 * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any purpose with
 * or without fee is hereby granted, provided that the above copyright notice and this
 * permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef DISTRHO_PLUGIN_UTILS_HPP_INCLUDED
#define DISTRHO_PLUGIN_UTILS_HPP_INCLUDED

#include "DistrhoPlugin.hpp"

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------------------------------------------

/**
   Handy class to help keep audio buffer in sync with incoming MIDI events.
   To use it, create a local variable (on the stack) and call nextEvent() until it returns false.
   @code
    for (AudioMidiSyncHelper amsh(outputs, frames, midiEvents, midiEventCount); amsh.nextEvent();)
    {
        float* const outL = amsh.outputs[0];
        float* const outR = amsh.outputs[1];

        for (uint32_t i=0; i<amsh.midiEventCount; ++i)
        {
            const MidiEvent& ev(amsh.midiEvents[i]);
            // ... do something with the midi event
        }

        renderSynth(outL, outR, amsh.frames);
    }
   @endcode

   Some important notes when using this class:
    1. MidiEvent::frame retains its original value, but it is useless, do not use it.
    2. The class variable names are the same as the default ones in the run function.
       Keep that in mind and try to avoid typos. :)
 */
struct AudioMidiSyncHelper
{
    /** Parameters from the run function, adjusted for event sync */
    float* outputs[DISTRHO_PLUGIN_NUM_OUTPUTS];
    uint32_t frames;
    const MidiEvent* midiEvents;
    uint32_t midiEventCount;

    /**
       Constructor, using values from the run function.
    */
    AudioMidiSyncHelper(float** const o, uint32_t f, const MidiEvent* m, uint32_t mc)
        : outputs(),
          frames(0),
          midiEvents(m),
          midiEventCount(0),
          remainingFrames(f),
          remainingMidiEventCount(mc),
          totalFramesUsed(0)
    {
        for (uint i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
            outputs[i] = o[i];
    }

    /**
       Process a batch of events untill no more are available.
       You must not read any more values from this class after this function returns false.
    */
    bool nextEvent()
    {
        // nothing else to do
        if (remainingFrames == 0)
            return false;

        // initial setup, need to find first MIDI event
        if (totalFramesUsed == 0)
        {
            // no MIDI events at all in this process cycle
            if (remainingMidiEventCount == 0)
            {
                frames = remainingFrames;
                remainingFrames = 0;
                totalFramesUsed += frames;
                return true;
            }

            // render audio until first midi event, if needed
            if (const uint32_t firstEventFrame = midiEvents[0].frame)
            {
                DISTRHO_SAFE_ASSERT_UINT2_RETURN(firstEventFrame < remainingFrames,
                                                 firstEventFrame, remainingFrames, false);
                frames = firstEventFrame;
                remainingFrames -= firstEventFrame;
                totalFramesUsed += firstEventFrame;
                return true;
            }
        }
        else
        {
            for (uint32_t i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
                outputs[i] += frames;
        }

        // no more MIDI events available
        if (remainingMidiEventCount == 0)
        {
            frames = remainingFrames;
            midiEvents = nullptr;
            midiEventCount = 0;
            remainingFrames = 0;
            totalFramesUsed += frames;
            return true;
        }

        // if there were midi events before, increment pointer
        if (midiEventCount != 0)
            midiEvents += midiEventCount;

        const uint32_t firstEventFrame = midiEvents[0].frame;
        DISTRHO_SAFE_ASSERT_UINT2_RETURN(firstEventFrame >= totalFramesUsed,
                                         firstEventFrame, totalFramesUsed, false);

        midiEventCount = 1;
        while (midiEventCount < remainingMidiEventCount)
        {
            if (midiEvents[midiEventCount].frame == firstEventFrame)
                ++midiEventCount;
            else
                break;
        }

        frames = firstEventFrame - totalFramesUsed;
        remainingFrames -= frames;
        remainingMidiEventCount -= midiEventCount;
        totalFramesUsed += frames;
        return true;
    }

private:
    /** @internal */
    uint32_t remainingFrames;
    uint32_t remainingMidiEventCount;
    uint32_t totalFramesUsed;
};

// -----------------------------------------------------------------------------------------------------------

END_NAMESPACE_DISTRHO

#endif // DISTRHO_PLUGIN_UTILS_HPP_INCLUDED
<|endoftext|>


<commit_before>/*
 *  about_dialog.cpp
 *  PHD Guiding
 *
 *  Created by Sylvain Girard.
 *  Copyright (c) 2013 Sylvain Girard.
 *  All rights reserved.
 *
 *  This source code is distributed under the following "BSD" license
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *    Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *    Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *    Neither the name of Craig Stark, Stark Labs nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "phd.h"
#include "about_dialog.h"
#include <wx/fs_mem.h>
#include <wx/html/htmlwin.h>

BEGIN_EVENT_TABLE(AboutDialog, wxDialog)
    EVT_HTML_LINK_CLICKED(ABOUT_LINK,AboutDialog::OnLink)
END_EVENT_TABLE()

AboutDialog::AboutDialog(void) :
wxDialog(pFrame, wxID_ANY, _T("About ") APPNAME, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{
    SetBackgroundColour(*wxWHITE);

    wxBoxSizer *pSizer = new wxBoxSizer(wxHORIZONTAL);

    #include "icons/phd2_64.png.h"
    wxBitmap phd2(wxBITMAP_PNG_FROM_DATA(phd2_64));
    wxStaticBitmap *pImage = new wxStaticBitmap(this, wxID_ANY, phd2);

    wxFileSystem::AddHandler(new wxMemoryFSHandler);
    wxMemoryFSHandler::AddFile("about.html", wxString::Format(
        ""
        "
%s %s
"
        "PHD2 home page - openphdguiding.org
"
        "PHD2 open source project page

"
        ""
        "Credits:
"
        "
"
        "
"
        "Craig Stark	"
        "Bret McKee	"
        "
"
        "
"
        "Andy Galasso	"
        "Bernhard Reutner-Fischer	"
        "
"
        "
"
        "Stefan Elste	"
        "Geoffrey Hausheer	"
        "
"
        "
"
        "Jared Wellman	"
        "John Wainwright	"
        "
"
        "
"
        "Sylvain Girard	"
        "Bruce Waddington	"
        "
"
        "
"
        "Max Chen	"
        "Carsten Przygoda	"
        "
"
        "
"
        "Hans Lambermont	"
        "David Ault	"
        "
"
        "
"
        "Markus Wieczorek	"
        "Linkage	"
        "
"
        "
"
        "Robin Glover	"
        "Patrick Chevalley	"
        "
"
        "
"
        "Scott Edwards	"
        "Eiji Kaneshige	"
        "
"
        "
"
        "Konstantin Menshikoff   	"
        "Jakub Bartas	"
        "
"
        "
"
        "Javier R	"
        "Oleh Malyi	"
        "
"
        "
"
        "Tsung-Chi Wu	"
        "Raffi Enficiaud	"
        "
"
        "
"
        "Sabin Fota	"
        "Dylan O'Donnell	"
        "
"
        "
"
        "Katsuhiro Kojima	"
        "Simon Taylor	"
        "
"
        "
"
        "Hallgeir Holien	"
        "Laurent Schmitz	"
        "
"
        "
"
        "Atushi Sakauchi	"
        "Giorgio Mazzacurati	"
        "
"
        "
"
        "G\u00FCnter Scholz	"
        "Ray Gralak	"
        "
"
        "
"
        "Khalefa Algadi	"
        "David C. Partridge	"
        "
"
        "
"
        "Matteo Ghellere	"
        "norma	"
        "
"
        "Edgar D. Klenske	"
        "Bernhard Schölkopf	"
        "
"
        "
"
        "Philipp Hennig	"
        "Stephan Wenninger	"
        "
"
        "
"
        "Wagner Trindade	"
        "Cyril Richard	"
        "
"
        "

"
        "
"
        "
"
        "Copyright 2006-2013 Craig Stark
"
        "Copyright 2009 Geoffrey Hausheer
"
        "Copyright 2012-2013 Bret McKee
"
        "Copyright 2013 Sylvain Girard
"
        "Copyright 2013-2017 Andy Galasso
"
        "Copyright 2013-2017 Bruce Waddington
"
        "Copyright 2014 Hans Lambermont
"
        "Copyright 2014 Robin Glover
"
        "Copyright 2014-2017 Max Planck Society
"
        "
"
        "
"
        "The Predictive PEC guide algorithm is based on
"
        "Gaussian Process Based Predictive Control
for Periodic Error Correction"
        ""
        "", APPNAME, FULLVER));
    wxHtmlWindow *pHtml;
    pHtml = new wxHtmlWindow(this, ABOUT_LINK, wxDefaultPosition, wxSize(380, 540), wxHW_SCROLLBAR_AUTO);
    pHtml->SetBorders(0);
    pHtml->LoadPage("memory:about.html");
    pHtml->SetSize(pHtml->GetInternalRepresentation()->GetWidth(), pHtml->GetInternalRepresentation()->GetHeight());

    pSizer->Add(pImage, wxSizerFlags(0).Border(wxALL, 10));
    pSizer->Add(pHtml, wxSizerFlags(0).Border(wxALL, 10));

    wxBoxSizer *pTopLevelSizer = new wxBoxSizer(wxVERTICAL);
    pTopLevelSizer->Add(pSizer, wxSizerFlags(0).Expand());
    pTopLevelSizer->Add(CreateButtonSizer(wxOK), wxSizerFlags(0).Expand().Border(wxALL, 10));
    SetSizerAndFit(pTopLevelSizer);
}

AboutDialog::~AboutDialog(void)
{
    wxMemoryFSHandler::RemoveFile("about.html");
}

void AboutDialog::OnLink(wxHtmlLinkEvent & event)
{
    wxLaunchDefaultBrowser(event.GetLinkInfo().GetHref());
}
<commit_msg>add Mattia Verga to About dialog<commit_after>/*
 *  about_dialog.cpp
 *  PHD Guiding
 *
 *  Created by Sylvain Girard.
 *  Copyright (c) 2013 Sylvain Girard.
 *  All rights reserved.
 *
 *  This source code is distributed under the following "BSD" license
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *    Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *    Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *    Neither the name of Craig Stark, Stark Labs nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "phd.h"
#include "about_dialog.h"
#include <wx/fs_mem.h>
#include <wx/html/htmlwin.h>

BEGIN_EVENT_TABLE(AboutDialog, wxDialog)
    EVT_HTML_LINK_CLICKED(ABOUT_LINK,AboutDialog::OnLink)
END_EVENT_TABLE()

AboutDialog::AboutDialog(void) :
wxDialog(pFrame, wxID_ANY, _T("About ") APPNAME, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{
    SetBackgroundColour(*wxWHITE);

    wxBoxSizer *pSizer = new wxBoxSizer(wxHORIZONTAL);

    #include "icons/phd2_64.png.h"
    wxBitmap phd2(wxBITMAP_PNG_FROM_DATA(phd2_64));
    wxStaticBitmap *pImage = new wxStaticBitmap(this, wxID_ANY, phd2);

    wxFileSystem::AddHandler(new wxMemoryFSHandler);
    wxMemoryFSHandler::AddFile("about.html", wxString::Format(
        ""
        "
%s %s
"
        "PHD2 home page - openphdguiding.org
"
        "PHD2 open source project page

"
        ""
        "Credits:
"
        "
"
        "
"
        "Craig Stark	"
        "Bret McKee	"
        "
"
        "
"
        "Andy Galasso	"
        "Bernhard Reutner-Fischer	"
        "
"
        "
"
        "Stefan Elste	"
        "Geoffrey Hausheer	"
        "
"
        "
"
        "Jared Wellman	"
        "John Wainwright	"
        "
"
        "
"
        "Sylvain Girard	"
        "Bruce Waddington	"
        "
"
        "
"
        "Max Chen	"
        "Carsten Przygoda	"
        "
"
        "
"
        "Hans Lambermont	"
        "David Ault	"
        "
"
        "
"
        "Markus Wieczorek	"
        "Linkage	"
        "
"
        "
"
        "Robin Glover	"
        "Patrick Chevalley	"
        "
"
        "
"
        "Scott Edwards	"
        "Eiji Kaneshige	"
        "
"
        "
"
        "Konstantin Menshikoff   	"
        "Jakub Bartas	"
        "
"
        "
"
        "Javier R	"
        "Oleh Malyi	"
        "
"
        "
"
        "Tsung-Chi Wu	"
        "Raffi Enficiaud	"
        "
"
        "
"
        "Sabin Fota	"
        "Dylan O'Donnell	"
        "
"
        "
"
        "Katsuhiro Kojima	"
        "Simon Taylor	"
        "
"
        "
"
        "Hallgeir Holien	"
        "Laurent Schmitz	"
        "
"
        "
"
        "Atushi Sakauchi	"
        "Giorgio Mazzacurati	"
        "
"
        "
"
        "G\u00FCnter Scholz	"
        "Ray Gralak	"
        "
"
        "
"
        "Khalefa Algadi	"
        "David C. Partridge	"
        "
"
        "
"
        "Matteo Ghellere	"
        "norma	"
        "
"
        "Edgar D. Klenske	"
        "Bernhard Schölkopf	"
        "
"
        "
"
        "Philipp Hennig	"
        "Stephan Wenninger	"
        "
"
        "
"
        "Wagner Trindade	"
        "Cyril Richard	"
        "
"
        "
"
        "Mattia Verga	"
        "	"
        "
"
        "

"
        "
"
        "
"
        "Copyright 2006-2013 Craig Stark
"
        "Copyright 2009 Geoffrey Hausheer
"
        "Copyright 2012-2013 Bret McKee
"
        "Copyright 2013 Sylvain Girard
"
        "Copyright 2013-2017 Andy Galasso
"
        "Copyright 2013-2017 Bruce Waddington
"
        "Copyright 2014 Hans Lambermont
"
        "Copyright 2014 Robin Glover
"
        "Copyright 2014-2017 Max Planck Society
"
        "
"
        "
"
        "The Predictive PEC guide algorithm is based on
"
        "Gaussian Process Based Predictive Control
for Periodic Error Correction"
        ""
        "", APPNAME, FULLVER));
    wxHtmlWindow *pHtml;
    pHtml = new wxHtmlWindow(this, ABOUT_LINK, wxDefaultPosition, wxSize(380, 540), wxHW_SCROLLBAR_AUTO);
    pHtml->SetBorders(0);
    pHtml->LoadPage("memory:about.html");
    pHtml->SetSize(pHtml->GetInternalRepresentation()->GetWidth(), pHtml->GetInternalRepresentation()->GetHeight());

    pSizer->Add(pImage, wxSizerFlags(0).Border(wxALL, 10));
    pSizer->Add(pHtml, wxSizerFlags(0).Border(wxALL, 10));

    wxBoxSizer *pTopLevelSizer = new wxBoxSizer(wxVERTICAL);
    pTopLevelSizer->Add(pSizer, wxSizerFlags(0).Expand());
    pTopLevelSizer->Add(CreateButtonSizer(wxOK), wxSizerFlags(0).Expand().Border(wxALL, 10));
    SetSizerAndFit(pTopLevelSizer);
}

AboutDialog::~AboutDialog(void)
{
    wxMemoryFSHandler::RemoveFile("about.html");
}

void AboutDialog::OnLink(wxHtmlLinkEvent & event)
{
    wxLaunchDefaultBrowser(event.GetLinkInfo().GetHref());
}
<|endoftext|>


<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache\@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation, and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com .  For more information
 * on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * $Log$
 * Revision 1.6  2002/02/01 22:40:44  peiyongz
 * sane_include
 *
 * Revision 1.5  2001/05/11 13:24:57  tng
 * Copyright update.
 *
 * Revision 1.4  2001/05/03 16:00:03  tng
 * Schema: samples update with schema
 *
 * Revision 1.3  2000/10/10 23:55:53  andyh
 * XMLFormatter patch, contributed by Bill Schindler.  Fix problems with
 * output to multi-byte encodings.
 *
 * Revision 1.2  2000/08/09 22:20:38  jpolast
 * updates for changes to sax2 core functionality.
 *
 * Revision 1.1  2000/08/02 19:16:14  jpolast
 * initial checkin of SAX2Print
 *
 *
 */

// ---------------------------------------------------------------------------
//  Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/sax2/Attributes.hpp>
#include "SAX2Print.hpp"

// ---------------------------------------------------------------------------
//  Local const data
//
//  Note: This is the 'safe' way to do these strings. If you compiler supports
//        L"" style strings, and portability is not a concern, you can use
//        those types constants directly.
// ---------------------------------------------------------------------------
static const XMLCh  gEndElement[] = { chOpenAngle, chForwardSlash, chNull };
static const XMLCh  gEndPI[] = { chQuestion, chCloseAngle, chNull };
static const XMLCh  gStartPI[] = { chOpenAngle, chQuestion, chNull };
static const XMLCh  gXMLDecl1[] =
{
        chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
    ,   chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
    ,   chLatin_o, chLatin_n, chEqual, chDoubleQuote, chDigit_1, chPeriod
    ,   chDigit_0, chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
    ,   chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
    ,   chDoubleQuote, chNull
};

static const XMLCh  gXMLDecl2[] =
{
        chDoubleQuote, chQuestion, chCloseAngle
    ,   chLF, chNull
};

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Constructors and Destructor
// ---------------------------------------------------------------------------
SAX2PrintHandlers::SAX2PrintHandlers( const   char* const              encodingName
                                    , const XMLFormatter::UnRepFlags unRepFlags
									, const bool					 expandNamespaces) :

    fFormatter
    (
        encodingName
        , this
        , XMLFormatter::NoEscapes
        , unRepFlags
    ),
	fExpandNS ( expandNamespaces )
{
    //
    //  Go ahead and output an XML Decl with our known encoding. This
    //  is not the best answer, but its the best we can do until we
    //  have SAX2 support.
    //
    fFormatter << gXMLDecl1 << fFormatter.getEncodingName() << gXMLDecl2;
}

SAX2PrintHandlers::~SAX2PrintHandlers()
{
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the output formatter target interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::writeChars(const XMLByte* const toWrite)
{
}

void SAX2PrintHandlers::writeChars(const XMLByte* const toWrite,
                                   const unsigned int count,
                                   XMLFormatter* const formatter)
{
    // For this one, just dump them to the standard output
    // Surprisingly, Solaris was the only platform on which
    // required the char* cast to print out the string correctly.
    // Without the cast, it was printing the pointer value in hex.
    // Quite annoying, considering every other platform printed
    // the string with the explicit cast to char* below.
  cout.write((char *) toWrite, (int) count);
	cout.flush();
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the SAX ErrorHandler interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::error(const SAXParseException& e)
{
    cerr << "\nError at file " << StrX(e.getSystemId())
		 << ", line " << e.getLineNumber()
		 << ", char " << e.getColumnNumber()
         << "\n  Message: " << StrX(e.getMessage()) << endl;
}

void SAX2PrintHandlers::fatalError(const SAXParseException& e)
{
    cerr << "\nFatal Error at file " << StrX(e.getSystemId())
		 << ", line " << e.getLineNumber()
		 << ", char " << e.getColumnNumber()
         << "\n  Message: " << StrX(e.getMessage()) << endl;
}

void SAX2PrintHandlers::warning(const SAXParseException& e)
{
    cerr << "\nWarning at file " << StrX(e.getSystemId())
		 << ", line " << e.getLineNumber()
		 << ", char " << e.getColumnNumber()
         << "\n  Message: " << StrX(e.getMessage()) << endl;
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the SAX DTDHandler interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::unparsedEntityDecl(const     XMLCh* const name
                                          , const   XMLCh* const publicId
                                          , const   XMLCh* const systemId
                                          , const   XMLCh* const notationName)
{
    // Not used at this time
}

void SAX2PrintHandlers::notationDecl(const   XMLCh* const name
                                    , const XMLCh* const publicId
                                    , const XMLCh* const systemId)
{
    // Not used at this time
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the SAX DocumentHandler interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::characters(const     XMLCh* const    chars
                                  , const   unsigned int    length)
{
    fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes);
}

void SAX2PrintHandlers::endDocument()
{
}

void SAX2PrintHandlers::endElement(const XMLCh* const uri,
								 const XMLCh* const localname,
								 const XMLCh* const qname)
{
    // No escapes are legal here
    fFormatter << XMLFormatter::NoEscapes << gEndElement ;
	if ( fExpandNS )
	{
		if (XMLString::compareIString(uri,XMLUni::fgEmptyString) != 0)
				fFormatter  << uri << chColon;
		fFormatter << localname << chCloseAngle;
	}
	else
		fFormatter << qname << chCloseAngle;
}

void SAX2PrintHandlers::ignorableWhitespace( const   XMLCh* const chars
                                            ,const  unsigned int length)
{
    fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes);
}

void SAX2PrintHandlers::processingInstruction(const  XMLCh* const target
                                            , const XMLCh* const data)
{
    fFormatter << XMLFormatter::NoEscapes << gStartPI  << target;
    if (data)
        fFormatter << chSpace << data;
    fFormatter << XMLFormatter::NoEscapes << gEndPI;
}

void SAX2PrintHandlers::startDocument()
{
}

void SAX2PrintHandlers::startElement(const   XMLCh* const    uri,
									const   XMLCh* const    localname,
									const   XMLCh* const    qname,
                                    const   Attributes&		attributes)
{
    // The name has to be representable without any escapes
    fFormatter  << XMLFormatter::NoEscapes << chOpenAngle ;
	if ( fExpandNS )
	{
		if (XMLString::compareIString(uri,XMLUni::fgEmptyString) != 0)
				fFormatter  << uri << chColon;
		fFormatter << localname ;
	}
	else
		fFormatter << qname ;

    unsigned int len = attributes.getLength();
    for (unsigned int index = 0; index < len; index++)
    {
        //
        //  Again the name has to be completely representable. But the
        //  attribute can have refs and requires the attribute style
        //  escaping.
        //
        fFormatter  << XMLFormatter::NoEscapes << chSpace ;
		if ( fExpandNS )
		{
			if (XMLString::compareIString(attributes.getURI(index),XMLUni::fgEmptyString) != 0)
				fFormatter  << attributes.getURI(index) << chColon;
			fFormatter  << attributes.getLocalName(index) ;
		}
		else
			fFormatter  << attributes.getQName(index) ;

		fFormatter  << chEqual << chDoubleQuote
                    << XMLFormatter::AttrEscapes
		            << attributes.getValue(index)
                    << XMLFormatter::NoEscapes
                    << chDoubleQuote;
    }
    fFormatter << chCloseAngle;
}
<commit_msg>XMLUni::fgEmptyString which is defined as "EMPTY" is incorrectly used as an empty string, should use XMLUni::fgZeroLenString instead<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache\@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation, and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com .  For more information
 * on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

/*
 * $Log$
 * Revision 1.7  2002/05/28 20:24:15  tng
 * XMLUni::fgEmptyString which is defined as "EMPTY" is incorrectly used as an empty string, should use XMLUni::fgZeroLenString instead
 *
 * Revision 1.6  2002/02/01 22:40:44  peiyongz
 * sane_include
 *
 * Revision 1.5  2001/05/11 13:24:57  tng
 * Copyright update.
 *
 * Revision 1.4  2001/05/03 16:00:03  tng
 * Schema: samples update with schema
 *
 * Revision 1.3  2000/10/10 23:55:53  andyh
 * XMLFormatter patch, contributed by Bill Schindler.  Fix problems with
 * output to multi-byte encodings.
 *
 * Revision 1.2  2000/08/09 22:20:38  jpolast
 * updates for changes to sax2 core functionality.
 *
 * Revision 1.1  2000/08/02 19:16:14  jpolast
 * initial checkin of SAX2Print
 *
 *
 */

// ---------------------------------------------------------------------------
//  Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/sax2/Attributes.hpp>
#include "SAX2Print.hpp"

// ---------------------------------------------------------------------------
//  Local const data
//
//  Note: This is the 'safe' way to do these strings. If you compiler supports
//        L"" style strings, and portability is not a concern, you can use
//        those types constants directly.
// ---------------------------------------------------------------------------
static const XMLCh  gEndElement[] = { chOpenAngle, chForwardSlash, chNull };
static const XMLCh  gEndPI[] = { chQuestion, chCloseAngle, chNull };
static const XMLCh  gStartPI[] = { chOpenAngle, chQuestion, chNull };
static const XMLCh  gXMLDecl1[] =
{
        chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
    ,   chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
    ,   chLatin_o, chLatin_n, chEqual, chDoubleQuote, chDigit_1, chPeriod
    ,   chDigit_0, chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
    ,   chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
    ,   chDoubleQuote, chNull
};

static const XMLCh  gXMLDecl2[] =
{
        chDoubleQuote, chQuestion, chCloseAngle
    ,   chLF, chNull
};

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Constructors and Destructor
// ---------------------------------------------------------------------------
SAX2PrintHandlers::SAX2PrintHandlers( const   char* const              encodingName
                                    , const XMLFormatter::UnRepFlags unRepFlags
									, const bool					 expandNamespaces) :

    fFormatter
    (
        encodingName
        , this
        , XMLFormatter::NoEscapes
        , unRepFlags
    ),
	fExpandNS ( expandNamespaces )
{
    //
    //  Go ahead and output an XML Decl with our known encoding. This
    //  is not the best answer, but its the best we can do until we
    //  have SAX2 support.
    //
    fFormatter << gXMLDecl1 << fFormatter.getEncodingName() << gXMLDecl2;
}

SAX2PrintHandlers::~SAX2PrintHandlers()
{
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the output formatter target interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::writeChars(const XMLByte* const toWrite)
{
}

void SAX2PrintHandlers::writeChars(const XMLByte* const toWrite,
                                   const unsigned int count,
                                   XMLFormatter* const formatter)
{
    // For this one, just dump them to the standard output
    // Surprisingly, Solaris was the only platform on which
    // required the char* cast to print out the string correctly.
    // Without the cast, it was printing the pointer value in hex.
    // Quite annoying, considering every other platform printed
    // the string with the explicit cast to char* below.
  cout.write((char *) toWrite, (int) count);
	cout.flush();
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the SAX ErrorHandler interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::error(const SAXParseException& e)
{
    cerr << "\nError at file " << StrX(e.getSystemId())
		 << ", line " << e.getLineNumber()
		 << ", char " << e.getColumnNumber()
         << "\n  Message: " << StrX(e.getMessage()) << endl;
}

void SAX2PrintHandlers::fatalError(const SAXParseException& e)
{
    cerr << "\nFatal Error at file " << StrX(e.getSystemId())
		 << ", line " << e.getLineNumber()
		 << ", char " << e.getColumnNumber()
         << "\n  Message: " << StrX(e.getMessage()) << endl;
}

void SAX2PrintHandlers::warning(const SAXParseException& e)
{
    cerr << "\nWarning at file " << StrX(e.getSystemId())
		 << ", line " << e.getLineNumber()
		 << ", char " << e.getColumnNumber()
         << "\n  Message: " << StrX(e.getMessage()) << endl;
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the SAX DTDHandler interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::unparsedEntityDecl(const     XMLCh* const name
                                          , const   XMLCh* const publicId
                                          , const   XMLCh* const systemId
                                          , const   XMLCh* const notationName)
{
    // Not used at this time
}

void SAX2PrintHandlers::notationDecl(const   XMLCh* const name
                                    , const XMLCh* const publicId
                                    , const XMLCh* const systemId)
{
    // Not used at this time
}

// ---------------------------------------------------------------------------
//  SAX2PrintHandlers: Overrides of the SAX DocumentHandler interface
// ---------------------------------------------------------------------------
void SAX2PrintHandlers::characters(const     XMLCh* const    chars
                                  , const   unsigned int    length)
{
    fFormatter.formatBuf(chars, length, XMLFormatter::CharEscapes);
}

void SAX2PrintHandlers::endDocument()
{
}

void SAX2PrintHandlers::endElement(const XMLCh* const uri,
								 const XMLCh* const localname,
								 const XMLCh* const qname)
{
    // No escapes are legal here
    fFormatter << XMLFormatter::NoEscapes << gEndElement ;
	if ( fExpandNS )
	{
		if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0)
				fFormatter  << uri << chColon;
		fFormatter << localname << chCloseAngle;
	}
	else
		fFormatter << qname << chCloseAngle;
}

void SAX2PrintHandlers::ignorableWhitespace( const   XMLCh* const chars
                                            ,const  unsigned int length)
{
    fFormatter.formatBuf(chars, length, XMLFormatter::NoEscapes);
}

void SAX2PrintHandlers::processingInstruction(const  XMLCh* const target
                                            , const XMLCh* const data)
{
    fFormatter << XMLFormatter::NoEscapes << gStartPI  << target;
    if (data)
        fFormatter << chSpace << data;
    fFormatter << XMLFormatter::NoEscapes << gEndPI;
}

void SAX2PrintHandlers::startDocument()
{
}

void SAX2PrintHandlers::startElement(const   XMLCh* const    uri,
									const   XMLCh* const    localname,
									const   XMLCh* const    qname,
                                    const   Attributes&		attributes)
{
    // The name has to be representable without any escapes
    fFormatter  << XMLFormatter::NoEscapes << chOpenAngle ;
	if ( fExpandNS )
	{
		if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0)
				fFormatter  << uri << chColon;
		fFormatter << localname ;
	}
	else
		fFormatter << qname ;

    unsigned int len = attributes.getLength();
    for (unsigned int index = 0; index < len; index++)
    {
        //
        //  Again the name has to be completely representable. But the
        //  attribute can have refs and requires the attribute style
        //  escaping.
        //
        fFormatter  << XMLFormatter::NoEscapes << chSpace ;
		if ( fExpandNS )
		{
			if (XMLString::compareIString(attributes.getURI(index),XMLUni::fgZeroLenString) != 0)
				fFormatter  << attributes.getURI(index) << chColon;
			fFormatter  << attributes.getLocalName(index) ;
		}
		else
			fFormatter  << attributes.getQName(index) ;

		fFormatter  << chEqual << chDoubleQuote
                    << XMLFormatter::AttrEscapes
		            << attributes.getValue(index)
                    << XMLFormatter::NoEscapes
                    << chDoubleQuote;
    }
    fFormatter << chCloseAngle;
}
<|endoftext|>


<commit_before>#include <gtest/gtest.h>
#include "TestRequiringOptions.h"

int main(int argc, char** argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    assert(TestRequiringOptions::initFilename("Wangscape/example/example_options.json"));
    return RUN_ALL_TESTS();
}<commit_msg>Get the options file from command line args<commit_after>#include <gtest/gtest.h>
#include "TestRequiringOptions.h"

int main(int argc, char** argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    std::string filename;
    if (argc < 2)
        filename = std::string("Wangscape/example/example_options.json");
    else
        filename = std::string(argv[1]);
    std::cout << "Using options file at " << filename << "\n";
    assert(TestRequiringOptions::initFilename(filename));
    return RUN_ALL_TESTS();
}<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: LayerDialogContent.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 18:33:30 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#include "LayerDialogContent.hxx"

#ifndef _COM_SUN_STAR_PRESENTATION_ANIMATIONEFFECT_HPP_
#include <com/sun/star/presentation/AnimationEffect.hpp>
#endif
#ifndef _COM_SUN_STAR_PRESENTATION_ANIMATIONSPEED_HPP_
#include <com/sun/star/presentation/AnimationSpeed.hpp>
#endif

#define ITEMID_COLOR SID_COLOR_TABLE

#include <svx/gallery.hxx>
#include <svx/colritem.hxx>
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _AEITEM_HXX //autogen
#include <svtools/aeitem.hxx>
#endif
#ifndef _SV_MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif

#include "sdattr.hxx"

#include "LayerDialog.hrc"
#include "app.hrc"
#include "strings.hrc"
#include "res_bmp.hrc"
#include "sdresid.hxx"
#ifndef SD_VIEW_HXX
#include "View.hxx"
#endif
#include "drawdoc.hxx"
#include "PaneManager.hxx"
#include "ViewShellBase.hxx"
#include "DrawViewShell.hxx"

using namespace ::com::sun::star;

namespace sd {

LayerDialogContent::LayerDialogContent (
    SfxBindings* pInBindings,
    SfxChildWindow *pCW,
    Window* pParent,
    const SdResId& rSdResId,
    ViewShellBase& rBase)
    : SfxDockingWindow (pInBindings, pCW, pParent, rSdResId),
      maLayerTabBar (
          static_cast<DrawViewShell*>(
              rBase.GetPaneManager().GetViewShell(PaneManager::PT_CENTER)),
          this,
          SdResId(TB_LAYERS))
{
    FreeResource();

    maLayerTabBar.Show();
}

LayerDialogContent::~LayerDialogContent (void)
{
}

LayerTabBar& LayerDialogContent::GetLayerTabBar (void)
{
    return maLayerTabBar;
}

BOOL LayerDialogContent::Close (void)
{
    return SfxDockingWindow::Close();
}

void LayerDialogContent::Resize (void)
{
    maLayerTabBar.SetPosSizePixel (
        Point(0,0),
        Size(GetSizePixel().Width(), 17));
    SfxDockingWindow::Resize();
}

} // end of namespace sd
<commit_msg>INTEGRATION: CWS components1 (1.3.234); FILE MERGED 2006/09/25 16:56:15 af 1.3.234.2: RESYNC: (1.3-1.4); FILE MERGED 2006/08/22 09:37:29 af 1.3.234.1: #i68075# Transition to new drawing framework.<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: LayerDialogContent.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2007-04-03 15:39:50 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#include "LayerDialogContent.hxx"

#ifndef _COM_SUN_STAR_PRESENTATION_ANIMATIONEFFECT_HPP_
#include <com/sun/star/presentation/AnimationEffect.hpp>
#endif
#ifndef _COM_SUN_STAR_PRESENTATION_ANIMATIONSPEED_HPP_
#include <com/sun/star/presentation/AnimationSpeed.hpp>
#endif

#define ITEMID_COLOR SID_COLOR_TABLE

#include <svx/gallery.hxx>
#include <svx/colritem.hxx>
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _AEITEM_HXX //autogen
#include <svtools/aeitem.hxx>
#endif
#ifndef _SV_MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif

#include "sdattr.hxx"

#include "LayerDialog.hrc"
#include "app.hrc"
#include "strings.hrc"
#include "res_bmp.hrc"
#include "sdresid.hxx"
#ifndef SD_VIEW_HXX
#include "View.hxx"
#endif
#include "drawdoc.hxx"
#include "ViewShellBase.hxx"
#include "DrawViewShell.hxx"
#include "framework/FrameworkHelper.hxx"

using namespace ::com::sun::star;

namespace sd {

LayerDialogContent::LayerDialogContent (
    SfxBindings* pInBindings,
    SfxChildWindow *pCW,
    Window* pParent,
    const SdResId& rSdResId,
    ViewShellBase& rBase)
    : SfxDockingWindow (pInBindings, pCW, pParent, rSdResId),
      maLayerTabBar(
          dynamic_cast<DrawViewShell*>(
              framework::FrameworkHelper::Instance(rBase)->GetViewShell(
                  framework::FrameworkHelper::msCenterPaneURL).get()),
          this,
          SdResId(TB_LAYERS))
{
    FreeResource();

    maLayerTabBar.Show();
}

LayerDialogContent::~LayerDialogContent (void)
{
}

LayerTabBar& LayerDialogContent::GetLayerTabBar (void)
{
    return maLayerTabBar;
}

BOOL LayerDialogContent::Close (void)
{
    return SfxDockingWindow::Close();
}

void LayerDialogContent::Resize (void)
{
    maLayerTabBar.SetPosSizePixel (
        Point(0,0),
        Size(GetSizePixel().Width(), 17));
    SfxDockingWindow::Resize();
}

} // end of namespace sd
<|endoftext|>


<commit_before>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2009, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 *  Author: Siddharth Choudhary (itzsid@gmail.com)
 *
 */

#ifndef PCL_SEARCH_AUTO_TUNED_SEARCH_IMPL
#define PCL_SEARCH_AUTO_TUNED_SEARCH_IMPL

#include <pcl/pcl_base.h>
#include <vector>
#include "pcl/search/auto.h"
#include "pcl/search/kdtree.h"
#include "pcl/search/octree.h"
#include "pcl/search/organized_neighbor.h"
#include <pcl/common/time.h>

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::initSearchDS (int spatial_locator)
{
  // specifies the data-structure to be used using spatial_locator flag
  if (spatial_locator == KDTREE)
    // initialize kdtree
    search_.reset (new KdTree<PointT> ());
  else if (spatial_locator == ORGANIZED_INDEX)
    search_.reset (new OrganizedNeighbor<PointT> ());
  else if (spatial_locator == OCTREE)
    search_.reset (new Octree<PointT> (0.1f));
  else
    PCL_ERROR ("[pcl::search::AutotunedSearch::initSearchDS] Spatial locator (%d) unknown!\n", spatial_locator);
   spatial_loc_ = spatial_locator;
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::evaluateSearchMethods (const PointCloudConstPtr& cloud, const int search_type)
{
  // Evaluates different search data-structures for the given data and sets it to the ds having minimum time
	unsigned int searchIdx;
  while (1)
  {
    searchIdx = rand()%(cloud->width * cloud->height);
    if (cloud->points[searchIdx].z < 100)
      break;
   }

  double time_kdtree, time_octree, time_organized_data;
  if (search_type == NEAREST_K_SEARCH)
  {
    unsigned int no_of_neighbors = 20;
    std::vector<int> k_indices;
    k_indices.resize (no_of_neighbors);
    std::vector<float> k_distances;
    k_distances.resize (no_of_neighbors);
    std::cout << "\n---------------\nKDTree\n---------------\n";
    double time1 = getTime ();
    search_.reset (new KdTree<PointT> ());
    search_->setInputCloud (cloud);
    search_->nearestKSearch (cloud->points[searchIdx], no_of_neighbors, k_indices, k_distances);
    std::cout << "Neighbors are:" << std::endl;
    for (int i = 0; i < 20; i++)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOrganizedData\n---------------\n";
    double time2 = getTime ();
    search_.reset (new OrganizedNeighbor<PointT>());
    search_->setInputCloud (cloud);
    search_->nearestKSearch (cloud->points[searchIdx], no_of_neighbors, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0;i < 20; i++)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neigbhors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOctree\n---------------\n";
    double time3 = getTime ();
    search_.reset (new Octree<PointT> (0.1f));
    search_->setInputCloud (cloud);
    search_->nearestKSearch (cloud->points[searchIdx], no_of_neighbors, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0;i < 20; i++)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();
    std::cout << std::endl;
    std::cout << std::endl;

    time_kdtree = time2 - time1;
    time_organized_data = time3 - time2;
    time_octree = getTime () - time3;

    std::cout << "Time Taken: " << "KDTree: " << time_kdtree << '\t' <<"OranizedData: "  << time_organized_data << '\t' << "Octree: " << time_octree << '\t' << std::endl;
  }
  else if (search_type == NEAREST_RADIUS_SEARCH)
  {
    double searchRadius = 1.0 * ((double)rand () / (double)RAND_MAX);

    std::vector<int> k_indices;
    std::vector<float> k_distances;
    std::cout << "\n---------------\nKDTree\n---------------\n";
    double time1 = getTime ();
    search_.reset (new KdTree<PointT> ());
    search_->setInputCloud (cloud);
    search_->radiusSearch (cloud->points[searchIdx], searchRadius, k_indices, k_distances);
    std::cout << "Neighbors are:" << std::endl;

    for(int i = 0;i < 20; ++i)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOrganizedData\n---------------\n";
    double time2 = getTime ();
    search_.reset (new OrganizedNeighbor<PointT> ());
    search_->setInputCloud (cloud);
    search_->radiusSearch (cloud->points[searchIdx], searchRadius, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0; i < 20; ++i)
    {
    std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neigbhors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOctree\n---------------\n";
    double time3 = getTime ();
    search_.reset (new Octree<PointT> (0.1f));
    search_->setInputCloud (cloud);
    search_->radiusSearch (cloud->points[searchIdx], searchRadius, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0; i < 20; ++i)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();
    std::cout << std::endl;
    std::cout << std::endl;

    time_kdtree = time2 - time1;
    time_organized_data = time3 - time2;
    time_octree = getTime () - time3;

    std::cout << "Time Taken: " << "KDTree: " << time_kdtree << '\t' <<"OranizedData: "  << time_organized_data << '\t' << "Octree: " << time_octree << '\t' << std::endl;
  }
  else
  {
    PCL_ERROR ("[pcl::search::AutotunedSearch::evaluateSearchMethods] Only NEAREST_K_SEARCH and NEAREST_RADIUS_SEARCH supported\n");
    return (0);
  }
  // Set the datastructure according to which takes the minimum time
  if (time_kdtree < time_organized_data && time_kdtree < time_octree)
  {
    spatial_loc_ = KDTREE;
    search_.reset (new KdTree<PointT> ());
  }
  else if (time_octree < time_kdtree && time_octree < time_organized_data)
  {
    spatial_loc_ = OCTREE;
    search_.reset (new Octree<PointT> (0.1f));
  }
  else if (time_organized_data < time_kdtree && time_organized_data < time_octree)
  {
    spatial_loc_ = OCTREE;
    search_.reset (new OrganizedNeighbor<PointT> ());
  }
//  search_->setInputCloud (cloud);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::setInputCloud (const PointCloudConstPtr &cloud,
                                             const IndicesConstPtr &indices)
{
  input_ = cloud;
  search_->setInputCloud (cloud, indices);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::setInputCloud (const PointCloudConstPtr& cloud)
{
  input_ = cloud;
  search_->setInputCloud (cloud);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::nearestKSearch (const PointT &point,
                                              int k,
                                              std::vector<int> &k_indices,
                                              std::vector<float> &k_sqr_distances)
{
  return (search_->nearestKSearch (point, k, k_indices, k_sqr_distances));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::nearestKSearch (const PointCloud &cloud,
                                              int index,
                                              int k,
                                              std::vector<int> &k_indices,
                                              std::vector<float> &k_sqr_distances)
{
  return (search_->nearestKSearch (cloud, index, k, k_indices, k_sqr_distances));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::nearestKSearch (int index,
                                              int k,
                                              std::vector<int> &k_indices,
                                              std::vector<float> &k_sqr_distances)
{
  return (search_->nearestKSearch (index, k, k_indices, k_sqr_distances));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::radiusSearch (const PointT &point,
                                            const double radius,
                                            std::vector<int> &k_indices,
                                            std::vector<float> &k_distances,
                                            int max_nn) const
{
  return (search_->radiusSearch (point, radius, k_indices, k_distances, max_nn));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::radiusSearch (const PointCloud &cloud,
                                            int index,
                                            double radius,
                                            std::vector<int> &k_indices,
                                            std::vector<float> &k_distances,
                                            int max_nn)
{
  return (search_->radiusSearch (cloud, index, radius, k_indices, k_distances, max_nn));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::radiusSearch (int index,
                                            double radius,
                                            std::vector<int> &k_indices,
                                            std::vector<float> &k_distances,
                                            int max_nn) const
{
  return (search_->radiusSearch (index, radius, k_indices, k_distances, max_nn));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::approxNearestSearch (const PointCloudConstPtr &cloud_arg,
                                                   int query_index_arg,
                                                   int &result_index_arg,
                                                   float &sqr_distance_arg)
{
  if(spatial_loc_ == OCTREE)
    search_->approxNearestSearch (cloud_arg, query_index_arg, result_index_arg, sqr_distance_arg);
  else
    PCL_ERROR ("approxNearestSearch() works only for OCTREE structure\n");
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::approxNearestSearch (const PointT &p_q_arg,
                                                   int &result_index_arg,
                                                   float &sqr_distance_arg)
{
  if (spatial_loc_ == OCTREE)
    search_->approxNearestSearch (p_q_arg, result_index_arg, sqr_distance_arg);
  else
    PCL_ERROR ("approxNearestSearch() works only for OCTREE structure\n");
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::approxNearestSearch (int query_index_arg,
                                                   int &result_index_arg,
                                                   float &sqr_distance_arg)
{
  if (spatial_loc_ == OCTREE)
   search_->approxNearestSearch (query_index_arg, result_index_arg, sqr_distance_arg);
  else
    PCL_ERROR ("approxNearestSearch() works only for OCTREE structure\n");
}

#define PCL_INSTANTIATE_AutotunedSearch(T) template class PCL_EXPORTS pcl::search::AutotunedSearch<T>;

#endif  //#ifndef PCL_SEARCH_AUTO_TUNED_SEARCH_IMPL
<commit_msg>Fixing  return-statement with a value, in function returning `void'.<commit_after>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2009, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 *  Author: Siddharth Choudhary (itzsid@gmail.com)
 *
 */

#ifndef PCL_SEARCH_AUTO_TUNED_SEARCH_IMPL
#define PCL_SEARCH_AUTO_TUNED_SEARCH_IMPL

#include <pcl/pcl_base.h>
#include <vector>
#include "pcl/search/auto.h"
#include "pcl/search/kdtree.h"
#include "pcl/search/octree.h"
#include "pcl/search/organized_neighbor.h"
#include <pcl/common/time.h>

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::initSearchDS (int spatial_locator)
{
  // specifies the data-structure to be used using spatial_locator flag
  if (spatial_locator == KDTREE)
    // initialize kdtree
    search_.reset (new KdTree<PointT> ());
  else if (spatial_locator == ORGANIZED_INDEX)
    search_.reset (new OrganizedNeighbor<PointT> ());
  else if (spatial_locator == OCTREE)
    search_.reset (new Octree<PointT> (0.1f));
  else
    PCL_ERROR ("[pcl::search::AutotunedSearch::initSearchDS] Spatial locator (%d) unknown!\n", spatial_locator);
   spatial_loc_ = spatial_locator;
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::evaluateSearchMethods (const PointCloudConstPtr& cloud, const int search_type)
{
  // Evaluates different search data-structures for the given data and sets it to the ds having minimum time
	unsigned int searchIdx;
  while (1)
  {
    searchIdx = rand()%(cloud->width * cloud->height);
    if (cloud->points[searchIdx].z < 100)
      break;
   }

  double time_kdtree, time_octree, time_organized_data;
  if (search_type == NEAREST_K_SEARCH)
  {
    unsigned int no_of_neighbors = 20;
    std::vector<int> k_indices;
    k_indices.resize (no_of_neighbors);
    std::vector<float> k_distances;
    k_distances.resize (no_of_neighbors);
    std::cout << "\n---------------\nKDTree\n---------------\n";
    double time1 = getTime ();
    search_.reset (new KdTree<PointT> ());
    search_->setInputCloud (cloud);
    search_->nearestKSearch (cloud->points[searchIdx], no_of_neighbors, k_indices, k_distances);
    std::cout << "Neighbors are:" << std::endl;
    for (int i = 0; i < 20; i++)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOrganizedData\n---------------\n";
    double time2 = getTime ();
    search_.reset (new OrganizedNeighbor<PointT>());
    search_->setInputCloud (cloud);
    search_->nearestKSearch (cloud->points[searchIdx], no_of_neighbors, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0;i < 20; i++)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neigbhors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOctree\n---------------\n";
    double time3 = getTime ();
    search_.reset (new Octree<PointT> (0.1f));
    search_->setInputCloud (cloud);
    search_->nearestKSearch (cloud->points[searchIdx], no_of_neighbors, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0;i < 20; i++)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();
    std::cout << std::endl;
    std::cout << std::endl;

    time_kdtree = time2 - time1;
    time_organized_data = time3 - time2;
    time_octree = getTime () - time3;

    std::cout << "Time Taken: " << "KDTree: " << time_kdtree << '\t' <<"OranizedData: "  << time_organized_data << '\t' << "Octree: " << time_octree << '\t' << std::endl;
  }
  else if (search_type == NEAREST_RADIUS_SEARCH)
  {
    double searchRadius = 1.0 * ((double)rand () / (double)RAND_MAX);

    std::vector<int> k_indices;
    std::vector<float> k_distances;
    std::cout << "\n---------------\nKDTree\n---------------\n";
    double time1 = getTime ();
    search_.reset (new KdTree<PointT> ());
    search_->setInputCloud (cloud);
    search_->radiusSearch (cloud->points[searchIdx], searchRadius, k_indices, k_distances);
    std::cout << "Neighbors are:" << std::endl;

    for(int i = 0;i < 20; ++i)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOrganizedData\n---------------\n";
    double time2 = getTime ();
    search_.reset (new OrganizedNeighbor<PointT> ());
    search_->setInputCloud (cloud);
    search_->radiusSearch (cloud->points[searchIdx], searchRadius, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0; i < 20; ++i)
    {
    std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neigbhors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();

    std::cout << "\n---------------\nOctree\n---------------\n";
    double time3 = getTime ();
    search_.reset (new Octree<PointT> (0.1f));
    search_->setInputCloud (cloud);
    search_->radiusSearch (cloud->points[searchIdx], searchRadius, k_indices, k_distances);
    std::cout << "Neighbors are: " << std::endl;
    for (int i = 0; i < 20; ++i)
    {
      std::cout << k_indices[i] << '\t';
    }
    std::cout << std::endl;
    std::cout << "Number of Neighbors: " << k_indices.size () << std::endl;
    k_indices.clear (); k_distances.clear ();
    std::cout << std::endl;
    std::cout << std::endl;

    time_kdtree = time2 - time1;
    time_organized_data = time3 - time2;
    time_octree = getTime () - time3;

    std::cout << "Time Taken: " << "KDTree: " << time_kdtree << '\t' <<"OranizedData: "  << time_organized_data << '\t' << "Octree: " << time_octree << '\t' << std::endl;
  }
  else
  {
    PCL_ERROR ("[pcl::search::AutotunedSearch::evaluateSearchMethods] Only NEAREST_K_SEARCH and NEAREST_RADIUS_SEARCH supported\n");
    return;
  }
  // Set the datastructure according to which takes the minimum time
  if (time_kdtree < time_organized_data && time_kdtree < time_octree)
  {
    spatial_loc_ = KDTREE;
    search_.reset (new KdTree<PointT> ());
  }
  else if (time_octree < time_kdtree && time_octree < time_organized_data)
  {
    spatial_loc_ = OCTREE;
    search_.reset (new Octree<PointT> (0.1f));
  }
  else if (time_organized_data < time_kdtree && time_organized_data < time_octree)
  {
    spatial_loc_ = OCTREE;
    search_.reset (new OrganizedNeighbor<PointT> ());
  }
//  search_->setInputCloud (cloud);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::setInputCloud (const PointCloudConstPtr &cloud,
                                             const IndicesConstPtr &indices)
{
  input_ = cloud;
  search_->setInputCloud (cloud, indices);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::setInputCloud (const PointCloudConstPtr& cloud)
{
  input_ = cloud;
  search_->setInputCloud (cloud);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::nearestKSearch (const PointT &point,
                                              int k,
                                              std::vector<int> &k_indices,
                                              std::vector<float> &k_sqr_distances)
{
  return (search_->nearestKSearch (point, k, k_indices, k_sqr_distances));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::nearestKSearch (const PointCloud &cloud,
                                              int index,
                                              int k,
                                              std::vector<int> &k_indices,
                                              std::vector<float> &k_sqr_distances)
{
  return (search_->nearestKSearch (cloud, index, k, k_indices, k_sqr_distances));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::nearestKSearch (int index,
                                              int k,
                                              std::vector<int> &k_indices,
                                              std::vector<float> &k_sqr_distances)
{
  return (search_->nearestKSearch (index, k, k_indices, k_sqr_distances));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::radiusSearch (const PointT &point,
                                            const double radius,
                                            std::vector<int> &k_indices,
                                            std::vector<float> &k_distances,
                                            int max_nn) const
{
  return (search_->radiusSearch (point, radius, k_indices, k_distances, max_nn));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::radiusSearch (const PointCloud &cloud,
                                            int index,
                                            double radius,
                                            std::vector<int> &k_indices,
                                            std::vector<float> &k_distances,
                                            int max_nn)
{
  return (search_->radiusSearch (cloud, index, radius, k_indices, k_distances, max_nn));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> int
pcl::search::AutotunedSearch<PointT>::radiusSearch (int index,
                                            double radius,
                                            std::vector<int> &k_indices,
                                            std::vector<float> &k_distances,
                                            int max_nn) const
{
  return (search_->radiusSearch (index, radius, k_indices, k_distances, max_nn));
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::approxNearestSearch (const PointCloudConstPtr &cloud_arg,
                                                   int query_index_arg,
                                                   int &result_index_arg,
                                                   float &sqr_distance_arg)
{
  if(spatial_loc_ == OCTREE)
    search_->approxNearestSearch (cloud_arg, query_index_arg, result_index_arg, sqr_distance_arg);
  else
    PCL_ERROR ("approxNearestSearch() works only for OCTREE structure\n");
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::approxNearestSearch (const PointT &p_q_arg,
                                                   int &result_index_arg,
                                                   float &sqr_distance_arg)
{
  if (spatial_loc_ == OCTREE)
    search_->approxNearestSearch (p_q_arg, result_index_arg, sqr_distance_arg);
  else
    PCL_ERROR ("approxNearestSearch() works only for OCTREE structure\n");
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::search::AutotunedSearch<PointT>::approxNearestSearch (int query_index_arg,
                                                   int &result_index_arg,
                                                   float &sqr_distance_arg)
{
  if (spatial_loc_ == OCTREE)
   search_->approxNearestSearch (query_index_arg, result_index_arg, sqr_distance_arg);
  else
    PCL_ERROR ("approxNearestSearch() works only for OCTREE structure\n");
}

#define PCL_INSTANTIATE_AutotunedSearch(T) template class PCL_EXPORTS pcl::search::AutotunedSearch<T>;

#endif  //#ifndef PCL_SEARCH_AUTO_TUNED_SEARCH_IMPL
<|endoftext|>