<commit_before>#include "test_helper.h"
#include "uTensor/loaders/tensorIdxImporter.hpp"
#include "MatrixOps.hpp"

#include <iostream>
using std::cout;
using std::endl;

TensorIdxImporter t_import;
Context ctx;

void test_operators_fusedConvMaxpool12(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_input.idx"), "x_1_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_weights.idx"), "w_1_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size2_output.idx"), "ref_1_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },VALID),
            { "x_1_2", "w_1_2"}, {"out_1_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool13(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_input.idx"), "x_1_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_weights.idx"), "w_1_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size3_output.idx"), "ref_1_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },VALID),
            { "x_1_3", "w_1_3"}, {"out_1_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool14(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_input.idx"), "x_1_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_weights.idx"), "w_1_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size4_output.idx"), "ref_1_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },VALID),
            { "x_1_4", "w_1_4"}, {"out_1_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool22(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_input.idx"), "x_2_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_weights.idx"), "w_2_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size2_output.idx"), "ref_2_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },VALID),
            { "x_2_2", "w_2_2"}, {"out_2_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool23(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_input.idx"), "x_2_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_weights.idx"), "w_2_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size3_output.idx"), "ref_2_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },VALID),
            { "x_2_3", "w_2_3"}, {"out_2_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool24(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_input.idx"), "x_2_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_weights.idx"), "w_2_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size4_output.idx"), "ref_2_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },VALID),
            { "x_2_4", "w_2_4"}, {"out_2_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool32(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_input.idx"), "x_3_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_weights.idx"), "w_3_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size2_output.idx"), "ref_3_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },VALID),
            { "x_3_2", "w_3_2"}, {"out_3_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool33(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_input.idx"), "x_3_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_weights.idx"), "w_3_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size3_output.idx"), "ref_3_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },VALID),
            { "x_3_3", "w_3_3"}, {"out_3_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool34(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_input.idx"), "x_3_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_weights.idx"), "w_3_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size4_output.idx"), "ref_3_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },VALID),
            { "x_3_4", "w_3_4"}, {"out_3_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}

// First configure the uTensor test runner
UTENSOR_TEST_CONFIGURE()

// Second declare tests to run
UTENSOR_TEST(operators, fusedConvMaxpool12, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool13, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool14, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool22, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool23, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool24, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool32, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool33, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool34, "Generated Fused Conv Maxpool test")

// Third, run like hell
UTENSOR_TEST_RUN()

<commit_msg>Change to SAME padding<commit_after>#include "test_helper.h"
#include "uTensor/loaders/tensorIdxImporter.hpp"
#include "MatrixOps.hpp"

#include <iostream>
using std::cout;
using std::endl;

TensorIdxImporter t_import;
Context ctx;

void test_operators_fusedConvMaxpool12(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_input.idx"), "x_1_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_weights.idx"), "w_1_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size2_output.idx"), "ref_1_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },SAME),
            { "x_1_2", "w_1_2"}, {"out_1_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool13(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_input.idx"), "x_1_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_weights.idx"), "w_1_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size3_output.idx"), "ref_1_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },SAME),
            { "x_1_3", "w_1_3"}, {"out_1_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool14(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_input.idx"), "x_1_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_weights.idx"), "w_1_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size4_output.idx"), "ref_1_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },SAME),
            { "x_1_4", "w_1_4"}, {"out_1_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool22(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_input.idx"), "x_2_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_weights.idx"), "w_2_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size2_output.idx"), "ref_2_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },SAME),
            { "x_2_2", "w_2_2"}, {"out_2_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool23(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_input.idx"), "x_2_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_weights.idx"), "w_2_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size3_output.idx"), "ref_2_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },SAME),
            { "x_2_3", "w_2_3"}, {"out_2_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool24(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_input.idx"), "x_2_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_weights.idx"), "w_2_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size4_output.idx"), "ref_2_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },SAME),
            { "x_2_4", "w_2_4"}, {"out_2_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool32(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_input.idx"), "x_3_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_weights.idx"), "w_3_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size2_output.idx"), "ref_3_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },SAME),
            { "x_3_2", "w_3_2"}, {"out_3_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool33(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_input.idx"), "x_3_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_weights.idx"), "w_3_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size3_output.idx"), "ref_3_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },SAME),
            { "x_3_3", "w_3_3"}, {"out_3_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool34(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_input.idx"), "x_3_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_weights.idx"), "w_3_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size4_output.idx"), "ref_3_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },SAME),
            { "x_3_4", "w_3_4"}, {"out_3_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}

// First configure the uTensor test runner
UTENSOR_TEST_CONFIGURE()

// Second declare tests to run
UTENSOR_TEST(operators, fusedConvMaxpool12, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool13, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool14, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool22, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool23, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool24, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool32, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool33, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool34, "Generated Fused Conv Maxpool test")

// Third, run like hell
UTENSOR_TEST_RUN()

<|endoftext|>


<commit_before>/*
* Copyright 2017 - KBC Group NV - Franky Braem - The MIT license
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
*  copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "MQ/Web/ChannelRemove.h"

namespace MQ {
namespace Web {

ChannelRemove::ChannelRemove(CommandServer& commandServer, Poco::JSON::Object::Ptr input)
: PCFSimpleCommand(commandServer, MQCMD_DELETE_CHANNEL, "Channel", input)
{
	// Required Parameters
	addParameter<std::string>(MQCACH_CHANNEL_NAME, "ChannelName");

	// Optional Parameters
	addParameter<std::string>(MQCACF_COMMAND_SCOPE, "CommandScope");
	addParameterNumFromString(MQIACH_CHANNEL_TABLE, "ChannelTable");
	addParameterNumFromString(MQIA_QSG_DISP, "QSGDisposition");
	addParameterNumFromString(MQIACH_CHANNEL_TYPE, "ChannelType");
}

ChannelRemove::~ChannelRemove()
{
}

}} //  Namespace MQ::Web
<commit_msg>Use a TextMap for ChannelTable<commit_after>/*
* Copyright 2017 - KBC Group NV - Franky Braem - The MIT license
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
*  copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "MQ/Web/ChannelRemove.h"

namespace MQ {
namespace Web {

ChannelRemove::ChannelRemove(CommandServer& commandServer, Poco::JSON::Object::Ptr input)
: PCFSimpleCommand(commandServer, MQCMD_DELETE_CHANNEL, "Channel", input)
{
	// Required Parameters
	addParameter<std::string>(MQCACH_CHANNEL_NAME, "ChannelName");

	// Optional Parameters
	addParameter<std::string>(MQCACF_COMMAND_SCOPE, "CommandScope");
	static TextMap channelTableMap = TextMapInitializer
		(MQCHTAB_Q_MGR, "QMgr")
		(MQCHTAB_CLNTCONN, "Client-connection")
	;
	std::string channelTable = input->get("ChannelTable");
	for (TextMap::const_iterator it = channelTableMap.begin(); it != channelTableMap.end(); ++it)
	{
		if (it->second.compare(channelTable) == 0) {
			pcf()->addParameter(MQIACH_CHANNEL_TABLE, it->first);
		}
	}
	addParameterNumFromString(MQIA_QSG_DISP, "QSGDisposition");
	addParameterNumFromString(MQIACH_CHANNEL_TYPE, "ChannelType");
}

ChannelRemove::~ChannelRemove()
{
}

}} //  Namespace MQ::Web
<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLPStructuredDataReader.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLPStructuredDataReader.h"

#include "vtkDataArray.h"
#include "vtkDataSet.h"
#include "vtkExtentSplitter.h"
#include "vtkTableExtentTranslator.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLStructuredDataReader.h"

vtkCxxRevisionMacro(vtkXMLPStructuredDataReader, "1.9.2.1");

//----------------------------------------------------------------------------
vtkXMLPStructuredDataReader::vtkXMLPStructuredDataReader()
{
  this->ExtentTranslator = vtkTableExtentTranslator::New();
  this->ExtentSplitter = vtkExtentSplitter::New();
  this->PieceExtents = 0;
}

//----------------------------------------------------------------------------
vtkXMLPStructuredDataReader::~vtkXMLPStructuredDataReader()
{
  if(this->NumberOfPieces) { this->DestroyPieces(); }
  this->ExtentSplitter->Delete();
  this->ExtentTranslator->Delete();
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

//----------------------------------------------------------------------------
vtkExtentTranslator* vtkXMLPStructuredDataReader::GetExtentTranslator()
{
  return this->ExtentTranslator;
}

//----------------------------------------------------------------------------
vtkIdType vtkXMLPStructuredDataReader::GetNumberOfPoints()
{
  return (this->PointDimensions[0]*
          this->PointDimensions[1]*
          this->PointDimensions[2]);
}

//----------------------------------------------------------------------------
vtkIdType vtkXMLPStructuredDataReader::GetNumberOfCells()
{
  return (this->CellDimensions[0]*
          this->CellDimensions[1]*
          this->CellDimensions[2]);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::ReadXMLData()
{
  // Get the requested Update Extent.
  this->GetOutputAsDataSet(0)->GetUpdateExtent(this->UpdateExtent);

  vtkDebugMacro("Updating extent "
                << this->UpdateExtent[0] << " " << this->UpdateExtent[1] << " "
                << this->UpdateExtent[2] << " " << this->UpdateExtent[3] << " "
                << this->UpdateExtent[4] << " " << this->UpdateExtent[5]
                << "\n");

  // Prepare increments for the update extent.
  this->ComputeDimensions(this->UpdateExtent, this->PointDimensions, 1);
  this->ComputeIncrements(this->UpdateExtent, this->PointIncrements, 1);
  this->ComputeDimensions(this->UpdateExtent, this->CellDimensions, 0);
  this->ComputeIncrements(this->UpdateExtent, this->CellIncrements, 0);

  // Let superclasses read data.  This also allocates output data.
  this->Superclass::ReadXMLData();

  // Use the ExtentSplitter to split the update extent into
  // sub-extents read by each piece.
  if(!this->ComputePieceSubExtents())
    {
    // Not all needed data are available.
    this->DataError = 1;
    return;
    }

  // Split current progress range based on fraction contributed by
  // each sub-extent.
  float progressRange[2] = {0,0};
  this->GetProgressRange(progressRange);

  // Calculate the cumulative fraction of data contributed by each
  // sub-extent (for progress).
  int n = this->ExtentSplitter->GetNumberOfSubExtents();
  float* fractions = new float[n+1];
  int i;
  fractions[0] = 0;
  for(i=0;i < n;++i)
    {
    // Get this sub-extent.
    this->ExtentSplitter->GetSubExtent(i, this->SubExtent);

    // Add this sub-extent's volume to the cumulative volume.
    int pieceDims[3] = {0,0,0};
    this->ComputeDimensions(this->SubExtent, pieceDims, 1);
    fractions[i+1] = fractions[i] + pieceDims[0]*pieceDims[1]*pieceDims[2];
    }
  if(fractions[n] == 0)
    {
    fractions[n] = 1;
    }
  for(i=1;i <= n;++i)
    {
    fractions[i] = fractions[i] / fractions[n];
    }

  // Read the data needed from each sub-extent.
  for(i=0;(i < n && !this->AbortExecute && !this->DataError);++i)
    {
    // Set the range of progress for this sub-extent.
    this->SetProgressRange(progressRange, i, fractions);

    // Get this sub-extent and the piece from which to read it.
    int piece = this->ExtentSplitter->GetSubExtentSource(i);
    this->ExtentSplitter->GetSubExtent(i, this->SubExtent);

    vtkDebugMacro("Reading extent "
                  << this->SubExtent[0] << " " << this->SubExtent[1] << " "
                  << this->SubExtent[2] << " " << this->SubExtent[3] << " "
                  << this->SubExtent[4] << " " << this->SubExtent[5]
                  << " from piece " << piece);

    this->ComputeDimensions(this->SubExtent, this->SubPointDimensions, 1);
    this->ComputeDimensions(this->SubExtent, this->SubCellDimensions, 0);

    // Read the data from this piece.
    if(!this->Superclass::ReadPieceData(piece))
      {
      // An error occurred while reading the piece.
      this->DataError = 1;
      }
    }

  delete [] fractions;

  // We filled the exact update extent in the output.
  this->SetOutputExtent(this->UpdateExtent);
}

//----------------------------------------------------------------------------
int
vtkXMLPStructuredDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
{
  if(!this->Superclass::ReadPrimaryElement(ePrimary)) { return 0; }
  vtkDataSet* output = this->GetOutputAsDataSet(0);

  // Read information about the structured data.
  int extent[6];
  if(ePrimary->GetVectorAttribute("WholeExtent", 6, extent) < 6)
    {
    vtkErrorMacro(<< this->GetDataSetName()
                  << " element has no WholeExtent.");
    return 0;
    }
  output->SetWholeExtent(extent);

  return 1;
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::SetupOutputInformation()
{
  this->Superclass::SetupOutputInformation();

  // Tell the output to use the table extent translator to provide the
  // correct piece breakdown for the file layout.
  this->GetOutputAsDataSet(0)->SetExtentTranslator(this->ExtentTranslator);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::SetupEmptyOutput()
{
  // Special extent to indicate no input.
  this->GetOutputAsDataSet(0)->SetUpdateExtent(1, 0, 1, 0, 1, 0);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::SetupPieces(int numPieces)
{
  this->Superclass::SetupPieces(numPieces);
  this->ExtentTranslator->SetNumberOfPieces(this->NumberOfPieces);
  this->ExtentTranslator->SetMaximumGhostLevel(this->GhostLevel);
  this->PieceExtents = new int[6*this->NumberOfPieces];
  int i;
  for(i=0;i < this->NumberOfPieces;++i)
    {
    int* extent = this->PieceExtents+i*6;
    extent[0] = 0; extent[1] = -1;
    extent[2] = 0; extent[3] = -1;
    extent[4] = 0; extent[5] = -1;
    }
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::DestroyPieces()
{
  delete [] this->PieceExtents;
  this->PieceExtents = 0;
  this->Superclass::DestroyPieces();
}

//----------------------------------------------------------------------------
int vtkXMLPStructuredDataReader::ReadPiece(vtkXMLDataElement* ePiece)
{
  // Superclass will create a reader for the piece's file.
  if(!this->Superclass::ReadPiece(ePiece)) { return 0; }

  // Get the extent of the piece.
  int* pieceExtent = this->PieceExtents+this->Piece*6;
  if(ePiece->GetVectorAttribute("Extent", 6, pieceExtent) < 6)
    {
    vtkErrorMacro("Piece " << this->Piece << " has invalid Extent.");
    return 0;
    }

  // Set this table entry in the extent translator.
  this->ExtentTranslator->SetExtentForPiece(this->Piece, pieceExtent);
  this->ExtentTranslator->SetPieceAvailable(this->Piece,
                                            this->CanReadPiece(this->Piece));

  return 1;
}

//----------------------------------------------------------------------------
int vtkXMLPStructuredDataReader::ReadPieceData()
{
  // Use the internal reader to read the piece.
  vtkDataSet* input = this->GetPieceInputAsDataSet(this->Piece);
  input->SetUpdateExtent(this->SubExtent);
  input->Update();

  // Skip rest of read if aborting.
  if(this->AbortExecute)
    {
    return 0;
    }

  // Get the actual portion of the piece that was read.
  this->GetPieceInputExtent(this->Piece, this->SubPieceExtent);
  this->ComputeDimensions(this->SubPieceExtent,
                          this->SubPiecePointDimensions, 1);
  this->ComputeIncrements(this->SubPieceExtent,
                          this->SubPiecePointIncrements, 1);
  this->ComputeDimensions(this->SubPieceExtent,
                          this->SubPieceCellDimensions, 0);
  this->ComputeIncrements(this->SubPieceExtent,
                          this->SubPieceCellIncrements, 0);

  // Let the superclass read the data it wants.
  return this->Superclass::ReadPieceData();
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::CopyArrayForPoints(vtkDataArray* inArray,
                                                     vtkDataArray* outArray)
{
  if(!inArray || !outArray)
    {
    return;
    }
  this->CopySubExtent(this->SubPieceExtent,
                      this->SubPiecePointDimensions,
                      this->SubPiecePointIncrements,
                      this->UpdateExtent, this->PointDimensions,
                      this->PointIncrements, this->SubExtent,
                      this->SubPointDimensions, inArray, outArray);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::CopyArrayForCells(vtkDataArray* inArray,
                                                    vtkDataArray* outArray)
{
  if(!inArray || !outArray)
    {
    return;
    }
  this->CopySubExtent(this->SubPieceExtent,
                      this->SubPieceCellDimensions,
                      this->SubPieceCellIncrements,
                      this->UpdateExtent, this->CellDimensions,
                      this->CellIncrements, this->SubExtent,
                      this->SubCellDimensions, inArray, outArray);
}

//----------------------------------------------------------------------------
void
vtkXMLPStructuredDataReader
::CopySubExtent(int* inExtent, int* inDimensions, int* inIncrements,
                int* outExtent, int* outDimensions, int* outIncrements,
                int* subExtent, int* subDimensions,
                vtkDataArray* inArray, vtkDataArray* outArray)
{
  unsigned int components = inArray->GetNumberOfComponents();
  unsigned int tupleSize = inArray->GetDataTypeSize()*components;

  if((inDimensions[0] == outDimensions[0]) &&
     (inDimensions[1] == outDimensions[1]))
    {
    if(inDimensions[2] == outDimensions[2])
      {
      // Copy the whole volume at once.
      unsigned int volumeTuples = (inDimensions[0]*
                                   inDimensions[1]*
                                   inDimensions[2]);
      memcpy(outArray->GetVoidPointer(0), inArray->GetVoidPointer(0),
             volumeTuples*tupleSize);
      }
    else
      {
      // Copy an entire slice at a time.
      unsigned int sliceTuples = inDimensions[0]*inDimensions[1];
      int k;
      for(k=0;k < subDimensions[2];++k)
        {
        unsigned int sourceTuple = this->GetStartTuple(inExtent, inIncrements,
                                                       subExtent[0],
                                                       subExtent[2],
                                                       subExtent[4]+k);
        unsigned int destTuple = this->GetStartTuple(outExtent, outIncrements,
                                                     subExtent[0],
                                                     subExtent[2],
                                                     subExtent[4]+k);
        memcpy(outArray->GetVoidPointer(destTuple*components),
               inArray->GetVoidPointer(sourceTuple*components),
               sliceTuples*tupleSize);
        }
      }
    }
  else
    {
    // Copy a row at a time.
    unsigned int rowTuples = subDimensions[0];
    int j,k;
    for(k=0;k < subDimensions[2];++k)
      {
      for(j=0;j < subDimensions[1];++j)
        {
        unsigned int sourceTuple = this->GetStartTuple(inExtent, inIncrements,
                                                       subExtent[0],
                                                       subExtent[2]+j,
                                                       subExtent[4]+k);
        unsigned int destTuple = this->GetStartTuple(outExtent, outIncrements,
                                                     subExtent[0],
                                                     subExtent[2]+j,
                                                     subExtent[4]+k);
        memcpy(outArray->GetVoidPointer(destTuple*components),
               inArray->GetVoidPointer(sourceTuple*components),
               rowTuples*tupleSize);
        }
      }
    }
}

//----------------------------------------------------------------------------
int vtkXMLPStructuredDataReader::ComputePieceSubExtents()
{
  // Reset the extent splitter.
  this->ExtentSplitter->RemoveAllExtentSources();

  // Add each readable piece as an extent source.
  int i;
  for(i=0;i < this->NumberOfPieces;++i)
    {
    if(this->CanReadPiece(i))
      {
      this->ExtentSplitter->AddExtentSource(i, 0, this->PieceExtents + i*6);
      }
    }

  // We want to split the entire update extent across the pieces.
  this->ExtentSplitter->AddExtent(this->UpdateExtent);

  // Compute the sub-extents.
  if(!this->ExtentSplitter->ComputeSubExtents())
    {
    // A portion of the extent is not available.
    ostrstream e;
    e << "No available piece provides data for the following extents:\n";
    for(i=0; i < this->ExtentSplitter->GetNumberOfSubExtents(); ++i)
      {
      if(this->ExtentSplitter->GetSubExtentSource(i) < 0)
        {
        int extent[6];
        this->ExtentSplitter->GetSubExtent(i, extent);
        e << "    "
          << extent[0] << " " << extent[1] << "  "
          << extent[2] << " " << extent[3] << "  "
          << extent[4] << " " << extent[5] << "\n";
        }
      }
    e << "The UpdateExtent cannot be filled." << ends;
    vtkErrorMacro(<< e.str());
    e.rdbuf()->freeze(0);
    return 0;
    }

  return 1;
}
<commit_msg>ENH: The extent splitter now uses the input file for each readable piece to get available extents.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLPStructuredDataReader.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLPStructuredDataReader.h"

#include "vtkDataArray.h"
#include "vtkDataSet.h"
#include "vtkExtentSplitter.h"
#include "vtkTableExtentTranslator.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLStructuredDataReader.h"

vtkCxxRevisionMacro(vtkXMLPStructuredDataReader, "1.9.2.2");

//----------------------------------------------------------------------------
vtkXMLPStructuredDataReader::vtkXMLPStructuredDataReader()
{
  this->ExtentTranslator = vtkTableExtentTranslator::New();
  this->ExtentSplitter = vtkExtentSplitter::New();
  this->PieceExtents = 0;
}

//----------------------------------------------------------------------------
vtkXMLPStructuredDataReader::~vtkXMLPStructuredDataReader()
{
  if(this->NumberOfPieces) { this->DestroyPieces(); }
  this->ExtentSplitter->Delete();
  this->ExtentTranslator->Delete();
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

//----------------------------------------------------------------------------
vtkExtentTranslator* vtkXMLPStructuredDataReader::GetExtentTranslator()
{
  return this->ExtentTranslator;
}

//----------------------------------------------------------------------------
vtkIdType vtkXMLPStructuredDataReader::GetNumberOfPoints()
{
  return (this->PointDimensions[0]*
          this->PointDimensions[1]*
          this->PointDimensions[2]);
}

//----------------------------------------------------------------------------
vtkIdType vtkXMLPStructuredDataReader::GetNumberOfCells()
{
  return (this->CellDimensions[0]*
          this->CellDimensions[1]*
          this->CellDimensions[2]);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::ReadXMLData()
{
  // Get the requested Update Extent.
  this->GetOutputAsDataSet(0)->GetUpdateExtent(this->UpdateExtent);

  vtkDebugMacro("Updating extent "
                << this->UpdateExtent[0] << " " << this->UpdateExtent[1] << " "
                << this->UpdateExtent[2] << " " << this->UpdateExtent[3] << " "
                << this->UpdateExtent[4] << " " << this->UpdateExtent[5]
                << "\n");

  // Prepare increments for the update extent.
  this->ComputeDimensions(this->UpdateExtent, this->PointDimensions, 1);
  this->ComputeIncrements(this->UpdateExtent, this->PointIncrements, 1);
  this->ComputeDimensions(this->UpdateExtent, this->CellDimensions, 0);
  this->ComputeIncrements(this->UpdateExtent, this->CellIncrements, 0);

  // Let superclasses read data.  This also allocates output data.
  this->Superclass::ReadXMLData();

  // Use the ExtentSplitter to split the update extent into
  // sub-extents read by each piece.
  if(!this->ComputePieceSubExtents())
    {
    // Not all needed data are available.
    this->DataError = 1;
    return;
    }

  // Split current progress range based on fraction contributed by
  // each sub-extent.
  float progressRange[2] = {0,0};
  this->GetProgressRange(progressRange);

  // Calculate the cumulative fraction of data contributed by each
  // sub-extent (for progress).
  int n = this->ExtentSplitter->GetNumberOfSubExtents();
  float* fractions = new float[n+1];
  int i;
  fractions[0] = 0;
  for(i=0;i < n;++i)
    {
    // Get this sub-extent.
    this->ExtentSplitter->GetSubExtent(i, this->SubExtent);

    // Add this sub-extent's volume to the cumulative volume.
    int pieceDims[3] = {0,0,0};
    this->ComputeDimensions(this->SubExtent, pieceDims, 1);
    fractions[i+1] = fractions[i] + pieceDims[0]*pieceDims[1]*pieceDims[2];
    }
  if(fractions[n] == 0)
    {
    fractions[n] = 1;
    }
  for(i=1;i <= n;++i)
    {
    fractions[i] = fractions[i] / fractions[n];
    }

  // Read the data needed from each sub-extent.
  for(i=0;(i < n && !this->AbortExecute && !this->DataError);++i)
    {
    // Set the range of progress for this sub-extent.
    this->SetProgressRange(progressRange, i, fractions);

    // Get this sub-extent and the piece from which to read it.
    int piece = this->ExtentSplitter->GetSubExtentSource(i);
    this->ExtentSplitter->GetSubExtent(i, this->SubExtent);

    vtkDebugMacro("Reading extent "
                  << this->SubExtent[0] << " " << this->SubExtent[1] << " "
                  << this->SubExtent[2] << " " << this->SubExtent[3] << " "
                  << this->SubExtent[4] << " " << this->SubExtent[5]
                  << " from piece " << piece);

    this->ComputeDimensions(this->SubExtent, this->SubPointDimensions, 1);
    this->ComputeDimensions(this->SubExtent, this->SubCellDimensions, 0);

    // Read the data from this piece.
    if(!this->Superclass::ReadPieceData(piece))
      {
      // An error occurred while reading the piece.
      this->DataError = 1;
      }
    }

  delete [] fractions;

  // We filled the exact update extent in the output.
  this->SetOutputExtent(this->UpdateExtent);
}

//----------------------------------------------------------------------------
int
vtkXMLPStructuredDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
{
  if(!this->Superclass::ReadPrimaryElement(ePrimary)) { return 0; }
  vtkDataSet* output = this->GetOutputAsDataSet(0);

  // Read information about the structured data.
  int extent[6];
  if(ePrimary->GetVectorAttribute("WholeExtent", 6, extent) < 6)
    {
    vtkErrorMacro(<< this->GetDataSetName()
                  << " element has no WholeExtent.");
    return 0;
    }
  output->SetWholeExtent(extent);

  return 1;
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::SetupOutputInformation()
{
  this->Superclass::SetupOutputInformation();

  // Tell the output to use the table extent translator to provide the
  // correct piece breakdown for the file layout.
  this->GetOutputAsDataSet(0)->SetExtentTranslator(this->ExtentTranslator);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::SetupEmptyOutput()
{
  // Special extent to indicate no input.
  this->GetOutputAsDataSet(0)->SetUpdateExtent(1, 0, 1, 0, 1, 0);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::SetupPieces(int numPieces)
{
  this->Superclass::SetupPieces(numPieces);
  this->ExtentTranslator->SetNumberOfPieces(this->NumberOfPieces);
  this->ExtentTranslator->SetMaximumGhostLevel(this->GhostLevel);
  this->PieceExtents = new int[6*this->NumberOfPieces];
  int i;
  for(i=0;i < this->NumberOfPieces;++i)
    {
    int* extent = this->PieceExtents+i*6;
    extent[0] = 0; extent[1] = -1;
    extent[2] = 0; extent[3] = -1;
    extent[4] = 0; extent[5] = -1;
    }
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::DestroyPieces()
{
  delete [] this->PieceExtents;
  this->PieceExtents = 0;
  this->Superclass::DestroyPieces();
}

//----------------------------------------------------------------------------
int vtkXMLPStructuredDataReader::ReadPiece(vtkXMLDataElement* ePiece)
{
  // Superclass will create a reader for the piece's file.
  if(!this->Superclass::ReadPiece(ePiece)) { return 0; }

  // Get the extent of the piece.
  int* pieceExtent = this->PieceExtents+this->Piece*6;
  if(ePiece->GetVectorAttribute("Extent", 6, pieceExtent) < 6)
    {
    vtkErrorMacro("Piece " << this->Piece << " has invalid Extent.");
    return 0;
    }

  // Set this table entry in the extent translator.
  this->ExtentTranslator->SetExtentForPiece(this->Piece, pieceExtent);
  this->ExtentTranslator->SetPieceAvailable(this->Piece,
                                            this->CanReadPiece(this->Piece));

  return 1;
}

//----------------------------------------------------------------------------
int vtkXMLPStructuredDataReader::ReadPieceData()
{
  // Use the internal reader to read the piece.
  vtkDataSet* input = this->GetPieceInputAsDataSet(this->Piece);
  input->SetUpdateExtent(this->SubExtent);
  input->Update();

  // Skip rest of read if aborting.
  if(this->AbortExecute)
    {
    return 0;
    }

  // Get the actual portion of the piece that was read.
  this->GetPieceInputExtent(this->Piece, this->SubPieceExtent);
  this->ComputeDimensions(this->SubPieceExtent,
                          this->SubPiecePointDimensions, 1);
  this->ComputeIncrements(this->SubPieceExtent,
                          this->SubPiecePointIncrements, 1);
  this->ComputeDimensions(this->SubPieceExtent,
                          this->SubPieceCellDimensions, 0);
  this->ComputeIncrements(this->SubPieceExtent,
                          this->SubPieceCellIncrements, 0);

  // Let the superclass read the data it wants.
  return this->Superclass::ReadPieceData();
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::CopyArrayForPoints(vtkDataArray* inArray,
                                                     vtkDataArray* outArray)
{
  if(!inArray || !outArray)
    {
    return;
    }
  this->CopySubExtent(this->SubPieceExtent,
                      this->SubPiecePointDimensions,
                      this->SubPiecePointIncrements,
                      this->UpdateExtent, this->PointDimensions,
                      this->PointIncrements, this->SubExtent,
                      this->SubPointDimensions, inArray, outArray);
}

//----------------------------------------------------------------------------
void vtkXMLPStructuredDataReader::CopyArrayForCells(vtkDataArray* inArray,
                                                    vtkDataArray* outArray)
{
  if(!inArray || !outArray)
    {
    return;
    }
  this->CopySubExtent(this->SubPieceExtent,
                      this->SubPieceCellDimensions,
                      this->SubPieceCellIncrements,
                      this->UpdateExtent, this->CellDimensions,
                      this->CellIncrements, this->SubExtent,
                      this->SubCellDimensions, inArray, outArray);
}

//----------------------------------------------------------------------------
void
vtkXMLPStructuredDataReader
::CopySubExtent(int* inExtent, int* inDimensions, int* inIncrements,
                int* outExtent, int* outDimensions, int* outIncrements,
                int* subExtent, int* subDimensions,
                vtkDataArray* inArray, vtkDataArray* outArray)
{
  unsigned int components = inArray->GetNumberOfComponents();
  unsigned int tupleSize = inArray->GetDataTypeSize()*components;

  if((inDimensions[0] == outDimensions[0]) &&
     (inDimensions[1] == outDimensions[1]))
    {
    if(inDimensions[2] == outDimensions[2])
      {
      // Copy the whole volume at once.
      unsigned int volumeTuples = (inDimensions[0]*
                                   inDimensions[1]*
                                   inDimensions[2]);
      memcpy(outArray->GetVoidPointer(0), inArray->GetVoidPointer(0),
             volumeTuples*tupleSize);
      }
    else
      {
      // Copy an entire slice at a time.
      unsigned int sliceTuples = inDimensions[0]*inDimensions[1];
      int k;
      for(k=0;k < subDimensions[2];++k)
        {
        unsigned int sourceTuple = this->GetStartTuple(inExtent, inIncrements,
                                                       subExtent[0],
                                                       subExtent[2],
                                                       subExtent[4]+k);
        unsigned int destTuple = this->GetStartTuple(outExtent, outIncrements,
                                                     subExtent[0],
                                                     subExtent[2],
                                                     subExtent[4]+k);
        memcpy(outArray->GetVoidPointer(destTuple*components),
               inArray->GetVoidPointer(sourceTuple*components),
               sliceTuples*tupleSize);
        }
      }
    }
  else
    {
    // Copy a row at a time.
    unsigned int rowTuples = subDimensions[0];
    int j,k;
    for(k=0;k < subDimensions[2];++k)
      {
      for(j=0;j < subDimensions[1];++j)
        {
        unsigned int sourceTuple = this->GetStartTuple(inExtent, inIncrements,
                                                       subExtent[0],
                                                       subExtent[2]+j,
                                                       subExtent[4]+k);
        unsigned int destTuple = this->GetStartTuple(outExtent, outIncrements,
                                                     subExtent[0],
                                                     subExtent[2]+j,
                                                     subExtent[4]+k);
        memcpy(outArray->GetVoidPointer(destTuple*components),
               inArray->GetVoidPointer(sourceTuple*components),
               rowTuples*tupleSize);
        }
      }
    }
}

//----------------------------------------------------------------------------
int vtkXMLPStructuredDataReader::ComputePieceSubExtents()
{
  // Reset the extent splitter.
  this->ExtentSplitter->RemoveAllExtentSources();

  // Add each readable piece as an extent source.
  int i;
  for(i=0;i < this->NumberOfPieces;++i)
    {
    if(this->CanReadPiece(i))
      {
      // Add the exact extent provided by the piece to the splitter.
      int extent[6];
      this->PieceReaders[i]->UpdateInformation();
      this->PieceReaders[i]->GetOutputAsDataSet()->GetWholeExtent(extent);
      this->ExtentSplitter->AddExtentSource(i, 0, extent);
      }
    }

  // We want to split the entire update extent across the pieces.
  this->ExtentSplitter->AddExtent(this->UpdateExtent);

  // Compute the sub-extents.
  if(!this->ExtentSplitter->ComputeSubExtents())
    {
    // A portion of the extent is not available.
    ostrstream e;
    e << "No available piece provides data for the following extents:\n";
    for(i=0; i < this->ExtentSplitter->GetNumberOfSubExtents(); ++i)
      {
      if(this->ExtentSplitter->GetSubExtentSource(i) < 0)
        {
        int extent[6];
        this->ExtentSplitter->GetSubExtent(i, extent);
        e << "    "
          << extent[0] << " " << extent[1] << "  "
          << extent[2] << " " << extent[3] << "  "
          << extent[4] << " " << extent[5] << "\n";
        }
      }
    e << "The UpdateExtent cannot be filled." << ends;
    vtkErrorMacro(<< e.str());
    e.rdbuf()->freeze(0);
    return 0;
    }

  return 1;
}
<|endoftext|>


<commit_before>/*
	This file is part of the E_Rendering library.
	Copyright (C) 2009-2012 Benjamin Eikel <benjamin@eikel.org>
	Copyright (C) 2009-2012 Claudius Jähn <claudius@uni-paderborn.de>
	Copyright (C) 2009-2012 Ralf Petring <ralf@petring.net>

	This library is subject to the terms of the Mozilla Public License, v. 2.0.
	You should have received a copy of the MPL along with this library; see the
	file LICENSE. If not, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "E_MeshBuilder.h"

#include "../Mesh/E_Mesh.h"
#include "../Mesh/E_VertexDescription.h"
#include "../Texture/E_Texture.h"

#include <E_Geometry/E_Vec2.h>
#include <E_Geometry/E_Vec3.h>
#include <E_Geometry/E_Matrix4x4.h>
#include <E_Geometry/E_SRT.h>
#include <E_Geometry/E_Sphere.h>
#include <E_Geometry/E_Box.h>
#include <E_Util/Graphics/E_Color.h>
#include <E_Util/Graphics/E_Bitmap.h>
#include <E_Util/Graphics/E_PixelAccessor.h>
#include <Rendering/Mesh/VertexAttributeIds.h>
#include <Rendering/MeshUtils/MeshUtils.h>

#include <EScript/Basics.h>
#include <EScript/StdObjects.h>

#include <cmath>

using namespace Rendering;
using namespace Rendering::MeshUtils;

namespace E_Rendering {

//! (static)
EScript::Type * E_MeshBuilder::getTypeObject() {
	// E_MeshBuilder ---|> Object
	static EScript::ERef<EScript::Type> typeObject = new EScript::Type(EScript::Object::getTypeObject());
	return typeObject.get();
}

//! initMembers
void E_MeshBuilder::init(EScript::Namespace & lib) {
	EScript::Type * typeObject = getTypeObject();
	declareConstant(&lib,getClassName(),typeObject);

	// (static)

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createArrow(Number radius, Number length)
	ES_FUN(typeObject,"createArrow", 2, 2, (MeshBuilder::createArrow(parameter[0].toFloat(), parameter[1].toFloat())))

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createCone(Number radius, Number height, Number segments)
	ES_FUN(typeObject,"createCone", 3, 3, (MeshBuilder::createCone(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].to<uint32_t>(rt))))

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createConicalFrustum(Number radiusBottom, Number radiusTop, Number height, Number segments)
	ES_FUN(typeObject,"createConicalFrustum", 4, 4, (MeshBuilder::createConicalFrustum(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].toFloat(), parameter[3].to<uint32_t>(rt))))

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createDiscSector(Number radius, Number segments, Number angle)
	ES_FUNCTION(typeObject,"createDiscSector",2,3,{
		if (parameter.count() == 2) {
			return EScript::create(MeshBuilder::createDiscSector(parameter[0].toFloat(), parameter[1].to<uint32_t>(rt)));
		} else {
			return EScript::create(MeshBuilder::createDiscSector(parameter[0].toFloat(), parameter[1].to<uint32_t>(rt), parameter[2].toFloat()));
		}
	})

	/*! [ESF] (static) Mesh Rendering.MeshBuilder.createDome(radius=100,
								int horiRes = 40, int vertRes = 40,
								double halfSphereFraction = 1.0,
								double imagePercentage = 1.0) */
	ES_FUN(typeObject,"createDome",0,5,(MeshBuilder::createDome(
				parameter[0].toFloat(100.0),
				parameter[1].toInt(40),
				parameter[2].toInt(40),
				parameter[3].toFloat(1.0),
				parameter[4].toFloat(1.0))))

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createRectangle([VertexDescription],width,height)
	ES_FUNCTION(typeObject, "createRectangle", 2, 3, {
		if (parameter.count() == 3) {
			return EScript::create(MeshBuilder::createRectangle(parameter[0].to<const VertexDescription&>(rt),parameter[1].toFloat(), parameter[2].toFloat()));
		} else {
			Rendering::VertexDescription vertexDescription;
			vertexDescription.appendPosition3D();
			vertexDescription.appendNormalFloat();
			vertexDescription.appendColorRGBFloat();
			vertexDescription.appendTexCoord();
			return EScript::create(MeshBuilder::createRectangle(vertexDescription,parameter[0].toFloat(), parameter[1].toFloat()));
		}
	})

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createRingSector(Number innerRadius, Number outerRadius, Number segments, Number angle)
	ES_FUNCTION(typeObject,"createRingSector",3,4,{
		if (parameter.count() == 3) {
			return EScript::create(MeshBuilder::createRingSector(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].to<uint32_t>(rt)));
		} else {
			return EScript::create(MeshBuilder::createRingSector(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].to<uint32_t>(rt), parameter[3].toFloat()));
		}
	})

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createSphere(Number, Number)
	ES_FUNCTION(typeObject, "createSphere", 2, 2, {
		Rendering::VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		vertexDescription.appendNormalFloat();
		vertexDescription.appendColorRGBFloat();
		vertexDescription.appendTexCoord();
		return EScript::create(MeshBuilder::createSphere(vertexDescription, parameter[0].to<uint32_t>(rt), parameter[1].to<uint32_t>(rt)));
	})

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createBox(Box)
	ES_FUNCTION(typeObject, "createBox", 1, 1, {
		Rendering::VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		vertexDescription.appendNormalFloat();
		vertexDescription.appendColorRGBFloat();
		vertexDescription.appendTexCoord();
		return EScript::create(MeshBuilder::createBox(vertexDescription, parameter[0].to<Geometry::Box>(rt)));
	})

	// EXPERIMENTAL!!!!!!!!!!!!!!
	//!	[ESMF] new Rendering.MeshBuilder.createMeshFromBitmaps(Util.Bitmap depth[, Util.Bitmap color[, Util.Bitmap normals]])
	ES_FUNCTION(typeObject,"createMeshFromBitmaps",1,3,{
		Util::Reference<Util::Bitmap> depth = parameter[0].to<Util::Reference<Util::Bitmap>>(rt);
		Util::Reference<Util::Bitmap> color;
		Util::Reference<Util::Bitmap> normal;

		Rendering::VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		if(parameter.count()>1){
			color = parameter[1].to<Util::Reference<Util::Bitmap>>(rt);
			vertexDescription.appendColorRGBAByte();
		}
		if(parameter.count()>2){
			normal = parameter[2].to<Util::Reference<Util::Bitmap>>(rt);
			vertexDescription.appendNormalByte();
		}
		Mesh * m=MeshBuilder::createMeshFromBitmaps(vertexDescription,
													std::move(depth),
													std::move(color),
													std::move(normal));
		if(m)
			return EScript::create(m);
		else return nullptr;
	})

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createHexGrid(VertexDescription, Number width, Number height, Number rows, Number columns)
	ES_FUN(typeObject,"createHexGrid", 5, 5,(
		MeshBuilder::createHexGrid(parameter[0].to<const VertexDescription&>(rt), parameter[1].toFloat(), parameter[2].toFloat(), parameter[3].toUInt(), parameter[4].toUInt())
	))
	// ----

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createVoxelMesh(VertexDescription, Util.PixelAccessor voxelBitmap, Number depth)
	ES_FUN(typeObject,"createVoxelMesh", 3, 3,(
		MeshBuilder::createVoxelMesh(parameter[0].to<const VertexDescription&>(rt), parameter[1].to<Util::PixelAccessor&>(rt), parameter[2].toUInt())
	))
	// ----

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

	//!	[ESMF] new Rendering.MeshBuilder( [VertexDescription] )
	ES_CONSTRUCTOR(typeObject,0,1, {
		if(parameter.count()==0)
			return EScript::create(new MeshBuilder);
		else
			return EScript::create(new MeshBuilder(parameter[0].to<const VertexDescription&>(rt)));
	})

	//!	[ESMF] thisEObj MeshBuilder.addIndex( idx )
	ES_MFUN(typeObject,MeshBuilder,"addIndex",1,1,
				(thisObj->addIndex( parameter[0].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addQuad( idx,idx,idx,idx )
	ES_MFUN(typeObject,MeshBuilder,"addQuad",4,4,
				(thisObj->addQuad( parameter[0].to<uint32_t>(rt),parameter[1].to<uint32_t>(rt),parameter[2].to<uint32_t>(rt),parameter[3].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addSphere( Sphere,inclinationSegments,azimuthSegments )
	ES_MFUN(typeObject,MeshBuilder,"addSphere",3,3,
				(MeshBuilder::addSphere(*thisObj,parameter[0].to<Geometry::Sphere_f>(rt),parameter[1].to<uint32_t>(rt),parameter[2].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addBox( Box )
	ES_MFUN(typeObject,MeshBuilder,"addBox",1,1,
				(MeshBuilder::addBox(*thisObj,parameter[0].to<Geometry::Box>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addTriangle( idx,idx,idx )
	ES_MFUN(typeObject,MeshBuilder,"addTriangle",3,3,
				(thisObj->addTriangle( parameter[0].to<uint32_t>(rt),parameter[1].to<uint32_t>(rt),parameter[2].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] Number MeshBuilder.addVertex( [Vec3f pos ,Vec3 normal, float r, g, b, a, float u, v )
	ES_MFUNCTION(typeObject,MeshBuilder,"addVertex",0,8,{
		uint32_t index=0;
		if(parameter.count() == 8) {
			index=thisObj->addVertex(
					parameter[0].to<Geometry::Vec3>(rt), // pos
					parameter[1].to<Geometry::Vec3>(rt), // normal
					parameter[2].toFloat(),	parameter[3].toFloat(),	parameter[4].toFloat(), parameter[5].toFloat(),	 // color
					parameter[6].toFloat(),	parameter[7].toFloat()); // tex0
		}
		else {
			assertParamCount(rt,parameter.count(),0,0);
			index=thisObj->addVertex();
		}
		return index;
	})

	//!	[ESMF] E_Mesh MeshBuilder.buildMesh()
	ES_MFUN(typeObject,MeshBuilder, "buildMesh", 0, 0, thisObj->buildMesh())

	//!	[ESMF] thisEObj MeshBuilder.color( Color4f | Color4ub )
	ES_MFUNCTION(typeObject,MeshBuilder,"color",1,1,{
		thisObj->color(parameter[0].to<Util::Color4f>(rt));
		return thisEObj;
	})

	//! int MeshBuilder.getNextIndex()
	ES_MFUN(typeObject,MeshBuilder,"getNextIndex",0,0,thisObj->getNextIndex())

	//! Matrix4x4 MeshBuilder.getTransformation()
	ES_MFUN(typeObject,MeshBuilder,"getTransformation",0,0,thisObj->getTransformation())

	//! bool MeshBuilder.isEmpty()
	ES_MFUN(typeObject,MeshBuilder,"isEmpty",0,0,thisObj->isEmpty())

	//!	[ESMF] thisEObj MeshBuilder.normal( Vec3 )
	ES_MFUN(typeObject,MeshBuilder,"normal",1,1,
				( thisObj->normal( parameter[0].to<Geometry::Vec3>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.position( Vec3 )
	ES_MFUN(typeObject,MeshBuilder,"position",1,1,
				( thisObj->position( parameter[0].to<Geometry::Vec3>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.position2D(Vec2)
	ES_MFUN(typeObject,MeshBuilder, "position2D", 1, 1,
				 (thisObj->position(parameter[0].to<Geometry::Vec2>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.texCoord0( Vec2 )
	ES_MFUN(typeObject,MeshBuilder,"texCoord0",1,1,
				( thisObj->texCoord0( parameter[0].to<Geometry::Vec2>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.setTransformation( Matrix4x4 | SRT )
	ES_MFUNCTION(typeObject,MeshBuilder,"setTransformation",1,1,{
		E_Geometry::E_Matrix4x4 * em = parameter[0].toType<E_Geometry::E_Matrix4x4>();
		if(em){
			thisObj->setTransformation(em->ref());
		}else{
			thisObj->setTransformation(parameter[0].to<const Geometry::SRT&>(rt));
		}
		return thisEObj;
	})

}

}
<commit_msg>added createTorus to MeshBuilder<commit_after>/*
	This file is part of the E_Rendering library.
	Copyright (C) 2009-2012 Benjamin Eikel <benjamin@eikel.org>
	Copyright (C) 2009-2012 Claudius Jähn <claudius@uni-paderborn.de>
	Copyright (C) 2009-2012 Ralf Petring <ralf@petring.net>

	This library is subject to the terms of the Mozilla Public License, v. 2.0.
	You should have received a copy of the MPL along with this library; see the
	file LICENSE. If not, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "E_MeshBuilder.h"

#include "../Mesh/E_Mesh.h"
#include "../Mesh/E_VertexDescription.h"
#include "../Texture/E_Texture.h"

#include <E_Geometry/E_Vec2.h>
#include <E_Geometry/E_Vec3.h>
#include <E_Geometry/E_Matrix4x4.h>
#include <E_Geometry/E_SRT.h>
#include <E_Geometry/E_Sphere.h>
#include <E_Geometry/E_Box.h>
#include <E_Util/Graphics/E_Color.h>
#include <E_Util/Graphics/E_Bitmap.h>
#include <E_Util/Graphics/E_PixelAccessor.h>
#include <Rendering/Mesh/VertexAttributeIds.h>
#include <Rendering/MeshUtils/MeshUtils.h>

#include <EScript/Basics.h>
#include <EScript/StdObjects.h>

#include <cmath>

using namespace Rendering;
using namespace Rendering::MeshUtils;

namespace E_Rendering {

//! (static)
EScript::Type * E_MeshBuilder::getTypeObject() {
	// E_MeshBuilder ---|> Object
	static EScript::ERef<EScript::Type> typeObject = new EScript::Type(EScript::Object::getTypeObject());
	return typeObject.get();
}

//! initMembers
void E_MeshBuilder::init(EScript::Namespace & lib) {
	EScript::Type * typeObject = getTypeObject();
	declareConstant(&lib,getClassName(),typeObject);

	// (static)

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createArrow(Number radius, Number length)
	ES_FUN(typeObject,"createArrow", 2, 2, (MeshBuilder::createArrow(parameter[0].toFloat(), parameter[1].toFloat())))

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createCone(Number radius, Number height, Number segments)
	ES_FUN(typeObject,"createCone", 3, 3, (MeshBuilder::createCone(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].to<uint32_t>(rt))))

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createConicalFrustum(Number radiusBottom, Number radiusTop, Number height, Number segments)
	ES_FUN(typeObject,"createConicalFrustum", 4, 4, (MeshBuilder::createConicalFrustum(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].toFloat(), parameter[3].to<uint32_t>(rt))))

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createDiscSector(Number radius, Number segments, Number angle)
	ES_FUNCTION(typeObject,"createDiscSector",2,3,{
		if (parameter.count() == 2) {
			return EScript::create(MeshBuilder::createDiscSector(parameter[0].toFloat(), parameter[1].to<uint32_t>(rt)));
		} else {
			return EScript::create(MeshBuilder::createDiscSector(parameter[0].toFloat(), parameter[1].to<uint32_t>(rt), parameter[2].toFloat()));
		}
	})

	/*! [ESF] (static) Mesh Rendering.MeshBuilder.createDome(radius=100,
								int horiRes = 40, int vertRes = 40,
								double halfSphereFraction = 1.0,
								double imagePercentage = 1.0) */
	ES_FUN(typeObject,"createDome",0,5,(MeshBuilder::createDome(
				parameter[0].toFloat(100.0),
				parameter[1].toInt(40),
				parameter[2].toInt(40),
				parameter[3].toFloat(1.0),
				parameter[4].toFloat(1.0))))

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createRectangle([VertexDescription],width,height)
	ES_FUNCTION(typeObject, "createRectangle", 2, 3, {
		if (parameter.count() == 3) {
			return EScript::create(MeshBuilder::createRectangle(parameter[0].to<const VertexDescription&>(rt),parameter[1].toFloat(), parameter[2].toFloat()));
		} else {
			Rendering::VertexDescription vertexDescription;
			vertexDescription.appendPosition3D();
			vertexDescription.appendNormalFloat();
			vertexDescription.appendColorRGBFloat();
			vertexDescription.appendTexCoord();
			return EScript::create(MeshBuilder::createRectangle(vertexDescription,parameter[0].toFloat(), parameter[1].toFloat()));
		}
	})

	//! [ESF] (static) Mesh Rendering.MeshBuilder.createRingSector(Number innerRadius, Number outerRadius, Number segments, Number angle)
	ES_FUNCTION(typeObject,"createRingSector",3,4,{
		if (parameter.count() == 3) {
			return EScript::create(MeshBuilder::createRingSector(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].to<uint32_t>(rt)));
		} else {
			return EScript::create(MeshBuilder::createRingSector(parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].to<uint32_t>(rt), parameter[3].toFloat()));
		}
	})

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createSphere(Number, Number)
	ES_FUNCTION(typeObject, "createSphere", 2, 2, {
		Rendering::VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		vertexDescription.appendNormalFloat();
		vertexDescription.appendColorRGBFloat();
		vertexDescription.appendTexCoord();
		return EScript::create(MeshBuilder::createSphere(vertexDescription, parameter[0].to<uint32_t>(rt), parameter[1].to<uint32_t>(rt)));
	})

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createBox(Box)
	ES_FUNCTION(typeObject, "createBox", 1, 1, {
		Rendering::VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		vertexDescription.appendNormalFloat();
		vertexDescription.appendColorRGBFloat();
		vertexDescription.appendTexCoord();
		return EScript::create(MeshBuilder::createBox(vertexDescription, parameter[0].to<Geometry::Box>(rt)));
	})

	// EXPERIMENTAL!!!!!!!!!!!!!!
	//!	[ESMF] new Rendering.MeshBuilder.createMeshFromBitmaps(Util.Bitmap depth[, Util.Bitmap color[, Util.Bitmap normals]])
	ES_FUNCTION(typeObject,"createMeshFromBitmaps",1,3,{
		Util::Reference<Util::Bitmap> depth = parameter[0].to<Util::Reference<Util::Bitmap>>(rt);
		Util::Reference<Util::Bitmap> color;
		Util::Reference<Util::Bitmap> normal;

		Rendering::VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		if(parameter.count()>1){
			color = parameter[1].to<Util::Reference<Util::Bitmap>>(rt);
			vertexDescription.appendColorRGBAByte();
		}
		if(parameter.count()>2){
			normal = parameter[2].to<Util::Reference<Util::Bitmap>>(rt);
			vertexDescription.appendNormalByte();
		}
		Mesh * m=MeshBuilder::createMeshFromBitmaps(vertexDescription,
													std::move(depth),
													std::move(color),
													std::move(normal));
		if(m)
			return EScript::create(m);
		else return nullptr;
	})

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createHexGrid(VertexDescription, Number width, Number height, Number rows, Number columns)
	ES_FUN(typeObject,"createHexGrid", 5, 5,(
		MeshBuilder::createHexGrid(parameter[0].to<const VertexDescription&>(rt), parameter[1].toFloat(), parameter[2].toFloat(), parameter[3].toUInt(), parameter[4].toUInt())
	))
	// ----

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createVoxelMesh(VertexDescription, Util.PixelAccessor voxelBitmap, Number depth)
	ES_FUN(typeObject,"createVoxelMesh", 3, 3,(
		MeshBuilder::createVoxelMesh(parameter[0].to<const VertexDescription&>(rt), parameter[1].to<Util::PixelAccessor&>(rt), parameter[2].toUInt())
	))
	// ----

	//!	[ESF] (static) Mesh Rendering.MeshBuilder.createTorus(Number, Number, Number, Number)
	ES_FUNCTION(typeObject, "createTorus", 4, 4, {
		Rendering::VertexDescription vertexDescription;
		vertexDescription.appendPosition3D();
		vertexDescription.appendNormalFloat();
		vertexDescription.appendColorRGBFloat();
		vertexDescription.appendTexCoord();
		return EScript::create(MeshBuilder::createTorus(vertexDescription, parameter[0].toFloat(), parameter[1].toFloat(), parameter[2].toUInt(), parameter[3].toUInt()));
	})

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

	//!	[ESMF] new Rendering.MeshBuilder( [VertexDescription] )
	ES_CONSTRUCTOR(typeObject,0,1, {
		if(parameter.count()==0)
			return EScript::create(new MeshBuilder);
		else
			return EScript::create(new MeshBuilder(parameter[0].to<const VertexDescription&>(rt)));
	})

	//!	[ESMF] thisEObj MeshBuilder.addIndex( idx )
	ES_MFUN(typeObject,MeshBuilder,"addIndex",1,1,
				(thisObj->addIndex( parameter[0].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addQuad( idx,idx,idx,idx )
	ES_MFUN(typeObject,MeshBuilder,"addQuad",4,4,
				(thisObj->addQuad( parameter[0].to<uint32_t>(rt),parameter[1].to<uint32_t>(rt),parameter[2].to<uint32_t>(rt),parameter[3].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addSphere( Sphere,inclinationSegments,azimuthSegments )
	ES_MFUN(typeObject,MeshBuilder,"addSphere",3,3,
				(MeshBuilder::addSphere(*thisObj,parameter[0].to<Geometry::Sphere_f>(rt),parameter[1].to<uint32_t>(rt),parameter[2].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addBox( Box )
	ES_MFUN(typeObject,MeshBuilder,"addBox",1,1,
				(MeshBuilder::addBox(*thisObj,parameter[0].to<Geometry::Box>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.addTriangle( idx,idx,idx )
	ES_MFUN(typeObject,MeshBuilder,"addTriangle",3,3,
				(thisObj->addTriangle( parameter[0].to<uint32_t>(rt),parameter[1].to<uint32_t>(rt),parameter[2].to<uint32_t>(rt)),thisEObj))

	//!	[ESMF] Number MeshBuilder.addVertex( [Vec3f pos ,Vec3 normal, float r, g, b, a, float u, v )
	ES_MFUNCTION(typeObject,MeshBuilder,"addVertex",0,8,{
		uint32_t index=0;
		if(parameter.count() == 8) {
			index=thisObj->addVertex(
					parameter[0].to<Geometry::Vec3>(rt), // pos
					parameter[1].to<Geometry::Vec3>(rt), // normal
					parameter[2].toFloat(),	parameter[3].toFloat(),	parameter[4].toFloat(), parameter[5].toFloat(),	 // color
					parameter[6].toFloat(),	parameter[7].toFloat()); // tex0
		}
		else {
			assertParamCount(rt,parameter.count(),0,0);
			index=thisObj->addVertex();
		}
		return index;
	})

	//!	[ESMF] E_Mesh MeshBuilder.buildMesh()
	ES_MFUN(typeObject,MeshBuilder, "buildMesh", 0, 0, thisObj->buildMesh())

	//!	[ESMF] thisEObj MeshBuilder.color( Color4f | Color4ub )
	ES_MFUNCTION(typeObject,MeshBuilder,"color",1,1,{
		thisObj->color(parameter[0].to<Util::Color4f>(rt));
		return thisEObj;
	})

	//! int MeshBuilder.getNextIndex()
	ES_MFUN(typeObject,MeshBuilder,"getNextIndex",0,0,thisObj->getNextIndex())

	//! Matrix4x4 MeshBuilder.getTransformation()
	ES_MFUN(typeObject,MeshBuilder,"getTransformation",0,0,thisObj->getTransformation())

	//! bool MeshBuilder.isEmpty()
	ES_MFUN(typeObject,MeshBuilder,"isEmpty",0,0,thisObj->isEmpty())

	//!	[ESMF] thisEObj MeshBuilder.normal( Vec3 )
	ES_MFUN(typeObject,MeshBuilder,"normal",1,1,
				( thisObj->normal( parameter[0].to<Geometry::Vec3>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.position( Vec3 )
	ES_MFUN(typeObject,MeshBuilder,"position",1,1,
				( thisObj->position( parameter[0].to<Geometry::Vec3>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.position2D(Vec2)
	ES_MFUN(typeObject,MeshBuilder, "position2D", 1, 1,
				 (thisObj->position(parameter[0].to<Geometry::Vec2>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.texCoord0( Vec2 )
	ES_MFUN(typeObject,MeshBuilder,"texCoord0",1,1,
				( thisObj->texCoord0( parameter[0].to<Geometry::Vec2>(rt)),thisEObj))

	//!	[ESMF] thisEObj MeshBuilder.setTransformation( Matrix4x4 | SRT )
	ES_MFUNCTION(typeObject,MeshBuilder,"setTransformation",1,1,{
		E_Geometry::E_Matrix4x4 * em = parameter[0].toType<E_Geometry::E_Matrix4x4>();
		if(em){
			thisObj->setTransformation(em->ref());
		}else{
			thisObj->setTransformation(parameter[0].to<const Geometry::SRT&>(rt));
		}
		return thisEObj;
	})

}

}
<|endoftext|>