Errors in CodeWarrior: co-processor offset out of range - c++

I'm trying to run a fuzzy inference system (FIS) application on a Freescale Kinetis K70F120M development board using CodeWarrior.
I wrote an Interpreter software that reads two plain text files (one that contains a Fuzzy Model and the other with patterns to be recognized) and writes a C++ application that can be uploaded to a development board to operate based on data read by sensors.
All the information contained in the FIS C++ application is written by the Interpreter, there's no chance I miscalculated the dimensions of a vector because the amount of elements were counted from the data contained in the files.
I've managed to run a FIS example application on the board but when I try to run the actual application I need to run I get the following 71 errors:
Description Resource Path Location Type
C:\Users\CRISTH~1\AppData\Local\Temp\ccLOvcxh.s co-processor offset out of range Prueba FALLAS 2 line 8696, external location: C:\Users\CRISTH~1\AppData\Local\Temp\ccLOvcxh.s C/C++ Problem
C:\Users\CRISTH~1\AppData\Local\Temp\ccLOvcxh.s co-processor offset out of range Prueba FALLAS 2 line 8697, external location: C:\Users\CRISTH~1\AppData\Local\Temp\ccLOvcxh.s C/C++ Problem
...
C:\Users\CRISTH~1\AppData\Local\Temp\ccLOvcxh.s co-processor offset out of range Prueba FALLAS 2 line 15897, external location: C:\Users\CRISTH~1\AppData\Local\Temp\ccLOvcxh.s C/C++ Problem
mingw32-make: *** [Sources/main.o] Error 1 Prueba FALLAS 2 C/C++ Problem
This is the code I'm trying to run:
#include "derivative.h"
#include "network.h"
int main() {
Network ReporteDeFallasCEC;
const int NInputs = 50, NClasses = 10, NRules = 32;
ReporteDeFallasCEC.initialize();
ReporteDeFallasCEC.setClassNeurons(NClasses);
ReporteDeFallasCEC.setRuleNeurons(NRules, 0, Network::Pruning());
Universe input1;
input1.setLimits(0, 100);
input1.addFuzzySet(FuzzySet("vs", 0, 17.52, 35.04));
input1.addFuzzySet(FuzzySet("s", 9.3, 29.65, 50));
input1.addFuzzySet(FuzzySet("m", 23.82, 45.24, 66.67));
input1.addFuzzySet(FuzzySet("l", 50, 66.67, 83.33));
input1.addFuzzySet(FuzzySet("vl", 66.67, 83.33, 100));
ReporteDeFallasCEC.addVariable(input1);
Universe input2;
input2.setLimits(0, 100);
input2.addFuzzySet(FuzzySet("vs", 0, 24.75, 49.51));
input2.addFuzzySet(FuzzySet("s", 5.45, 27.72, 50));
input2.addFuzzySet(FuzzySet("m", 33.33, 5, 6.67));
input2.addFuzzySet(FuzzySet("l", 50, 66.67, 83.33));
input2.addFuzzySet(FuzzySet("vl", 66.67, 83.33, 100));
ReporteDeFallasCEC.addVariable(input2);
//...here goes the remaining "universe" objects
Universe input50;
input50.setLimits(0, 100);
input50.addFuzzySet(FuzzySet("vs", 0, 22.79, 45.57));
input50.addFuzzySet(FuzzySet("s", 0, 34.55, 100));
input50.addFuzzySet(FuzzySet("m", 20.59, 43.63, 66.67));
input50.addFuzzySet(FuzzySet("l", 42.4, 68.49, 95.99));
input50.addFuzzySet(FuzzySet("vl", 66.67, 83.33, 100));
ReporteDeFallasCEC.addVariable(input50);
ClassNeuron InterferenciaDeGas;
ClassNeuron TuberiaDesancladaConGolpeDeFluido;
ClassNeuron RoturaDeVarilla;
ClassNeuron FugaEnLaValvulaFijaDePie;
ClassNeuron FugaEnLaValvulaViajera;
ClassNeuron BarrilDeLaBombaDoblado;
ClassNeuron BuenLlenadoConTuberiaAnclada;
ClassNeuron AgujeroEnElBarrilDeLaBomba;
ClassNeuron AnclaDeTuberiaEnMalFuncionamiento;
ClassNeuron BarrilDeLaBombaGastado;
RuleNeuron FLRule65248697 = RuleNeuron();
FLRule65248697.setNumInputsNeurons(NInputs);
FLRule65248697.setNumClasses(NClasses);
FLRule65248697.setAntecedent(0, 0);
FLRule65248697.setAntecedent(1, 0);
FLRule65248697.setAntecedent(2, 0);
FLRule65248697.setAntecedent(3, 0);
FLRule65248697.setAntecedent(4, 0);
FLRule65248697.setAntecedent(5, 0);
FLRule65248697.setAntecedent(6, 0);
FLRule65248697.setAntecedent(7, 0);
FLRule65248697.setAntecedent(8, 0);
FLRule65248697.setAntecedent(9, 0);
FLRule65248697.setAntecedent(10, 0);
FLRule65248697.setAntecedent(11, 2);
FLRule65248697.setAntecedent(12, 2);
FLRule65248697.setAntecedent(13, 3);
FLRule65248697.setAntecedent(14, 3);
FLRule65248697.setAntecedent(15, 3);
FLRule65248697.setAntecedent(16, 4);
FLRule65248697.setAntecedent(17, 4);
FLRule65248697.setAntecedent(18, 4);
FLRule65248697.setAntecedent(19, 4);
FLRule65248697.setAntecedent(20, 4);
FLRule65248697.setAntecedent(21, 4);
FLRule65248697.setAntecedent(22, 4);
FLRule65248697.setAntecedent(23, 4);
FLRule65248697.setAntecedent(24, 4);
FLRule65248697.setAntecedent(25, 3);
FLRule65248697.setAntecedent(26, 4);
FLRule65248697.setAntecedent(27, 4);
FLRule65248697.setAntecedent(28, 4);
FLRule65248697.setAntecedent(29, 4);
FLRule65248697.setAntecedent(30, 4);
FLRule65248697.setAntecedent(31, 4);
FLRule65248697.setAntecedent(32, 4);
FLRule65248697.setAntecedent(33, 4);
FLRule65248697.setAntecedent(34, 4);
FLRule65248697.setAntecedent(35, 4);
FLRule65248697.setAntecedent(36, 4);
FLRule65248697.setAntecedent(37, 4);
FLRule65248697.setAntecedent(38, 4);
FLRule65248697.setAntecedent(39, 4);
FLRule65248697.setAntecedent(40, 4);
FLRule65248697.setAntecedent(41, 4);
FLRule65248697.setAntecedent(42, 4);
FLRule65248697.setAntecedent(43, 4);
FLRule65248697.setAntecedent(44, 4);
FLRule65248697.setAntecedent(45, 4);
FLRule65248697.setAntecedent(46, 4);
FLRule65248697.setAntecedent(47, 4);
FLRule65248697.setAntecedent(48, 4);
FLRule65248697.setAntecedent(49, 4);
FLRule65248697.setConsecuent(1);
ReporteDeFallasCEC.addRule(FLRule65248697);
RuleNeuron FLRule50510248 = RuleNeuron();
FLRule50510248.setNumInputsNeurons(NInputs);
FLRule50510248.setNumClasses(NClasses);
FLRule50510248.setAntecedent(0, 0);
FLRule50510248.setAntecedent(1, 0);
FLRule50510248.setAntecedent(2, 0);
FLRule50510248.setAntecedent(3, 0);
FLRule50510248.setAntecedent(4, 0);
FLRule50510248.setAntecedent(5, 0);
FLRule50510248.setAntecedent(6, 0);
FLRule50510248.setAntecedent(7, 0);
FLRule50510248.setAntecedent(8, 0);
FLRule50510248.setAntecedent(9, 0);
FLRule50510248.setAntecedent(10, 0);
FLRule50510248.setAntecedent(11, 0);
FLRule50510248.setAntecedent(12, 0);
FLRule50510248.setAntecedent(13, 0);
FLRule50510248.setAntecedent(14, 2);
FLRule50510248.setAntecedent(15, 4);
FLRule50510248.setAntecedent(16, 4);
FLRule50510248.setAntecedent(17, 4);
FLRule50510248.setAntecedent(18, 4);
FLRule50510248.setAntecedent(19, 4);
FLRule50510248.setAntecedent(20, 4);
FLRule50510248.setAntecedent(21, 4);
FLRule50510248.setAntecedent(22, 4);
FLRule50510248.setAntecedent(23, 4);
FLRule50510248.setAntecedent(24, 4);
FLRule50510248.setAntecedent(25, 3);
FLRule50510248.setAntecedent(26, 4);
FLRule50510248.setAntecedent(27, 4);
FLRule50510248.setAntecedent(28, 4);
FLRule50510248.setAntecedent(29, 4);
FLRule50510248.setAntecedent(30, 4);
FLRule50510248.setAntecedent(31, 4);
FLRule50510248.setAntecedent(32, 4);
FLRule50510248.setAntecedent(33, 4);
FLRule50510248.setAntecedent(34, 4);
FLRule50510248.setAntecedent(35, 4);
FLRule50510248.setAntecedent(36, 4);
FLRule50510248.setAntecedent(37, 4);
FLRule50510248.setAntecedent(38, 4);
FLRule50510248.setAntecedent(39, 4);
FLRule50510248.setAntecedent(40, 4);
FLRule50510248.setAntecedent(41, 4);
FLRule50510248.setAntecedent(42, 4);
FLRule50510248.setAntecedent(43, 4);
FLRule50510248.setAntecedent(44, 4);
FLRule50510248.setAntecedent(45, 4);
FLRule50510248.setAntecedent(46, 4);
FLRule50510248.setAntecedent(47, 4);
FLRule50510248.setAntecedent(48, 4);
FLRule50510248.setAntecedent(49, 4);
FLRule50510248.setConsecuent(2);
ReporteDeFallasCEC.addRule(FLRule50510248);
//...here goes the remaining "RuleNeuron" objects
RuleNeuron FLRule2056998 = RuleNeuron();
FLRule2056998.setNumInputsNeurons(NInputs);
FLRule2056998.setNumClasses(NClasses);
FLRule2056998.setAntecedent(0, 0);
FLRule2056998.setAntecedent(1, 0);
FLRule2056998.setAntecedent(2, 0);
FLRule2056998.setAntecedent(3, 0);
FLRule2056998.setAntecedent(4, 0);
FLRule2056998.setAntecedent(5, 0);
FLRule2056998.setAntecedent(6, 0);
FLRule2056998.setAntecedent(7, 0);
FLRule2056998.setAntecedent(8, 0);
FLRule2056998.setAntecedent(9, 0);
FLRule2056998.setAntecedent(10, 0);
FLRule2056998.setAntecedent(11, 1);
FLRule2056998.setAntecedent(12, 1);
FLRule2056998.setAntecedent(13, 1);
FLRule2056998.setAntecedent(14, 1);
FLRule2056998.setAntecedent(15, 2);
FLRule2056998.setAntecedent(16, 2);
FLRule2056998.setAntecedent(17, 3);
FLRule2056998.setAntecedent(18, 3);
FLRule2056998.setAntecedent(19, 4);
FLRule2056998.setAntecedent(20, 3);
FLRule2056998.setAntecedent(21, 4);
FLRule2056998.setAntecedent(22, 3);
FLRule2056998.setAntecedent(23, 3);
FLRule2056998.setAntecedent(24, 4);
FLRule2056998.setAntecedent(25, 0);
FLRule2056998.setAntecedent(26, 0);
FLRule2056998.setAntecedent(27, 0);
FLRule2056998.setAntecedent(28, 0);
FLRule2056998.setAntecedent(29, 0);
FLRule2056998.setAntecedent(30, 0);
FLRule2056998.setAntecedent(31, 0);
FLRule2056998.setAntecedent(32, 0);
FLRule2056998.setAntecedent(33, 1);
FLRule2056998.setAntecedent(34, 1);
FLRule2056998.setAntecedent(35, 1);
FLRule2056998.setAntecedent(36, 1);
FLRule2056998.setAntecedent(37, 2);
FLRule2056998.setAntecedent(38, 2);
FLRule2056998.setAntecedent(39, 2);
FLRule2056998.setAntecedent(40, 2);
FLRule2056998.setAntecedent(41, 3);
FLRule2056998.setAntecedent(42, 3);
FLRule2056998.setAntecedent(43, 3);
FLRule2056998.setAntecedent(44, 4);
FLRule2056998.setAntecedent(45, 4);
FLRule2056998.setAntecedent(46, 4);
FLRule2056998.setAntecedent(47, 4);
FLRule2056998.setAntecedent(48, 3);
FLRule2056998.setAntecedent(49, 4);
FLRule2056998.setConsecuent(3);
ReporteDeFallasCEC.addRule(FLRule2056998);
const int nPatterns = 60;
double patternArray[nPatterns][NInputs] = {
{ 6.60, 9.70, 12.2, 4.60, 5.70, 8.70, 12.9, 7.60, 11.8, 7.90, 24.9, 44.3, 55.0, 63.6, 71.3, 75.0, 76.8, 80.9, 84.50, 86.50, 90.70, 91.40, 95.00, 97.30, 93.80, 69.20, 82.60, 95.80, 98.90, 97.20, 97.70, 97.80, 96.90, 97.50, 94.50, 93.50, 95.80, 92.50, 93.60, 94.20, 92.00, 90.20, 91.60, 90.20, 91.50, 91.80, 90.70, 93.90, 96.10, 95.70 },
{ 7.70, 5.50, 4.50, 0.60, 1.70, 5.90, 6.70, 6.70, 8.60, 10.1, 5.60, 5.30, 8.40, 24.3, 57.2, 79.8, 88.0, 90.8, 91.10, 91.90, 92.40, 91.80, 91.60, 91.40, 95.70, 62.20, 94.10, 96.40, 91.60, 92.40, 94.00, 97.40, 97.70, 97.80, 96.10, 94.40, 94.40, 96.00, 98.10, 99.30, 94.40, 94.50, 96.30, 96.80, 94.20, 94.50, 96.60, 98.70, 97.10, 97.30 },
//...here goes the remaining pattern rows
{ 1.95, 3.10, 2.00, 3.20, 1.90, 3.70, 5.70, 5.00, 2.10, 3.50, 3.30, 2.05, 2.95, 2.40, 2.70, 3.80, 4.10, 3.30, 4.700, 5.100, 5.300, 5.900, 8.600, 14.30, 38.70, 87.40, 94.80, 96.00, 97.00, 97.40, 98.40, 98.80, 98.10, 98.90, 96.50, 92.00, 83.80, 75.00, 67.80, 69.00, 77.00, 87.70, 94.90, 96.00, 95.80, 95.60, 95.70, 93.80, 87.60, 38.80 }, };
double pattern[NInputs];
for (int i = 0; i < nPatterns; i++) {
std::cout << "Patron " << i + 1 << ": [ ";
for (int j = 0; j < NInputs; j++) {
pattern[j] = patternArray[i][j];
std::cout << patternArray[i][j];
if (j != NInputs - 1) {
std::cout << ", ";
}
}
std::cout << " ]" << "\n";
int clase = ReporteDeFallasCEC.classificate(pattern);
std::cout << "\nClase [ " << clase << " ]\n\n";
}
//std::cin.get();
return 0;
}
This CodeWarrior Project was created in the CodeWarrior IDE v.10.6.4 as a new Bareboard Project:
Device to be used: MK70FN1M0 processor (K70F 120 MHz Family)
Project Type: Application
Connection to be used: Open Source JTAG
Language: C++
Floating Point: Hardware (-mfloat-abi=hard) vs. (-fp vfpv4)
I/O Support: Debugger Console
ARM Build Tools: GCC
Rapid Application Development: None
Start with perspective designed for: current perspective
I'm building the project with the FLASH configuration and debugging as "Prueba FALLAS 2_FLASH_OSJTAG".
I'm running CodeWarrior on Windows 7.
Help me find what's preventing the code from running on the board.
Update #1:
I've removed the code concerning the generation of the "ClassNeuron" and "RuleNeuron" objects and the patternArray vector including the functions that make use of that vector, so the remaining application is only creating the 50 "Universe" objects. After doing that I proceeded to remove a deliberate number of Universe objects to try to find out if there is a memory limit related issue, but wether it is 15 or 26 objects, I get a random amount of errors of the type described above (even 0 errors).
I need to run my application with that exact quantity of objects (50 Universes, 10 Classes, 32 Rules & the 50x60 Pattern Array).
I suspect that the problem has something to do with the amount of objects the code creates, but I'm not sure if there is a FLASH memory limit set by CodeWarrior when the project is compiled. Nevertheless, I'm pretty sure that these errors have nothing to do with array handling, for I have enterely removed any reference to the patternArray from the project and, still, if I were doing something wrong with arrays, the CodeWarrior IDE should have given me some kind of clue on that.
Help me solve this problem as it is difficult to find info on this matter, even in the NXP(freescale) community.
Update #2:
As stated in the following related questions It appears that this error is actually a compiler bug, please confirm this to me:
cross-compilation FFTW for cortex-a15 failure: co-processor offset out of range
iphone: co-processor offset out of range
This is my post at the NXP(formerly Freescale) Community: co-processor offset out of range
Partially Solved
I moved my code to a project in Kinetis Design Studio. It compiled with no errors and I could debug the application until some point when the board ran out of memory, then I applied some optimization changes and everything went great.

Since it suggests it may have something to do with array sizes I'd recommend checking on your array initializations first.
The error co-processor offset out of range doesn't relate to any of your variables, but there's array variable: double patternArray[nPatterns][NInputs]. Do these have correct number of elements?

Related

Several groups of cells in vtk files

I would like to enter several groups of cells with a name in an unstructure grid of VTK.
In the following code, two triangles and four lines elements are created and added to an unstructured grid. I would like to create a group for example with the lines and named 'Beams' for instance.
vtkNew<vtkTriangle> tri1, tri2;
tri1->GetPointIds()->SetId(0, 6);
tri1->GetPointIds()->SetId(1, 7);
tri1->GetPointIds()->SetId(2, 5);
tri2->GetPointIds()->SetId(0, 5);
tri2->GetPointIds()->SetId(1, 2);
tri2->GetPointIds()->SetId(2, 6);
vtkNew<vtkLine> lin1, lin2, lin3, lin4;
lin1->GetPointIds()->SetId(0, 6);
lin1->GetPointIds()->SetId(1, 1);
lin2->GetPointIds()->SetId(0, 7);
lin2->GetPointIds()->SetId(1, 4);
lin3->GetPointIds()->SetId(0, 5);
lin3->GetPointIds()->SetId(1, 3);
lin4->GetPointIds()->SetId(0, 2);
lin4->GetPointIds()->SetId(1, 0);
vtkNew<vtkUnstructuredGrid> ug;
ug->SetPoints(points);
ug->InsertNextCell(tri1->GetCellType(), tri1->GetPointIds()); //0
ug->InsertNextCell(tri2->GetCellType(), tri2->GetPointIds()); //1
ug->InsertNextCell(lin1->GetCellType(), lin1->GetPointIds()); //2
ug->InsertNextCell(lin2->GetCellType(), lin2->GetPointIds()); //3
ug->InsertNextCell(lin3->GetCellType(), lin3->GetPointIds()); //4
ug->InsertNextCell(lin4->GetCellType(), lin4->GetPointIds()); //5

MultiThreading error: no matching overloaded function found

Hi guys I am new to c++ and working on getting multithreading working.
What I am doing is trying to push 5 threads in a vector and make them multiply 2 matrices. However I keep getting this error. I know this will be flagged as a duplicate, but I am only asking because I couldn't really find another similar question in regards to threads.
The error I get based off the code below is the following:
Error C2672 'std::invoke': no matching overloaded function found
C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept()'
Here is my Code
#include "matrices.h"
#include <memory>
#include <iostream>
#include <string>
#include <vector>
#include <thread>
#include <algorithm>
using namespace std;
int main()
{
std::vector<std::thread> threads;
CMatrix3 matrix1, matrix2, result;
std::thread::hardware_concurrency();
matrix1.SetElement(0, 0, 2);
matrix1.SetElement(0, 1, 2);
matrix1.SetElement(0, 2, 3);
matrix1.SetElement(0, 3, 1);
matrix1.SetElement(1, 0, 0);
matrix1.SetElement(1, 1, 0);
matrix1.SetElement(1, 2, 2);
matrix1.SetElement(1, 3, 5);
matrix1.SetElement(2, 0, 1);
matrix1.SetElement(2, 1, 6);
matrix1.SetElement(2, 2, 2);
matrix1.SetElement(2, 3, 0);
matrix1.SetElement(3, 0, 0);
matrix1.SetElement(3, 1, 2);
matrix1.SetElement(3, 2, 0);
matrix1.SetElement(3, 3, 2);
matrix2.SetElement(0, 0, 1);
matrix2.SetElement(0, 1, 1);
matrix2.SetElement(0, 2, 1);
matrix2.SetElement(0, 3, 1);
matrix2.SetElement(1, 0, 1);
matrix2.SetElement(1, 1, 1);
matrix2.SetElement(1, 2, 1);
matrix2.SetElement(1, 3, 1);
matrix2.SetElement(2, 0, 1);
matrix2.SetElement(2, 1, 1);
matrix2.SetElement(2, 2, 1);
matrix2.SetElement(2, 3, 1);
matrix2.SetElement(3, 0, 0);
matrix2.SetElement(3, 1, 2);
matrix2.SetElement(3, 2, 0);
matrix2.SetElement(3, 3, 2);
for (unsigned i = 0; i<5; ++i)
{
threads.push_back(std::thread(CMatrix3::Multiply, &matrix1, std::ref(matrix1), std::ref(matrix2), std::ref(result)));
}
std::for_each(threads.begin(), threads.end(),std::mem_fn(&std::thread::join));
result.display4by4(result);
int h;
cin >> h;
return 0;
}
CMatrix3::Multiply is the entry point function of the class CMatrix3, it takes in 3 arguments matrix1, matrix2 and resultant matrix which is an identity matrix that will be the result of the two multiplied matrices.
ie;this is what it looks like
CMatrix3 & CMatrix3::Multiply(const CMatrix3 & _rA, const CMatrix3 & _rB, CMatrix3 & _rResult)
If you can help I will be grateful.
Thanks
Since c++11 (specifically the introduction of lambdas and range-based for), constructs such as bind, mem_fn and cref have become much less relevant.
You can achieve what you're trying to do like this (assuming I have correctly inferred the interface of CMatrix3):
for (unsigned i = 0; i<5; ++i)
{
// static interface
threads.emplace_back([&]{ CMatrix3::Multiply(matrix1, matrix2, result); });
// or it could be one of these, depending on CMatrix3's interface:
// threads.emplace_back([&]{ matrix1.Multiply(matrix2, result); });
// threads.emplace_back([&]{ result = matrix1.Multiply(matrix2); });
}
for(std::thread& thread : threads) thread.join();
However, as the example stands, this would result in undefined behaviour since all five threads will race to overwrite the data in result.
Hi So I just fixed the error. The right code inside the for loop was supposed to be threads.push_back(std::thread(CMatrix3::Multiply,std::ref(matrix1), std::ref(matrix2), std::ref(result)));
as opposed to threads.push_back(std::thread(CMatrix3::Multiply, &matrix1,std::ref(matrix1), std::ref(matrix2), std::ref(result))); I added in an extra parameter.
On top of that the reason it threw errors when I used an object as the second parameter after specifying the entry point was because the Multiply function was a static. I apologize and thank you guys for trying to help me

VTK: plot line segments

I need to plot line segments (not continous) combined in one chart.
In order to create a plot I use the code from the VTK example but when I skip some values when filling vtkTable line goes down to zero value. And if creating another plot and skip some of the first elements the line goes up from zero. So I need to solve these issues.
I have figured out the solution myself. It appears very simple at last. The basic idea is to represent each line segment by its own plot and to use a separate table for each of the plots. One more improtant point all of the tables do not need to have the same step on the X-axis.
Here is the sample code:
vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
vtkSmartPointer<vtkTable> table1 = vtkSmartPointer<vtkTable>::New();
vtkSmartPointer<vtkFloatArray> xAxis1 = vtkSmartPointer<vtkFloatArray>::New();
xAxis1->SetName("X");
vtkSmartPointer<vtkFloatArray> yAxis1 = vtkSmartPointer<vtkFloatArray>::New();
yAxis1->SetName("");
table1->AddColumn(xAxis1);
table1->AddColumn(yAxis1);
table1->SetNumberOfRows(2);
table1->SetValue(0, 0, 1);
table1->SetValue(0, 1, 1);
table1->SetValue(1, 0, 2);
table1->SetValue(1, 1, 2);
vtkPlot* plot1 = chart->AddPlot(vtkChart::LINE);
plot1->SetInputData(table1, 0, 1);
plot1->SetColor(0, 0, 255, 255);
vtkSmartPointer<vtkTable> table2 = vtkSmartPointer<vtkTable>::New();
vtkSmartPointer<vtkFloatArray> xAxis2 = vtkSmartPointer<vtkFloatArray>::New();
xAxis2->SetName("X");
vtkSmartPointer<vtkFloatArray> yAxis2 = vtkSmartPointer<vtkFloatArray>::New();
yAxis2->SetName("");
table2->AddColumn(xAxis2);
table2->AddColumn(yAxis2);
table2->SetNumberOfRows(3);
table2->SetValue(0, 0, 4);
table2->SetValue(0, 1, 4);
table2->SetValue(1, 0, 5);
table2->SetValue(1, 1, 5);
table2->SetValue(2, 0, 6);
table2->SetValue(2, 1, 6);
vtkPlot* plot2 = chart->AddPlot(vtkChart::LINE);
plot2->SetInputData(table2, 0, 1);
plot2->SetColor(255, 0, 0, 255);
view->GetScene()->AddItem(chart);
view->GetInteractor()->Initialize();
view->GetInteractor()->Start();
P.S. You can also specify several rows with the same x coordinate.

Adding custom tags to a TIFF file

I’m quite new to libtiff, but I’ve managed to get tiff files
saving and opening without much trouble.
Now, I’m being ambitious and trying to add custom tags into my files. I’ve
read the documentation (see here) and written some test code which compiles without
errors, but fails at runtime with an access violation at the first call to
TIFFSetField that features a custom field (calls to TIFFSetField with
standard fields are fine).
My test code follows: just under 100 lines, with the only external
dependency (besides libtiff) being my code to open a test image from a
.pgm file. Can anyone point out what I’m doing wrong? By the way, I'm using libtiff 4.0.3.
#include "stdafx.h"
#include "PGM.h" // Just for reading in the test image
#include "tiffio.h"
// There are a number of TIFF-related definitions we need to make in order to support the custom tags
// that we want to include in our files. The form of these definitions and subroutines comes straight
// out of the libtiff documentation, and the values of the custom tags themselves come from the
// range (65000-75535) defined in the TIFF specification as "reusable" and suitable for private use
// within organisations. See http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
#define N(a) (sizeof(a) / sizeof (a[0]))
#define TIFFTAG_INCIDENTPOWER 65000
#define TIFFTAG_REFLECTEDPOWER 65001
#define TIFFTAG_T1 65002
#define TIFFTAG_T2 65003
#define TIFFTAG_HUMIDITY 65004
#define TIFFTAG_EXPOSURE 65005
static const TIFFFieldInfo xtiffFieldInfo[] = {
{ TIFFTAG_INCIDENTPOWER, -1, -1, TIFF_LONG, FIELD_CUSTOM, 0, 1, const_cast<char*>("LaserIncidentPower") },
{ TIFFTAG_REFLECTEDPOWER, -1, -1, TIFF_LONG, FIELD_CUSTOM, 0, 1, const_cast<char*>("LaserReflectedPower") },
{ TIFFTAG_T1, -1, -1, TIFF_FLOAT, FIELD_CUSTOM, 0, 1, const_cast<char*>("Temperature_1") },
{ TIFFTAG_T2, -1, -1, TIFF_FLOAT, FIELD_CUSTOM, 0, 1, const_cast<char*>("Temperature_2") },
{ TIFFTAG_HUMIDITY, -1, -1, TIFF_FLOAT, FIELD_CUSTOM, 0, 1, const_cast<char*>("Humidity") },
{ TIFFTAG_EXPOSURE, -1, -1, TIFF_FLOAT, FIELD_CUSTOM, 0, 1, const_cast<char*>("ExposureTime(ms)") }
}; // The casts are necessary because the
// string literals are inherently const,
// but the definition of TIFFFieldInfo
// requires a non-const string pointer.
// The Intel and Microsoft compilers
// tolerate this, but gcc doesn't.
static void registerCustomTIFFTags(TIFF *tif)
{
/* Install the extended Tag field info */
TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));
}
void saveAsTiff(int nx, int ny, unsigned short *image, const char* filename,
int Power1, int Power2, float T1, float T2, float Humidity, float Exposure)
{
// Create the TIFF directory object:
TIFF* tif = TIFFOpen(filename, "w");
// Set the tags: first the standard ones...
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, nx);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, ny);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
TIFFSetField(tif, TIFFTAG_ZIPQUALITY, 6); // Takes maximum advantage of Intel ZLIB enhancements
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif, TIFFTAG_ORIENTATION, static_cast<int>(ORIENTATION_TOPLEFT));
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, ny);
// Saving the whole image in a single block makes heavy
// demands on memory but should enable optimum compression
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
// ... and now our own custom ones; if we comment out this next block then everything
// works as it should and we successfully save the image:
registerCustomTIFFTags(tif);
TIFFSetField(tif, TIFFTAG_INCIDENTPOWER, Power1); // Access violation here
TIFFSetField(tif, TIFFTAG_REFLECTEDPOWER, Power2);
TIFFSetField(tif, TIFFTAG_T1, T1);
TIFFSetField(tif, TIFFTAG_T2, T2);
TIFFSetField(tif, TIFFTAG_HUMIDITY, Humidity);
TIFFSetField(tif, TIFFTAG_EXPOSURE, Exposure);
TIFFWriteEncodedStrip(tif, 0, static_cast<void *>(image), nx * ny * 2);
// The '* 2' is present because each pixel
// has 16 bits, hence two bytes
// Write the directory to a file, and close it:
TIFFWriteDirectory(tif);
TIFFClose(tif);
}
int _tmain(int argc, _TCHAR* argv[])
{
// Variables to hold the image
int nx, ny;
unsigned short *image = nullptr;
// Information we'd like to put into our custom tags:
int Power1 = 1000000;
int Power2 = 8;
float T1 = 23.5f;
float T2 = -18.7f;
float Humidity = 0.98f;
float Exposure = 0.001f;
// Read the test image in from a PGM file:
readFromPGM(&nx, &ny, &image, "TestImage.pgm");
// Save the image as a TIF file:
saveAsTiff(nx, ny, image, "TestImage.tif", Power1, Power2, T1, T2, Humidity, Exposure);
return 0;
}
Following some guidance from a kind gentleman called Paul Heckbert on the TIFF users' mailing list, here is the code that finally worked for me. There were two keys to it:
(1) Defining the TIFFFieldInfo fields correctly, in a way which was different from the example given in the documentation.
(2) Using the "extender" pattern for encapsulating the call to TIFFMergeFieldInfo, but doing this before opening the file. If I left the call until after opening the file, then when reading a file with custom tags a number of "Warning, unknown field" messages would be issued immediately on opening the file.
Here is the code:
#include "stdafx.h"
#include "PGM.h"
#include "tiffio.h"
// There are a number of TIFF-related definitions we need to make in order to support the custom tags
// that we want to include in our files. The form of these definitions and subroutines comes straight
// out of the libtiff documentation, and the values of the custom tags themselves come from the
// range (65000-75535) defined in the TIFF specification as "reusable" and suitable for private use
// within organisations. See http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
#define N(a) (sizeof(a) / sizeof (a[0]))
#define TIFFTAG_INCIDENTPOWER 65000
#define TIFFTAG_REFLECTEDPOWER 65001
#define TIFFTAG_T1 65002
#define TIFFTAG_T2 65003
#define TIFFTAG_HUMIDITY 65004
#define TIFFTAG_EXPOSURE 65005
static const TIFFFieldInfo xtiffFieldInfo[] = {
{ TIFFTAG_INCIDENTPOWER, 1, 1, TIFF_LONG, FIELD_CUSTOM, 0, 0, const_cast<char*>("LaserIncidentPower") },
{ TIFFTAG_REFLECTEDPOWER, 1, 1, TIFF_LONG, FIELD_CUSTOM, 0, 0, const_cast<char*>("LaserReflectedPower") },
{ TIFFTAG_T1, 1, 1, TIFF_FLOAT, FIELD_CUSTOM, 0, 0, const_cast<char*>("Temperature_1") },
{ TIFFTAG_T2, 1, 1, TIFF_FLOAT, FIELD_CUSTOM, 0, 0, const_cast<char*>("Temperature_2") },
{ TIFFTAG_HUMIDITY, 1, 1, TIFF_FLOAT, FIELD_CUSTOM, 0, 0, const_cast<char*>("Humidity") },
{ TIFFTAG_EXPOSURE, 1, 1, TIFF_FLOAT, FIELD_CUSTOM, 0, 0, const_cast<char*>("ExposureTime(ms)") }
}; // The casts are necessary because the
// string literals are inherently const,
// but the definition of TIFFFieldInfo
// requires a non-const string pointer.
// The Intel and Microsoft compilers
// tolerate this, but gcc doesn't.
static TIFFExtendProc parent_extender = NULL; // In case we want a chain of extensions
static void registerCustomTIFFTags(TIFF *tif)
{
/* Install the extended Tag field info */
int error = TIFFMergeFieldInfo(tif, xtiffFieldInfo, N(xtiffFieldInfo));
if (parent_extender)
(*parent_extender)(tif);
}
static void augment_libtiff_with_custom_tags() {
static bool first_time = true;
if (!first_time) return;
first_time = false;
parent_extender = TIFFSetTagExtender(registerCustomTIFFTags);
}
void saveAsTiff(int nx, int ny, unsigned short *image, const char* filename,
int Power1, int Power2, float T1, float T2, float Humidity, float Exposure)
{
// Create the TIFF directory object:
augment_libtiff_with_custom_tags();
TIFF* tif = TIFFOpen(filename, "w");
// Set the tags: first the standard ones...
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, nx);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, ny);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
TIFFSetField(tif, TIFFTAG_ZIPQUALITY, 6); // Takes maximum advantage of Intel ZLIB enhancements
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif, TIFFTAG_ORIENTATION, static_cast<int>(ORIENTATION_TOPLEFT));
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, ny);
// Saving the whole image in a single block makes heavy
// demands on memory but should enable optimum compression
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
// ... and now our own custom ones:
TIFFSetField(tif, TIFFTAG_INCIDENTPOWER, Power1);
TIFFSetField(tif, TIFFTAG_REFLECTEDPOWER, Power2);
TIFFSetField(tif, TIFFTAG_T1, T1);
TIFFSetField(tif, TIFFTAG_T2, T2);
TIFFSetField(tif, TIFFTAG_HUMIDITY, Humidity);
TIFFSetField(tif, TIFFTAG_EXPOSURE, Exposure);
TIFFWriteEncodedStrip(tif, 0, static_cast<void *>(image), nx * ny * 2);
// The '* 2' is present because each pixel
// has 16 bits, hence two bytes
// Write the directory to a file, and close it:
TIFFWriteDirectory(tif);
TIFFClose(tif);
}
void readFromTiff(int *nx, int *ny, unsigned short **image, const char* filename,
int *Power1, int *Power2, float *T1, float *T2, float *Humidity, float *Exposure)
{
// Create the TIFF directory object:
augment_libtiff_with_custom_tags();
TIFF* tif = TIFFOpen(filename, "r");
if (NULL == tif)
{
*nx = -1;
*ny = -1;
return;
}
// Read in the image size and metadata:
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, nx);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, ny);
TIFFGetField(tif, TIFFTAG_INCIDENTPOWER, Power1);
TIFFGetField(tif, TIFFTAG_REFLECTEDPOWER, Power2);
TIFFGetField(tif, TIFFTAG_T1, T1);
TIFFGetField(tif, TIFFTAG_T2, T2);
TIFFGetField(tif, TIFFTAG_HUMIDITY, Humidity);
TIFFGetField(tif, TIFFTAG_EXPOSURE, Exposure);
// Dimension the buffer, and read in the image data itself:
*image = new unsigned short[(*nx) * (*ny)];
TIFFReadEncodedStrip(tif, static_cast<tstrip_t>(0), static_cast<void *>(*image), static_cast<tsize_t>(-1));
TIFFClose(tif);
}
int _tmain(int argc, _TCHAR* argv[])
{
// Variables to hold the image
int nx, ny;
unsigned short *image = nullptr;
// Information we'd like to put into our custom tags:
int Power1 = 1000000;
int Power2 = 8;
float T1 = 23.5f;
float T2 = -18.7f;
float Humidity = 0.98f;
float Exposure = 0.001f;
// Read the test image in from a PGM file:
readFromPGM(&nx, &ny, &image, "TestImage.pgm");
// Save the image as a TIF file:
saveAsTiff(nx, ny, image, "TestImage.tif", Power1, Power2, T1, T2, Humidity, Exposure);
// Prepare to read back in: first clear the various fields
Power1 = 0;
Power2 = 0;
T1 = 0.0f;
T2 = 0.0f;
Humidity = 0.0f;
Exposure = 0.0f;
nx = 0;
ny = 0;
delete [] image;
readFromTiff(&nx, &ny, &image, "TestImage.tif", &Power1, &Power2, &T1, &T2, &Humidity, &Exposure);
printf("Image size = %d, %d\r\n", ny, ny);
printf("Power1 = %d\r\n", Power1);
printf("Power2 = %d\r\n", Power2);
printf("T1 = %6.3f\r\n", T1);
printf("T2 = %6.3f\r\n", T2);
printf("Humidity = %6.3f\r\n", Humidity);
printf("Exposure = %6.3f\r\n", Exposure);
return 0;
}

double free or corruption error c++

i have a code for a graphic engine, it need to draw wire frames and line drawings, i made some adjustments to te original code of mine and now i get the error double free or corruption, but before the code worked just fine, does annybody know what i'm doing wrong?
void Wireframe::Generate(list<eye_point> &points, list<line> &lines, const ini::Configuration &configuration)
{
string buffer;
stringstream out;
for(int i = 0; i < nrFigures; i++)
{
figure = "Figure";
out<<i;
buffer = out.str();
figure.append(buffer);
out.str(string());
cout<<"de figure heeft de naam "<<figure<<endl;
Read_info(configuration);
Generate_points(points, configuration);
Generate_lines(lines, configuration);
}
}
in read info he reads the info from the ini file
void Wireframe::Generate_points(list<eye_point> &points, const ini::Configuration &configuration){
Matrix schaal = Scale(scale);
Matrix translate = Translatie(center);
Matrix xrotate = Rotate_x_as(rotatex);
Matrix yrotate = Rotate_y_as(rotatey);
Matrix zrotate = Rotate_z_as(rotatez);
Matrix eyematrix = Eye_transformatie(eye);
Matrix matrix;
matrix = schaal * translate * xrotate * yrotate * zrotate * eyematrix;
if(type.compare("LineDrawing") == 0)
{
linedrawing_point(points, configuration, matrix);
}
else if(type.compare("Cube") == 0)
{
cube_point(points,matrix);
}
}
void Wireframe::Generate_lines(list<line> &lines, const ini::Configuration &configuration){
if(type.compare("LineDrawing") == 0)
{
linedrawing_lines(lines, configuration);
}
else if (type.compare("Cube") == 0)
{
cube_lines(lines);
}
}
here he sees wha for line drawing he needs to do, were by line drawing works just fine, the error is in cube.
void Wireframe::cube_lines(list<line> &lines){
getline(lines, 1, 5);
getline(lines, 5, 3);
getline(lines, 3, 7);
getline(lines, 7, 1);
getline(lines, 5, 2);
getline(lines, 2, 8);
getline(lines, 8, 3);
getline(lines, 3, 5);
getline(lines, 2, 6);
getline(lines, 6, 4);
getline(lines, 4, 8);
getline(lines, 8, 2);
getline(lines, 6, 1);
getline(lines, 1, 7);
getline(lines, 7, 4);
getline(lines, 4, 6);
getline(lines, 7, 3);
getline(lines, 3, 8);
getline(lines, 8, 4);
getline(lines, 4, 7);
getline(lines, 1, 6);
getline(lines, 6, 2);
getline(lines, 2, 5);
getline(lines, 5, 1);
}
void Wireframe::cube_point(list<eye_point> &points, Matrix &matrix){
getpoint(1, -1, -1, points, 1, matrix );
getpoint(-1, 1, -1, points, 2, matrix );
getpoint(1, 1, 1, points, 3, matrix );
getpoint(-1, -1, 1, points, 4, matrix );
getpoint(1, 1, -1, points, 5, matrix );
getpoint(-1, -1, -1, points, 6, matrix );
getpoint(1, -1, 1, points, 7, matrix );
getpoint(-1, 1, 1, points, 1, matrix );
}
void Wireframe::projectie(Vector3D &vector_points, eye_point &point_element){
point_element.z = vector_points.z;
if(vector_points.z != 0)
{
point_element.x = vector_points.x / -vector_points.z;
point_element.y = vector_points.y / -vector_points.z;
}
else
{
point_element.x = vector_points.x;
point_element.y = vector_points.y;
}
}
void Wireframe::getpoint(double x, double y, double z, list<eye_point> &points, int nummer, Matrix &matrix ){
eye_point point_element;
Vector3D vector_points = Vector3D::point(x, y, z);
vector_points *= matrix;
point_element.figure = figure;
point_element.punt = nummer;
projectie(vector_points, point_element);
points.push_back(point_element);
}
void Wireframe::getline(list<line> &lines, int lijn0, int lijn1){
line line_element;
line_element.lijn0 = lijn0;
line_element.lijn1 = lijn1;
line_element.figure = figure;
line_element.linecolor = linecolor;
lines.push_back(line_element);
}
If you are on Windows, you might want to try AppVerifier tool which is free and is designed to detect double free errors http://msdn.microsoft.com/en-us/library/ms807121.aspx
The code posted doesn't directly do any allocation or freeing, so it's not relevant to your bug.
It's likely that the objects you're putting into containers (line and eye_point) have a bug. For instance, missing an assignment operator or copy constructor could lead to all sorts of baffling behavior.